@Override public ChunkedBodyContents.Chunk next() { if (!hasMoreChunks) { throw new NoSuchElementException(); } try { ChunkedBodyContents.Chunk chunk = readNextChunk(inputStream); hasMoreChunks = chunk.size() > 0; if (!hasMoreChunks) { // throw away the trailer-part readTrailer(inputStream); } return chunk; } catch (IOException e) { throw new RuntimeException(e); } } };
@Override public ChunkedBodyContents.Chunk next() { if (!hasMoreChunks) { throw new NoSuchElementException(); } try { ChunkedBodyContents.Chunk chunk = readNextChunk(inputStream); hasMoreChunks = chunk.size() > 0; if (!hasMoreChunks) { // throw away the trailer-part readTrailer(inputStream); } return chunk; } catch (IOException e) { throw new RuntimeException(e); } } };
/** * Read the next chunk available from the source input stream. * <p> * The last chunk is always the empty chunk. After the empty chunk is returned, the message is completed * and calling this method again after that results in an {@link IllegalStateException}. * <p> * When the last chunk is returned, the trailer-part, if any, is also consumed and can be obtained by * calling the {@link InputStreamChunkDecoder#getTrailer()} method. * * @return the next chunk * @throws IOException if an error occurs while reading the original stream * @throws IllegalStateException if this method is called after the empty chunk is returned */ public ChunkedBodyContents.Chunk readChunk() throws IOException { if (done) { throw new IllegalStateException("HTTP message body is already consumed"); } ChunkedBodyContents.Chunk chunk = parser.readNextChunk(inputStream); if (chunk.size() == 0) { trailer = parser.readTrailer(inputStream); done = true; currentSource = null; } else { currentSource = new ByteArrayInputStream(chunk.getData()); } return chunk; }
/** * Read the next chunk available from the source input stream. * <p> * The last chunk is always the empty chunk. After the empty chunk is returned, the message is completed * and calling this method again after that results in an {@link IllegalStateException}. * <p> * When the last chunk is returned, the trailer-part, if any, is also consumed and can be obtained by * calling the {@link InputStreamChunkDecoder#getTrailer()} method. * * @return the next chunk * @throws IOException if an error occurs while reading the original stream * @throws IllegalStateException if this method is called after the empty chunk is returned */ public ChunkedBodyContents.Chunk readChunk() throws IOException { if (done) { throw new IllegalStateException("HTTP message body is already consumed"); } ChunkedBodyContents.Chunk chunk = parser.readNextChunk(inputStream); if (chunk.size() == 0) { trailer = parser.readTrailer(inputStream); done = true; currentSource = null; } else { currentSource = new ByteArrayInputStream(chunk.getData()); } return chunk; }