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


Java HttpResponseBodyPart类代码示例

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


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


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