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

Java DataEmitter类代码示例

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

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



DataEmitter类属于com.koushikdutta.async包,在下文中一共展示了DataEmitter类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
 
开发者ID:maks,项目名称:UartBridge,代码行数:23,代码来源:SocketServer.java


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


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


示例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);
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:18,代码来源:Http20Draft13.java


示例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);
    }
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:26,代码来源:Spdy3.java


示例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;
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:26,代码来源:HttpUtil.java


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


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


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


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


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


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


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


示例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);
            }
        }
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:31,代码来源:AsyncHttpServerRequestImpl.java


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


示例16: onDataAvailable

import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
    try {
        ByteBuffer output = ByteBufferList.obtain(bb.remaining() * 2);
        int totalRead = 0;
        while (bb.size() > 0) {
            ByteBuffer b = bb.remove();
            if (b.hasRemaining()) {
                totalRead =+ b.remaining();
                mInflater.setInput(b.array(), b.arrayOffset() + b.position(), b.remaining());
                do {
                    int inflated = mInflater.inflate(output.array(), output.arrayOffset() + output.position(), output.remaining());
                    output.position(output.position() + inflated);
                    if (!output.hasRemaining()) {
                        output.flip();
                        transformed.add(output);
                        assert totalRead != 0;
                        int newSize = output.capacity() * 2;
                        output = ByteBufferList.obtain(newSize);
                    }
                }
                while (!mInflater.needsInput() && !mInflater.finished());
            }
            ByteBufferList.reclaim(b);
        }
        output.flip();
        transformed.add(output);

        Util.emitAllData(this, transformed);
    }
    catch (Exception ex) {
        report(ex);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:35,代码来源:InflaterInputFilter.java


示例17: terminate

import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
private void terminate() {
    // DISCONNECT. EVERYTHING.
    // should not get any data after this point...
    // if so, eat it and disconnect.
    mSocket.setDataCallback(new NullDataCallback() {
        @Override
        public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
            super.onDataAvailable(emitter, bb);
            mSocket.close();
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:13,代码来源:AsyncHttpResponseImpl.java


示例18: parse

import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void parse(DataEmitter emitter, final CompletedCallback completed) {
    new DocumentParser().parse(emitter).setCallback(new FutureCallback<Document>() {
        @Override
        public void onCompleted(Exception e, Document result) {
            document = result;
            completed.onCompleted(e);
        }
    });
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:11,代码来源:DocumentBody.java


示例19: parse

import com.koushikdutta.async.DataEmitter; //导入依赖的package包/类
@Override
public void parse(DataEmitter emitter, final CompletedCallback completed) {
    new JSONObjectParser().parse(emitter).setCallback(new FutureCallback<JSONObject>() {
        @Override
        public void onCompleted(Exception e, JSONObject result) {
            json = result;
            completed.onCompleted(e);
        }
    });
}
 
开发者ID:pogointel,项目名称:openmap-client-android,代码行数:11,代码来源:JSONObjectBody.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java X9IntegerConverter类代码示例发布时间:2022-05-22
下一篇:
Java MimeUtil类代码示例发布时间: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