result = new ChunkedInputStream(is, this); } else { if (getParams().isParameterTrue(HttpMethodParams.STRICT_TRANSFER_ENCODING)) {
/** * 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); }
/** * 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 { if (!bof) { readCRLF(); } chunkSize = getChunkSizeFromInputStream(in); bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
public static byte[] unchunkdata(byte[] contentBytes) throws IOException { byte[] unchunkedData = null; byte[] buffer = new byte[1024]; ByteArrayInputStream bis = new ByteArrayInputStream(contentBytes); ChunkedInputStream cis = new ChunkedInputStream(bis); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = -1; while ((read = cis.read(buffer)) != -1) { bos.write(buffer, 0, read); } unchunkedData = bos.toByteArray(); bos.close(); return unchunkedData; }
/** * <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 * * @see HttpMethod#getResponseFooters() */ public int read() throws IOException { if (closed) { throw new IOException("Attempted read from closed stream."); } if (eof) { return -1; } if (pos >= chunkSize) { nextChunk(); if (eof) { return -1; } } pos++; return in.read(); }
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { if (!bof) { readCRLF(); } chunkSize = getChunkSizeFromInputStream(in); bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
/** * 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; }
setInputStream(new ChunkedInputStream(is));
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { if (!bof) { readCRLF(); } chunkSize = getChunkSizeFromInputStream(in); bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
/** * <p>Reads until the end of the known length of content.</p> * * <p>Does not close the underlying socket input, but instead leaves it * primed to parse the next response.</p> * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { ChunkedInputStream.exhaustInputStream(this); } finally { // close after above so that we don't throw an exception trying // to read after closed! closed = true; } } }
/** * <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 * * @see HttpMethod#getResponseFooters() */ public int read() throws IOException { if (closed) { throw new IOException("Attempted read from closed stream."); } if (eof) { return -1; } if (pos >= chunkSize) { nextChunk(); if (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); }
setInputStream(new ChunkedInputStream(is));
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { if (!bof) { readCRLF(); } chunkSize = getChunkSizeFromInputStream(in); bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }
/** * <p>Reads until the end of the known length of content.</p> * * <p>Does not close the underlying socket input, but instead leaves it * primed to parse the next response.</p> * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { try { ChunkedInputStream.exhaustInputStream(this); } finally { // close after above so that we don't throw an exception trying // to read after closed! closed = true; } } }
/** * <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 * * @see HttpMethod#getResponseFooters() */ public int read() throws IOException { if (closed) { throw new IOException("Attempted read from closed stream."); } if (eof) { return -1; } if (pos >= chunkSize) { nextChunk(); if (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); }
socketIn = new ChunkedInputStream(socketIn);
/** * Read the next chunk. * @throws IOException If an IO error occurs. */ private void nextChunk() throws IOException { if (!bof) { readCRLF(); } chunkSize = getChunkSizeFromInputStream(in); bof = false; pos = 0; if (chunkSize == 0) { eof = true; parseTrailerHeaders(); } }