/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { chunkSize = getChunkSize(); if (chunkSize < 0) { throw new MalformedChunkCodingException("Negative chunk size"); } bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
/** * <p> Returns all the data in a chunked stream in coalesced form. A chunk * is followed by a CRLF. The method returns -1 as soon as a chunksize of 0 * is detected.</p> * * <p> Trailer headers are read automcatically at the end of the stream and * can be obtained with the getResponseFooters() method.</p> * * @return -1 of the end of the stream has been reached or the next data * byte * @throws IOException If an IO problem occurs */ public int read() throws IOException { if (this.closed) { throw new IOException("Attempted read from closed stream."); } if (this.eof) { return -1; } if (this.pos >= this.chunkSize) { nextChunk(); if (this.eof) { return -1; } } pos++; return in.read(); }
/** * Read some bytes from the stream. * @param b The byte array that will hold the contents from the stream. * @return The number of bytes returned or -1 if the end of stream has been * reached. * @see java.io.InputStream#read(byte[]) * @throws IOException if an IO problem occurs. */ public int read (byte[] b) throws IOException { return read(b, 0, b.length); }
entity.setChunked(true); entity.setContentLength(-1); entity.setContent(new ChunkedInputStream(inbuffer)); } else if (len == ContentLengthStrategy.IDENTITY) { entity.setChunked(false);
/** * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { if (!eof) { exhaustInputStream(this); } } finally { eof = true; closed = true; } } }
private static byte[] unchunk(byte[] content) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(content); ChunkedInputStream cis = new ChunkedInputStream(bais, new HttpClient() {}, null); return readFully(cis); }
/** * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { if (!eof) { exhaustInputStream(this); } } finally { eof = true; closed = true; } } }
/** * Read the next chunk. * @throws IOException in case of an I/O error */ private void nextChunk() throws IOException { if (state == CHUNK_INVALID) { throw new MalformedChunkCodingException("Corrupt data stream"); } try { chunkSize = getChunkSize(); if (chunkSize < 0L) { throw new MalformedChunkCodingException("Negative chunk size"); } state = CHUNK_DATA; pos = 0L; if (chunkSize == 0L) { eof = true; parseTrailerHeaders(); } } catch (MalformedChunkCodingException ex) { state = CHUNK_INVALID; throw ex; } }
protected InputStream createInputStream( final long len, final SessionInputBuffer inbuffer) { if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(inbuffer); } else if (len == ContentLengthStrategy.IDENTITY) { return new IdentityInputStream(inbuffer); } else { return new ContentLengthInputStream(inbuffer, len); } }
/** * Read some bytes from the stream. * @param b The byte array that will hold the contents from the stream. * @param off The offset into the byte array at which bytes will start to be * placed. * @param len the maximum number of bytes that can be returned. * @return The number of bytes returned or -1 if the end of stream has been * reached. * @see java.io.InputStream#read(byte[], int, int) * @throws IOException if an IO problem occurs. */ public int read (byte[] b, int off, int len) throws IOException { if (closed) { throw new IOException("Attempted read from closed stream."); } if (eof) { return -1; } if (pos >= chunkSize) { nextChunk(); if (eof) { return -1; } } len = Math.min(len, chunkSize - pos); int count = in.read(b, off, len); pos += count; return count; }
/** * Read some bytes from the stream. * @param b The byte array that will hold the contents from the stream. * @return The number of bytes returned or -1 if the end of stream has been * reached. * @throws IOException in case of an I/O error */ @Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
/** * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { if (!eof) { exhaustInputStream(this); } } finally { eof = true; closed = true; } } }
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { chunkSize = getChunkSize(); if (chunkSize < 0) { throw new MalformedChunkCodingException("Negative chunk size"); } bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
protected InputStream createInputStream( final long len, final SessionInputBuffer inbuffer) { if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(inbuffer, this.messageConstraints); } else if (len == ContentLengthStrategy.IDENTITY) { return new IdentityInputStream(inbuffer); } else if (len == 0L) { return EmptyInputStream.INSTANCE; } else { return new ContentLengthInputStream(inbuffer, len); } }
nextChunk(); if (this.eof) { return -1;
/** * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. * @throws IOException in case of an I/O error */ @Override public void close() throws IOException { if (!closed) { try { if (!eof && state != CHUNK_INVALID) { // read and discard the remainder of the message final byte[] buff = new byte[BUFFER_SIZE]; try { while (read(buff) >= 0) { continue; } } catch (ConnectionClosedException e) { // just ignore } catch (TruncatedChunkException e) { // just ignore } } } finally { eof = true; closed = true; } } }
/** * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { if (!eof) { exhaustInputStream(this); } } finally { eof = true; closed = true; } } }
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { chunkSize = getChunkSize(); if (chunkSize < 0) { throw new MalformedChunkCodingException("Negative chunk size"); } bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
protected InputStream createInputStream( final long len, final SessionInputBuffer inbuffer) { if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(inbuffer, this.messageConstraints); } else if (len == ContentLengthStrategy.IDENTITY) { return new IdentityInputStream(inbuffer); } else if (len == 0L) { return EmptyInputStream.INSTANCE; } else { return new ContentLengthInputStream(inbuffer, len); } }
nextChunk(); if (eof) { return -1;