io.netty.handler.stream.ChunkedInput Java Examples
The following examples show how to use
io.netty.handler.stream.ChunkedInput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChunkedWriteHandler.java From spring-boot-protocol with Apache License 2.0 | 6 votes |
PendingWrite(Object msg, ChannelPromise promise) { this.msg = msg; this.promise = promise; if(msg instanceof ByteBuf){ bytes = ((ByteBuf) msg).readableBytes(); }else if(msg instanceof ByteBuffer){ bytes = ((ByteBuffer) msg).remaining(); }else if(msg instanceof ByteBufHolder){ bytes = ((ByteBufHolder) msg).content().readableBytes(); }else if(msg instanceof ChunkedInput){ bytes = Math.max(((ChunkedInput) msg).length(),0); }else if(msg instanceof FileRegion){ bytes = ((FileRegion) msg).count() - ((FileRegion) msg).position(); }else { bytes = 0; } }
Example #2
Source File: SmtpSession.java From NioSmtpClient with Apache License 2.0 | 5 votes |
private static String objectToString(Object o) { if (o instanceof SmtpRequest) { SmtpRequest request = (SmtpRequest) o; if (request.command().equals(AUTH_COMMAND)) { return "<redacted-auth-command>"; } else { return String.format("%s %s", request.command().name(), Joiner.on(" ").join(request.parameters())); } } else if (o instanceof SmtpContent || o instanceof ByteBuf || o instanceof ChunkedInput) { return "[CONTENT]"; } else { return o.toString(); } }
Example #3
Source File: ModelView.java From Summer with Apache License 2.0 | 5 votes |
@Override public ChunkedInput<ByteBuf> getChunkedInput() { return new ChunkedInput<ByteBuf>() { @Override public boolean isEndOfInput() { return true; } @Override public void close() { byteBuf.clear(); } @Override public ByteBuf readChunk(ChannelHandlerContext ctx) { return null; } @Override public ByteBuf readChunk(ByteBufAllocator allocator) { return byteBuf; } @Override public long length() { return byteBuf.readableBytes(); } @Override public long progress() { return 0; } }; }
Example #4
Source File: HttpChunkedInputTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testWrappedReturnNull() throws Exception { HttpChunkedInput input = new HttpChunkedInput(new ChunkedInput<ByteBuf>() { @Override public boolean isEndOfInput() throws Exception { return false; } @Override public void close() throws Exception { // NOOP } @Override public ByteBuf readChunk(ChannelHandlerContext ctx) throws Exception { return null; } @Override public ByteBuf readChunk(ByteBufAllocator allocator) throws Exception { return null; } @Override public long length() { return 0; } @Override public long progress() { return 0; } }); assertNull(input.readChunk(ByteBufAllocator.DEFAULT)); }
Example #5
Source File: HttpChunkedInputTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private static void check(ChunkedInput<?>... inputs) { EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler()); for (ChunkedInput<?> input : inputs) { ch.writeOutbound(input); } assertTrue(ch.finish()); int i = 0; int read = 0; HttpContent lastHttpContent = null; for (;;) { HttpContent httpContent = ch.readOutbound(); if (httpContent == null) { break; } if (lastHttpContent != null) { assertTrue("Chunk must be DefaultHttpContent", lastHttpContent instanceof DefaultHttpContent); } ByteBuf buffer = httpContent.content(); while (buffer.isReadable()) { assertEquals(BYTES[i++], buffer.readByte()); read++; if (i == BYTES.length) { i = 0; } } buffer.release(); // Save last chunk lastHttpContent = httpContent; } assertEquals(BYTES.length * inputs.length, read); assertSame("Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT", LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent); }
Example #6
Source File: HttpChunkedInputTest.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
private static void check(ChunkedInput<?>... inputs) { EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler()); for (ChunkedInput<?> input : inputs) { ch.writeOutbound(input); } assertTrue(ch.finish()); int i = 0; int read = 0; HttpContent lastHttpContent = null; for (;;) { HttpContent httpContent = (HttpContent) ch.readOutbound(); if (httpContent == null) { break; } if (lastHttpContent != null) { assertTrue("Chunk must be DefaultHttpContent", lastHttpContent instanceof DefaultHttpContent); } ByteBuf buffer = httpContent.content(); while (buffer.isReadable()) { assertEquals(BYTES[i++], buffer.readByte()); read++; if (i == BYTES.length) { i = 0; } } buffer.release(); // Save last chunk lastHttpContent = httpContent; } assertEquals(BYTES.length * inputs.length, read); assertSame("Last chunk must be DefaultLastHttpContent", LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent); }
Example #7
Source File: ServletOutputStream.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
@Override public ChannelProgressivePromise write(ChunkedInput input) throws IOException { checkClosed(); writeResponseHeaderIfNeed(); ChannelHandlerContext context = servletHttpExchange.getChannelHandlerContext(); ChannelProgressivePromise promise = context.newProgressivePromise(); context.write(input,promise); return promise; }
Example #8
Source File: ChunkedWriteHandler.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
private static void handleEndOfInputFuture(ChannelFuture future, PendingWrite currentWrite) { ChunkedInput<?> input = (ChunkedInput<?>) currentWrite.msg; if (!future.isSuccess()) { closeInput(input); currentWrite.fail(future.cause()); } else { // read state of the input in local variables before closing it long inputProgress = input.progress(); long inputLength = input.length(); closeInput(input); currentWrite.progress(inputProgress, inputLength); currentWrite.success(inputLength); } }
Example #9
Source File: ChunkedWriteHandler.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
private void handleFuture(ChannelFuture future, PendingWrite currentWrite, boolean resume) { ChunkedInput<?> input = (ChunkedInput<?>) currentWrite.msg; if (!future.isSuccess()) { closeInput(input); currentWrite.fail(future.cause()); } else { currentWrite.progress(input.progress(), input.length()); if (resume && future.channel().isWritable()) { resumeTransfer(); } } }
Example #10
Source File: ChunkedWriteHandler.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
private static void closeInput(ChunkedInput<?> chunks) { try { chunks.close(); } catch (Throwable t) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Failed to close a chunked input.", t); } } }
Example #11
Source File: TextView.java From Summer with Apache License 2.0 | 5 votes |
@Override public ChunkedInput<ByteBuf> getChunkedInput() { return new ChunkedInput<ByteBuf>() { @Override public boolean isEndOfInput() { return true; } @Override public void close() { byteBuf.clear(); } @Override public ByteBuf readChunk(ChannelHandlerContext ctx) { return null; } @Override public ByteBuf readChunk(ByteBufAllocator allocator) { return byteBuf; } @Override public long length() { return byteBuf.readableBytes(); } @Override public long progress() { return 0; } }; }
Example #12
Source File: HttpChunkedInput.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
/** * Creates a new instance using the specified input. * @param input {@link ChunkedInput} containing data to write */ public HttpChunkedInput(ChunkedInput<ByteBuf> input) { this.input = input; lastHttpContent = LastHttpContent.EMPTY_LAST_CONTENT; }
Example #13
Source File: FileView.java From Summer with Apache License 2.0 | 4 votes |
@Override public ChunkedInput<ByteBuf> getChunkedInput() throws IOException { return new ChunkedFile(file); }
Example #14
Source File: ServletOutputStreamWrapper.java From spring-boot-protocol with Apache License 2.0 | 4 votes |
@Override public ChannelProgressivePromise write(ChunkedInput input) throws IOException { return source.write(input); }
Example #15
Source File: ChunkedInputs.java From glowroot with Apache License 2.0 | 4 votes |
static ChunkedInput<HttpContent> create(ChunkSource chunkSource) throws IOException { return new ChunkSourceChunkedInput(chunkSource); }
Example #16
Source File: ChunkedInputs.java From glowroot with Apache License 2.0 | 4 votes |
static ChunkedInput<HttpContent> createZipFileDownload(ChunkSource chunkSource, String fileName) throws IOException { return new ZipFileChunkedInput(chunkSource, fileName); }
Example #17
Source File: HttpChunkedInput.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Creates a new instance using the specified input.使用指定的输入创建一个新实例。 * @param input {@link ChunkedInput} containing data to write */ public HttpChunkedInput(ChunkedInput<ByteBuf> input) { this.input = input; lastHttpContent = LastHttpContent.EMPTY_LAST_CONTENT; }
Example #18
Source File: NettyClient.java From ambry with Apache License 2.0 | 3 votes |
/** * Sends the request and content to the server and returns a {@link Future} that tracks the arrival of a response for * the request. The {@link Future} and {@code callback} are triggered when the response is complete. * <p/> * Be sure to decrease the reference counts of each of the received response parts via a call to * {@link ReferenceCountUtil#release(Object)} once the part has been processed. Neglecting to do so might result in * OOM. * @param request the request that needs to be sent. * @param content the content accompanying the request. Can be null. * @param callback the callback to invoke when the response is available. Can be null. * @return a {@link Future} that tracks the arrival of the response for this request. */ public Future<ResponseParts> sendRequest(HttpRequest request, ChunkedInput<HttpContent> content, Callback<ResponseParts> callback) { this.request = request; this.content = content; this.callback = callback; resetState(); channelConnectFuture.addListener(requestSender); return responseFuture; }
Example #19
Source File: HttpChunkedInput.java From netty4.0.27Learn with Apache License 2.0 | 2 votes |
/** * Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating * chunk. * @param input {@link ChunkedInput} containing data to write * @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for * training headers. */ public HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent) { this.input = input; this.lastHttpContent = lastHttpContent; }
Example #20
Source File: WebSocketChunkedInput.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Creates a new instance using the specified input. * @param input {@link ChunkedInput} containing data to write * @param rsv RSV1, RSV2, RSV3 used for extensions * * @throws NullPointerException if {@code input} is null */ public WebSocketChunkedInput(ChunkedInput<ByteBuf> input, int rsv) { this.input = ObjectUtil.checkNotNull(input, "input"); this.rsv = rsv; }
Example #21
Source File: WebSocketChunkedInput.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Creates a new instance using the specified input. * @param input {@link ChunkedInput} containing data to write */ public WebSocketChunkedInput(ChunkedInput<ByteBuf> input) { this(input, 0); }
Example #22
Source File: HttpChunkedInput.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Creates a new instance using the specified input. {@code lastHttpContent} will be written as the terminating * chunk.使用指定的输入创建一个新实例。lastHttpContent将作为终止块编写。 * @param input {@link ChunkedInput} containing data to write * @param lastHttpContent {@link LastHttpContent} that will be written as the terminating chunk. Use this for * training headers. */ public HttpChunkedInput(ChunkedInput<ByteBuf> input, LastHttpContent lastHttpContent) { this.input = input; this.lastHttpContent = lastHttpContent; }
Example #23
Source File: WebView.java From Summer with Apache License 2.0 | votes |
ChunkedInput<ByteBuf> getChunkedInput() throws IOException;