本文整理汇总了Java中com.koushikdutta.async.DataEmitter类的典型用法代码示例。如果您正苦于以下问题:Java DataEmitter类的具体用法?Java DataEmitter怎么用?Java DataEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataEmitter类属于com.koushikdutta.async包,在下文中一共展示了DataEmitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAccepted
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onAccepted(AsyncSocket socket) {
// this example service shows only a single server <-> client communication
if (asyncClient != null) {
asyncClient.close();
}
asyncClient = (AsyncNetworkSocket) socket;
asyncClient.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
Timber.i("Data received: %s", bb.readString());
}
});
asyncClient.setClosedCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
asyncClient = null;
Timber.i("Client socket closed");
}
});
Timber.i("Client socket connected");
}
示例2: onDataAvailable
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
try {
while (bb.size() > 0) {
ByteBuffer b = bb.remove();
mOutput.write(b.array(), b.arrayOffset() + b.position(), b.remaining());
ByteBufferList.reclaim(b);
}
}
catch (Exception ex) {
onCompleted(ex);
}
finally {
bb.recycle();
}
}
示例3: idleSocket
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
private void idleSocket(final AsyncSocket socket) {
// must listen for socket close, otherwise log will get spammed.
socket.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
socket.setClosedCallback(null);
socket.close();
}
});
socket.setWriteableCallback(null);
// should not get any data after this point...
// if so, eat it and disconnect.
socket.setDataCallback(new DataCallback.NullDataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
super.onDataAvailable(emitter, bb);
bb.recycle();
socket.setClosedCallback(null);
socket.close();
}
});
}
示例4: onDataAvailable
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
bb.order(ByteOrder.BIG_ENDIAN);
w1 = bb.getInt();
w2 = bb.getInt();
// boolean r = (w1 & 0xc0000000) != 0; // Reserved: Ignore first 2 bits.
length = (short) ((w1 & 0x3fff0000) >> 16); // 14-bit unsigned == MAX_FRAME_SIZE
type = (byte) ((w1 & 0xff00) >> 8);
flags = (byte) (w1 & 0xff);
// boolean r = (w2 & 0x80000000) != 0; // Reserved: Ignore first bit.
streamId = (w2 & 0x7fffffff); // 31-bit opaque identifier.
if (logger.isLoggable(FINE))
logger.fine(formatHeader(true, streamId, length, type, flags));
reader.read(length, onFullFrame);
}
示例5: onDataAvailable
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
bb.order(ByteOrder.BIG_ENDIAN);
w1 = bb.getInt();
w2 = bb.getInt();
boolean control = (w1 & 0x80000000) != 0;
flags = (w2 & 0xff000000) >>> 24;
length = (w2 & 0xffffff);
if (!control) {
streamId = w1 & 0x7fffffff;
inFinished = (flags & FLAG_FIN) != 0;
emitter.setDataCallback(onDataFrame);
if (length == 0) {
// zero length packet, immediately trigger the data parsing
// fixes the hanging response portion of https://github.com/koush/ion/issues/443#issuecomment-67729152
onDataFrame.onDataAvailable(emitter, emptyList);
}
}
else {
reader.read(length, onFullFrame);
}
}
示例6: getBody
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
public static AsyncHttpRequestBody getBody(DataEmitter emitter, CompletedCallback reporter, Headers headers) {
String contentType = headers.get("Content-Type");
if (contentType != null) {
String[] values = contentType.split(";");
for (int i = 0; i < values.length; i++) {
values[i] = values[i].trim();
}
for (String ct: values) {
if (UrlEncodedFormBody.CONTENT_TYPE.equals(ct)) {
return new UrlEncodedFormBody();
}
if (JSONObjectBody.CONTENT_TYPE.equals(ct)) {
return new JSONObjectBody();
}
if (StringBody.CONTENT_TYPE.equals(ct)) {
return new StringBody();
}
if (MultipartFormDataBody.CONTENT_TYPE.equals(ct)) {
return new MultipartFormDataBody(values);
}
}
}
return null;
}
示例7: parse
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public Future<String> parse(DataEmitter emitter) {
final String charset = emitter.charset();
return new ByteBufferListParser().parse(emitter)
.then(new TransformFuture<String, ByteBufferList>() {
@Override
protected void transform(ByteBufferList result) throws Exception {
Charset charsetToUse = forcedCharset;
if (charsetToUse == null && charset != null)
charsetToUse = Charset.forName(charset);
setComplete(result.readString(charsetToUse));
}
});
}
示例8: parse
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public Future<JSONObject> parse(DataEmitter emitter) {
return new StringParser().parse(emitter)
.then(new TransformFuture<JSONObject, String>() {
@Override
protected void transform(String result) throws Exception {
setComplete(new JSONObject(result));
}
});
}
示例9: parse
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public Future<JSONArray> parse(DataEmitter emitter) {
return new StringParser().parse(emitter)
.then(new TransformFuture<JSONArray, String>() {
@Override
protected void transform(String result) throws Exception {
setComplete(new JSONArray(result));
}
});
}
示例10: onBoundaryStart
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
protected void onBoundaryStart() {
final Headers headers = new Headers();
liner = new LineEmitter();
liner.setLineCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
if (!"\r".equals(s)){
headers.addLine(s);
}
else {
handleLast();
liner = null;
setDataCallback(null);
Part part = new Part(headers);
if (mCallback != null)
mCallback.onPart(part);
if (getDataCallback() == null) {
if (part.isFile()) {
setDataCallback(new NullDataCallback());
return;
}
lastName = part.getName();
last = new ByteBufferList();
setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
bb.get(last);
}
});
}
}
}
});
setDataCallback(liner);
}
示例11: parse
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void parse(DataEmitter emitter, final CompletedCallback completed) {
new StringParser().parse(emitter).setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
string = result;
completed.onCompleted(e);
}
});
}
示例12: parse
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void parse(DataEmitter emitter, final CompletedCallback completed) {
new JSONArrayParser().parse(emitter).setCallback(new FutureCallback<JSONArray>() {
@Override
public void onCompleted(Exception e, JSONArray result) {
json = result;
completed.onCompleted(e);
}
});
}
示例13: Reader
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
Reader(DataEmitter emitter, Handler handler, int headerTableSize, boolean client) {
this.emitter = emitter;
this.client = client;
this.hpackReader = new HpackDraft08.Reader(headerTableSize);
this.handler = handler;
reader = new DataEmitterReader();
parseFrameHeader();
}
示例14: onStringAvailable
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onStringAvailable(String s) {
try {
if (statusLine == null) {
statusLine = s;
if (!statusLine.contains("HTTP/")) {
onNotHttp();
mSocket.setDataCallback(null);
}
}
else if (!"\r".equals(s)){
mRawHeaders.addLine(s);
}
else {
DataEmitter emitter = HttpUtil.getBodyDecoder(mSocket, Protocol.HTTP_1_1, mRawHeaders, true);
// emitter.setEndCallback(mReporter);
mBody = HttpUtil.getBody(emitter, mReporter, mRawHeaders);
if (mBody == null) {
mBody = onUnknownBody(mRawHeaders);
if (mBody == null)
mBody = new UnknownRequestBody(mRawHeaders.get("Content-Type"));
}
mBody.parse(emitter, mReporter);
onHeadersReceived();
}
}
catch (Exception ex) {
onCompleted(ex);
}
}
示例15: Reader
import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
Reader(DataEmitter emitter, Handler handler, boolean client) {
this.emitter = emitter;
this.handler = handler;
this.client = client;
emitter.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
// TODO: handle termination
}
});
reader = new DataEmitterReader();
parseFrameHeader();
}