• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ByteBufferList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.koushikdutta.async.ByteBufferList的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferList类的具体用法?Java ByteBufferList怎么用?Java ByteBufferList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ByteBufferList类属于com.koushikdutta.async包,在下文中一共展示了ByteBufferList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onAccepted

import com.koushikdutta.async.ByteBufferList; //导入依赖的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");
}
 
开发者ID:maks,项目名称:UartBridge,代码行数:23,代码来源:SocketServer.java


示例2: readGoAway

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
private void readGoAway(ByteBufferList source, short length, byte flags, int streamId)
throws IOException {
    if (length < 8) throw ioException("TYPE_GOAWAY length < 8: %s", length);
    if (streamId != 0) throw ioException("TYPE_GOAWAY streamId != 0");
    int lastStreamId = source.getInt();
    int errorCodeInt = source.getInt();
    int opaqueDataLength = length - 8;
    ErrorCode errorCode = ErrorCode.fromHttp2(errorCodeInt);
    if (errorCode == null) {
        throw ioException("TYPE_GOAWAY unexpected error code: %d", errorCodeInt);
    }
    ByteString debugData = ByteString.EMPTY;
    if (opaqueDataLength > 0) { // Must read debug data in order to not corrupt the connection.
        debugData = ByteString.of(source.getBytes(opaqueDataLength));
    }
    handler.goAway(lastStreamId, errorCode, debugData);
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:18,代码来源:Http20Draft13.java


示例3: pushPromise

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void pushPromise(int streamId, int promisedStreamId,
                                     List<Header> requestHeaders) throws IOException {
    if (closed) throw new IOException("closed");
    ByteBufferList hpackBuffer = hpackWriter.writeHeaders(requestHeaders);

    long byteCount = hpackBuffer.remaining();
    int length = (int) Math.min(MAX_FRAME_SIZE - 4, byteCount);
    byte type = TYPE_PUSH_PROMISE;
    byte flags = byteCount == length ? FLAG_END_HEADERS : 0;
    frameHeader(streamId, length + 4, type, flags);
    ByteBuffer sink = ByteBufferList.obtain(8192).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(promisedStreamId & 0x7fffffff);
    sink.flip();
    frameHeader.add(sink);
    hpackBuffer.get(frameHeader, length);
    this.sink.write(frameHeader);

    if (byteCount > length) writeContinuationFrames(hpackBuffer, streamId);
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:21,代码来源:Http20Draft13.java


示例4: idleSocket

import com.koushikdutta.async.ByteBufferList; //导入依赖的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();
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:23,代码来源:AsyncSocketMiddleware.java


示例5: write

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public void write(final ByteBufferList bb) {
    try {
        while (bb.size() > 0) {
            ByteBuffer b = bb.remove();
            getOutputStream().write(b.array(), b.arrayOffset() + b.position(), b.remaining());
            ByteBufferList.reclaim(b);
        }
    }
    catch (IOException e) {
        reportClose(e);
    }
    finally {
        bb.recycle();
    }
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:17,代码来源:OutputStreamDataSink.java


示例6: testPushParserUntil

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
public void testPushParserUntil() {
    valRead = 0;
    FilteredDataEmitter mock = new FilteredDataEmitter() {
        @Override
        public boolean isPaused() {
            return false;
        }
    };
    new PushParser(mock)
        .until((byte)0, new DataCallback.NullDataCallback())
        .readInt(new PushParser.ParseCallback<Integer>() {
            public void parsed(Integer arg) {
                valRead = arg;
            }
        });
    byte[] bytes = new byte[] { 5, 5, 5, 5, 0, 10, 5, 5, 5 };
    Util.emitAllData(mock, new ByteBufferList(bytes));
    assertEquals(valRead, 0x0A050505);
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:20,代码来源:ByteUtilTests.java


示例7: onDataAvailable

import com.koushikdutta.async.ByteBufferList; //导入依赖的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);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:26,代码来源:Spdy3.java


示例8: synStream

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void synStream(boolean outFinished, boolean inFinished,
                                   int streamId, int associatedStreamId, List<Header> headerBlock)
throws IOException {
    if (closed) throw new IOException("closed");
    ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock);
    int length = (int) (10 + headerBlockBuffer.remaining());
    int type = TYPE_SYN_STREAM;
    int flags = (outFinished ? FLAG_FIN : 0) | (inFinished ? FLAG_UNIDIRECTIONAL : 0);

    int unused = 0;
    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
    sink.putInt((flags & 0xff) << 24 | length & 0xffffff);
    sink.putInt(streamId & 0x7fffffff);
    sink.putInt(associatedStreamId & 0x7fffffff);
    sink.putShort((short) ((unused & 0x7) << 13 | (unused & 0x1f) << 8 | (unused & 0xff)));
    sink.flip();
    this.sink.write(frameHeader.add(sink).add(headerBlockBuffer));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:21,代码来源:Spdy3.java


示例9: synReply

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void synReply(boolean outFinished, int streamId,
                                  List<Header> headerBlock) throws IOException {
    if (closed) throw new IOException("closed");
    ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock);
    int type = TYPE_SYN_REPLY;
    int flags = (outFinished ? FLAG_FIN : 0);
    int length = (int) (headerBlockBuffer.remaining() + 4);

    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
    sink.putInt((flags & 0xff) << 24 | length & 0xffffff);
    sink.putInt(streamId & 0x7fffffff);
    sink.flip();
    this.sink.write(frameHeader.add(sink).add(headerBlockBuffer));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:17,代码来源:Spdy3.java


示例10: headers

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void headers(int streamId, List<Header> headerBlock)
throws IOException {
    if (closed) throw new IOException("closed");
    ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock);
    int flags = 0;
    int type = TYPE_HEADERS;
    int length = (int) (headerBlockBuffer.remaining() + 4);

    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
    sink.putInt((flags & 0xff) << 24 | length & 0xffffff);
    sink.putInt(streamId & 0x7fffffff);
    sink.flip();
    this.sink.write(frameHeader.add(sink).add(headerBlockBuffer));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:17,代码来源:Spdy3.java


示例11: ping

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void ping(boolean reply, int payload1, int payload2)
throws IOException {
    if (closed) throw new IOException("closed");
    boolean payloadIsReply = client != ((payload1 & 1) == 1);
    if (reply != payloadIsReply) throw new IllegalArgumentException("payload != reply");
    int type = TYPE_PING;
    int flags = 0;
    int length = 4;
    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff);
    sink.putInt((flags & 0xff) << 24 | length & 0xffffff);
    sink.putInt(payload1);
    sink.flip();
    this.sink.write(frameHeader.addAll(sink));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:17,代码来源:Spdy3.java


示例12: readHeaderBlock

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
private void readHeaderBlock(ByteBufferList source, short length, short padding, byte flags, int streamId)
throws IOException {
    source.skip(padding);
    hpackReader.refill(source);
    hpackReader.readHeaders();
    hpackReader.emitReferenceSet();
    // TODO: Concat multi-value headers with 0x0, except COOKIE, which uses 0x3B, 0x20.
    // http://tools.ietf.org/html/draft-ietf-httpbis-http2-09#section-8.1.3
    if ((flags & FLAG_END_HEADERS) != 0) {
        if (pendingHeaderType == TYPE_HEADERS) {
            boolean endStream = (flags & FLAG_END_STREAM) != 0;
            handler.headers(false, endStream, streamId, -1, hpackReader.getAndReset(), HeadersMode.HTTP_20_HEADERS);
        }
        else if (pendingHeaderType == TYPE_PUSH_PROMISE) {
            handler.pushPromise(streamId, promisedStreamId, hpackReader.getAndReset());
        }
        else {
            throw new AssertionError("unknown header type");
        }
    }
    else {
        continuingStreamId = streamId;
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:25,代码来源:Http20Draft13.java


示例13: write

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public void write(ByteBufferList bb) {
    // order is important here...
    assert !mEnded;
    // do the header write... this will call onWritable, which may be reentrant
    if (!headWritten)
        initFirstWrite();

    // now check to see if the list is empty. reentrancy may cause it to empty itself.
    if (bb.remaining() == 0)
        return;

    // null sink means that the header has not finished writing
    if (mSink == null)
        return;

    // can successfully write!
    mSink.write(bb);
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:20,代码来源:AsyncHttpServerResponseImpl.java


示例14: write

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public void write(ByteBufferList bb) {
    int canWrite = (int)Math.min(bytesLeftInWriteWindow, AsyncSpdyConnection.this.bytesLeftInWriteWindow);
    canWrite = Math.min(bb.remaining(), canWrite);
    if (canWrite == 0) {
        return;
    }
    if (canWrite < bb.remaining()) {
        if (writing.hasRemaining())
            throw new AssertionError("wtf");
        bb.get(writing, canWrite);
        bb = writing;
    }

    try {
        writer.data(false, id, bb);
        bytesLeftInWriteWindow -= canWrite;
    }
    catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:23,代码来源:AsyncSpdyConnection.java


示例15: goAway

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
@Override
public synchronized void goAway(int lastGoodStreamId, ErrorCode errorCode,
                                byte[] debugData) throws IOException {
    if (closed) throw new IOException("closed");
    if (errorCode.httpCode == -1) throw illegalArgument("errorCode.httpCode == -1");
    int length = 8 + debugData.length;
    byte type = TYPE_GOAWAY;
    byte flags = FLAG_NONE;
    int streamId = 0;
    frameHeader(streamId, length, type, flags);
    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt(lastGoodStreamId);
    sink.putInt(errorCode.httpCode);
    sink.put(debugData);
    sink.flip();
    this.sink.write(frameHeader.add(sink));
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:18,代码来源:Http20Draft13.java


示例16: addAndEmit

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
private void addAndEmit(ByteBufferList bb) {
    if (pending == null) {
        Util.emitAllData(this, bb);
        if (bb.remaining() > 0) {
            pending = new LinkedList<ByteBufferList>();
            pending.add(bb);
        }
        return;
    }
    
    while (!isPaused()) {
        bb = pending.remove();
        Util.emitAllData(this, bb);
        if (bb.remaining() > 0)
            pending.add(0, bb);
    }
    if (pending.size() == 0)
        pending = null;
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:20,代码来源:WebSocketImpl.java


示例17: onDataAvailable

import com.koushikdutta.async.ByteBufferList; //导入依赖的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();
    }
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:17,代码来源:OutputStreamDataCallback.java


示例18: testString

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
public void testString() throws Exception {
    StringParser p = new StringParser();
    FilteredDataEmitter f = new FilteredDataEmitter() {
        @Override
        public boolean isPaused() {
            return false;
        }
    };
    Future<String> ret = p.parse(f);
    ByteBufferList l = new ByteBufferList();
    l.add(ByteBuffer.wrap("foo".getBytes(Charsets.US_ASCII.name())));
    f.onDataAvailable(f, l);
    f.getEndCallback().onCompleted(null);
    String s = ret.get();
    assertEquals(s, "foo");
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:17,代码来源:ParserTests.java


示例19: sendData

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
public void sendData(String message) {
    if (asyncClient != null) {
        asyncClient.write(new ByteBufferList(message.getBytes()));
        Timber.d("Data sent: %s", message);
    } else {
        Timber.e("cannot send data - socket not yet ready");
    }
}
 
开发者ID:maks,项目名称:UartBridge,代码行数:9,代码来源:SocketServer.java


示例20: frameHeader

import com.koushikdutta.async.ByteBufferList; //导入依赖的package包/类
void frameHeader(int streamId, int length, byte type, byte flags) throws IOException {
    if (logger.isLoggable(FINE))
        logger.fine(formatHeader(false, streamId, length, type, flags));
    if (length > MAX_FRAME_SIZE) {
        throw illegalArgument("FRAME_SIZE_ERROR length > %d: %d", MAX_FRAME_SIZE, length);
    }
    if ((streamId & 0x80000000) != 0)
        throw illegalArgument("reserved bit set: %s", streamId);
    ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN);
    sink.putInt((length & 0x3fff) << 16 | (type & 0xff) << 8 | (flags & 0xff));
    sink.putInt(streamId & 0x7fffffff);
    sink.flip();
    this.sink.write(frameHeader.add(sink));
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:15,代码来源:Http20Draft13.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TagWriter类代码示例发布时间:2022-05-22
下一篇:
Java ServiceFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap