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

Java HttpResponseBodyPart类代码示例

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

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



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

示例1: onBinaryFragment

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public void onBinaryFragment(HttpResponseBodyPart part) {

        for (WebSocketListener listener : listeners) {
            if (listener instanceof WebSocketByteFragmentListener)
                WebSocketByteFragmentListener.class.cast(listener).onFragment(part);
        }

        if (interestedInByteMessages) {
            byte[] fragment = part.getBodyPartBytes();

            if (part.isLast()) {
                if (bufferSize == 0) {
                    notifyByteListeners(fragment);

                } else {
                    bufferFragment(fragment);
                    notifyByteListeners(fragmentsBytes());
                }

                reset();

            } else
                bufferFragment(fragment);
        }
    }
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:26,代码来源:NettyWebSocket.java


示例2: onTextFragment

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public void onTextFragment(HttpResponseBodyPart part) {
    for (WebSocketListener listener : listeners) {
        if (listener instanceof WebSocketTextFragmentListener)
            WebSocketTextFragmentListener.class.cast(listener).onFragment(part);
    }

    if (interestedInTextMessages) {
        byte[] fragment = part.getBodyPartBytes();

        if (part.isLast()) {
            if (bufferSize == 0) {
                notifyTextListeners(fragment);

            } else {
                bufferFragment(fragment);
                notifyTextListeners(fragmentsBytes());
            }

            reset();

        } else
            bufferFragment(fragment);
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:25,代码来源:NettyWebSocket.java


示例3: handleFrame

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
private void handleFrame(Channel channel, WebSocketFrame frame, WebSocketUpgradeHandler handler, NettyWebSocket webSocket) throws Exception {
    if (frame instanceof CloseWebSocketFrame) {
        Channels.setDiscard(channel);
        CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
        webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText());
    } else {
        ByteBuf buf = frame.content();
        if (buf != null && buf.readableBytes() > 0) {
            HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment());
            handler.onBodyPartReceived(part);

            if (frame instanceof BinaryWebSocketFrame) {
                webSocket.onBinaryFragment(part);
            } else if (frame instanceof TextWebSocketFrame) {
                webSocket.onTextFragment(part);
            } else if (frame instanceof PingWebSocketFrame) {
                webSocket.onPing(part);
            } else if (frame instanceof PongWebSocketFrame) {
                webSocket.onPong(part);
            }
        }
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:24,代码来源:WebSocketHandler.java


示例4: handleChunk

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
private void handleChunk(HttpContent chunk,//
        final Channel channel,//
        final NettyResponseFuture<?> future,//
        AsyncHandler<?> handler) throws IOException, Exception {

    boolean interrupt = false;
    boolean last = chunk instanceof LastHttpContent;

    // Netty 4: the last chunk is not empty
    if (last) {
        LastHttpContent lastChunk = (LastHttpContent) chunk;
        HttpHeaders trailingHeaders = lastChunk.trailingHeaders();
        if (!trailingHeaders.isEmpty()) {
            interrupt = handler.onHeadersReceived(new HttpResponseHeaders(trailingHeaders, true)) != State.CONTINUE;
        }
    }

    ByteBuf buf = chunk.content();
    if (!interrupt && !(handler instanceof StreamedAsyncHandler) && (buf.readableBytes() > 0 || last)) {
        HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
        interrupt = updateBodyAndInterrupt(future, handler, part);
    }

    if (interrupt || last)
        finishUpdate(future, channel, !last);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:27,代码来源:HttpHandler.java


示例5: onBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {

    if (accumulateBody) {
        responseBuilder.accumulate(bodyPart);
    }

    State state = State.CONTINUE;
    try {
        resumableListener.onBytesReceived(bodyPart.getBodyByteBuffer());
    } catch (IOException ex) {
        return AsyncHandler.State.ABORT;
    }

    if (decoratedAsyncHandler != null) {
        state = decoratedAsyncHandler.onBodyPartReceived(bodyPart);
    }

    byteTransferred.addAndGet(bodyPart.getBodyPartBytes().length);
    resumableProcessor.put(url, byteTransferred.get());

    return state;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:27,代码来源:ResumableAsyncHandler.java


示例6: testOnBodyPartReceivedWithDecoratedAsyncHandler

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Test
public void testOnBodyPartReceivedWithDecoratedAsyncHandler() throws Exception {
    HttpResponseBodyPart bodyPart = PowerMockito.mock(HttpResponseBodyPart.class);
    when(bodyPart.getBodyPartBytes()).thenReturn(new byte[0]);
    ByteBuffer buffer = ByteBuffer.allocate(0);
    when(bodyPart.getBodyByteBuffer()).thenReturn(buffer);

    @SuppressWarnings("unchecked")
    AsyncHandler<Response> decoratedAsyncHandler = mock(AsyncHandler.class);
    State mockState = mock(State.class);
    when(decoratedAsyncHandler.onBodyPartReceived(bodyPart)).thenReturn(mockState);

    // following is needed to set the url variable
    HttpResponseStatus mockResponseStatus = mock(HttpResponseStatus.class);
    when(mockResponseStatus.getStatusCode()).thenReturn(200);
    Uri mockUri = mock(Uri.class);
    when(mockUri.toUrl()).thenReturn("http://non.null");
    when(mockResponseStatus.getUri()).thenReturn(mockUri);

    ResumableAsyncHandler handler = new ResumableAsyncHandler(decoratedAsyncHandler);
    handler.onStatusReceived(mockResponseStatus);

    State state = handler.onBodyPartReceived(bodyPart);
    assertEquals(state, mockState, "State should be equal to the state returned from decoratedAsyncHandler");

}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:27,代码来源:ResumableAsyncHandlerTest.java


示例7: onPing

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public void onPing(HttpResponseBodyPart part) {
    for (WebSocketListener listener : listeners) {
        if (listener instanceof WebSocketPingListener)
            // bytes are cached in the part
            WebSocketPingListener.class.cast(listener).onPing(part.getBodyPartBytes());
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:NettyWebSocket.java


示例8: onPong

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public void onPong(HttpResponseBodyPart part) {
    for (WebSocketListener listener : listeners) {
        if (listener instanceof WebSocketPongListener)
            // bytes are cached in the part
            WebSocketPongListener.class.cast(listener).onPong(part.getBodyPartBytes());
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:NettyWebSocket.java


示例9: NettyResponse

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public NettyResponse(HttpResponseStatus status,//
        HttpResponseHeaders headers,//
        List<HttpResponseBodyPart> bodyParts) {
    this.bodyParts = bodyParts;
    this.headers = headers;
    this.status = status;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:NettyResponse.java


示例10: onBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
    // body arrived, flush headers
    if (!responseSet) {
        response = responseBuilder.build();
        responseSet = true;
        headersArrived.countDown();
    }

    output.write(bodyPart.getBodyPartBytes());
    return State.CONTINUE;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:12,代码来源:BodyDeferringAsyncHandler.java


示例11: onBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
    State s = State.CONTINUE;
    if (accumulateResponseBytes) {
        s = super.onBodyPartReceived(content);
    }
    fireOnBytesReceived(content.getBodyPartBytes());
    return s;
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:TransferCompletionHandler.java


示例12: zeroCopyFileTest

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Test(groups = "standalone")
public void zeroCopyFileTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException {
    File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt");
    tmp.deleteOnExit();
    try (AsyncHttpClient client = asyncHttpClient()) {
        try (FileOutputStream stream = new FileOutputStream(tmp)) {
            Response resp = client.preparePost("http://localhost:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler<Response>() {
                public void onThrowable(Throwable t) {
                }

                public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
                    stream.write(bodyPart.getBodyPartBytes());
                    return State.CONTINUE;
                }

                public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
                    return State.CONTINUE;
                }

                public State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
                    return State.CONTINUE;
                }

                public Response onCompleted() throws Exception {
                    return null;
                }
            }).get();
            assertNull(resp);
            assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length());
        }
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:33,代码来源:ZeroCopyFileTest.java


示例13: zeroCopyFileWithBodyManipulationTest

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Test(groups = "standalone")
public void zeroCopyFileWithBodyManipulationTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException {
    File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt");
    tmp.deleteOnExit();
    try (AsyncHttpClient client = asyncHttpClient()) {
        try (FileOutputStream stream = new FileOutputStream(tmp)) {
            Response resp = client.preparePost("http://localhost:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler<Response>() {
                public void onThrowable(Throwable t) {
                }

                public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {
                    stream.write(bodyPart.getBodyPartBytes());

                    if (bodyPart.getBodyPartBytes().length == 0) {
                        return State.ABORT;
                    }

                    return State.CONTINUE;
                }

                public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception {
                    return State.CONTINUE;
                }

                public State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
                    return State.CONTINUE;
                }

                public Response onCompleted() throws Exception {
                    return null;
                }
            }).get();
            assertNull(resp);
            assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length());
        }
    }
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:38,代码来源:ZeroCopyFileTest.java


示例14: onNext

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public void onNext(HttpResponseBodyPart t) {
    streamStarted.countDown();
    try {
        streamOnHold.await();
    } catch (InterruptedException e) {
        LOGGER.error("`streamOnHold` latch was interrupted", e);
    }
    super.onNext(t);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:11,代码来源:NettyReactiveStreamsTest.java


示例15: testOnBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Test
public void testOnBodyPartReceived() throws Exception {
    ResumableAsyncHandler handler = new ResumableAsyncHandler();
    HttpResponseBodyPart bodyPart = PowerMockito.mock(HttpResponseBodyPart.class);
    when(bodyPart.getBodyPartBytes()).thenReturn(new byte[0]);
    ByteBuffer buffer = ByteBuffer.allocate(0);
    when(bodyPart.getBodyByteBuffer()).thenReturn(buffer);
    State state = handler.onBodyPartReceived(bodyPart);
    assertEquals(state, AsyncHandler.State.CONTINUE, "State should be CONTINUE for a successful onBodyPartReceived");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:11,代码来源:ResumableAsyncHandlerTest.java


示例16: testOnBodyPartReceivedWithResumableListenerThrowsException

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Test
public void testOnBodyPartReceivedWithResumableListenerThrowsException() throws Exception {
    ResumableAsyncHandler handler = new ResumableAsyncHandler();

    ResumableListener resumableListener = PowerMockito.mock(ResumableListener.class);
    doThrow(new IOException()).when(resumableListener).onBytesReceived(anyObject());
    handler.setResumableListener(resumableListener);

    HttpResponseBodyPart bodyPart = PowerMockito.mock(HttpResponseBodyPart.class);
    State state = handler.onBodyPartReceived(bodyPart);
    assertEquals(state, AsyncHandler.State.ABORT,
            "State should be ABORT if the resumableListener threw an exception in onBodyPartReceived");
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:14,代码来源:ResumableAsyncHandlerTest.java


示例17: getBytes

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
public byte[] getBytes() throws Throwable {
    List<HttpResponseBodyPart> bodyParts = subscriber.getElements();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    for (HttpResponseBodyPart part : bodyParts) {
        bytes.write(part.getBodyPartBytes());
    }
    return bytes.toByteArray();
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:9,代码来源:ReactiveStreamsDownLoadTest.java


示例18: transactionMarker

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public void transactionMarker() throws Exception {
    AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger statusCode = new AtomicInteger();
    asyncHttpClient.prepareGet("http://localhost:" + getPort() + "/hello3/")
            .execute(new AsyncHandler<Response>() {
                @Override
                public State onBodyPartReceived(HttpResponseBodyPart part) {
                    return null;
                }
                @Override
                public Response onCompleted() throws Exception {
                    latch.countDown();
                    return null;
                }
                @Override
                public State onHeadersReceived(HttpResponseHeaders headers) {
                    return null;
                }
                @Override
                public State onStatusReceived(HttpResponseStatus status) {
                    statusCode.set(status.getStatusCode());
                    return null;
                }
                @Override
                public void onThrowable(Throwable t) {}
            });
    latch.await();
    asyncHttpClient.close();
    if (statusCode.get() != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:35,代码来源:AsyncHttpClientPluginIT.java


示例19: onBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
    monitorService.sendSize(content.length());
    return State.CONTINUE;
}
 
开发者ID:globocom,项目名称:groot,代码行数:6,代码来源:RequestExecutorService.java


示例20: onBodyPartReceived

import org.asynchttpclient.HttpResponseBodyPart; //导入依赖的package包/类
@Override
public State onBodyPartReceived(HttpResponseBodyPart bodyPart)
        throws Exception {
    httpResponseBodyPartLength.addAndGet(bodyPart.getBodyPartBytes().length);
    return asyncHandler.onBodyPartReceived(bodyPart);
}
 
开发者ID:yahoo,项目名称:metrics-api,代码行数:7,代码来源:ToyClientMetricsEmitter.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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