本文整理汇总了Java中com.koushikdutta.async.callback.CompletedCallback.onCompleted方法的典型用法代码示例。如果您正苦于以下问题:Java CompletedCallback.onCompleted方法的具体用法?Java CompletedCallback.onCompleted怎么用?Java CompletedCallback.onCompleted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.koushikdutta.async.callback.CompletedCallback
的用法示例。
在下文中一共展示了CompletedCallback.onCompleted方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: report
import com.koushikdutta.async.callback.CompletedCallback; //导入方法依赖的package包/类
private void report(Exception e) {
final HandshakeCallback hs = handshakeCallback;
if (hs != null) {
handshakeCallback = null;
mSocket.setDataCallback(new DataCallback.NullDataCallback());
mSocket.end();
// handshake sets this callback. unset it.
mSocket.setClosedCallback(null);
mSocket.close();
hs.onHandshakeCompleted(e, null);
return;
}
CompletedCallback cb = getEndCallback();
if (cb != null)
cb.onCompleted(e);
}
示例2: write
import com.koushikdutta.async.callback.CompletedCallback; //导入方法依赖的package包/类
@Override
public void write(DataSink sink, CompletedCallback callback) {
try {
InputStream is = getInputStream();
com.koushikdutta.async.Util.pump(is, sink, callback);
}
catch (Exception e) {
callback.onCompleted(e);
}
}
示例3: pump
import com.koushikdutta.async.callback.CompletedCallback; //导入方法依赖的package包/类
public static void pump(final InputStream is, final long max, final DataSink ds, final CompletedCallback callback) {
final CompletedCallback wrapper = new CompletedCallback() {
boolean reported;
@Override
public void onCompleted(Exception ex) {
if (reported)
return;
reported = true;
callback.onCompleted(ex);
}
};
final WritableCallback cb = new WritableCallback() {
int totalRead = 0;
private void cleanup() {
ds.setClosedCallback(null);
ds.setWriteableCallback(null);
pending.recycle();
StreamUtility.closeQuietly(is);
}
ByteBufferList pending = new ByteBufferList();
Allocator allocator = new Allocator();
@Override
public void onWriteable() {
try {
do {
if (!pending.hasRemaining()) {
ByteBuffer b = allocator.allocate();
long toRead = Math.min(max - totalRead, b.capacity());
int read = is.read(b.array(), 0, (int)toRead);
if (read == -1 || totalRead == max) {
cleanup();
wrapper.onCompleted(null);
return;
}
allocator.track(read);
totalRead += read;
b.position(0);
b.limit(read);
pending.add(b);
}
ds.write(pending);
}
while (!pending.hasRemaining());
}
catch (Exception e) {
cleanup();
wrapper.onCompleted(e);
}
}
};
ds.setWriteableCallback(cb);
ds.setClosedCallback(wrapper);
cb.onWriteable();
}
示例4: report
import com.koushikdutta.async.callback.CompletedCallback; //导入方法依赖的package包/类
protected void report(Exception e) {
CompletedCallback closed = getClosedCallback();
if (closed != null)
closed.onCompleted(e);
}