当前位置: 首页>>代码示例>>Java>>正文


Java CompletedCallback.onCompleted方法代码示例

本文整理汇总了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);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:18,代码来源:AsyncSSLSocketWrapper.java

示例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);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:11,代码来源:StreamPart.java

示例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();
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:61,代码来源:Util.java

示例4: report

import com.koushikdutta.async.callback.CompletedCallback; //导入方法依赖的package包/类
protected void report(Exception e) {
    CompletedCallback closed = getClosedCallback();
    if (closed != null)
        closed.onCompleted(e);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:6,代码来源:ZipDataSink.java


注:本文中的com.koushikdutta.async.callback.CompletedCallback.onCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。