0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage sun.net.www.http;
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/Aimport sun.net.*;
0N/Aimport sun.net.www.*;
0N/A
0N/A/**
0N/A * A <code>ChunkedInputStream</code> provides a stream for reading a body of
0N/A * a http message that can be sent as a series of chunks, each with its own
0N/A * size indicator. Optionally the last chunk can be followed by trailers
0N/A * containing entity-header fields.
0N/A * <p>
0N/A * A <code>ChunkedInputStream</code> is also <code>Hurryable</code> so it
0N/A * can be hurried to the end of the stream if the bytes are available on
0N/A * the underlying stream.
0N/A */
0N/Apublic
0N/Aclass ChunkedInputStream extends InputStream implements Hurryable {
0N/A
0N/A /**
0N/A * The underlying stream
0N/A */
0N/A private InputStream in;
0N/A
0N/A /**
0N/A * The <code>HttpClient</code> that should be notified when the chunked stream has
0N/A * completed.
0N/A */
0N/A private HttpClient hc;
0N/A
0N/A /**
0N/A * The <code>MessageHeader</code> that is populated with any optional trailer
0N/A * that appear after the last chunk.
0N/A */
0N/A private MessageHeader responses;
0N/A
0N/A /**
0N/A * The size, in bytes, of the chunk that is currently being read.
0N/A * This size is only valid if the current position in the underlying
0N/A * input stream is inside a chunk (ie: state == STATE_READING_CHUNK).
0N/A */
0N/A private int chunkSize;
0N/A
0N/A /**
0N/A * The number of bytes read from the underlying stream for the current
0N/A * chunk. This value is always in the range <code>0</code> through to
0N/A * <code>chunkSize</code>
0N/A */
0N/A private int chunkRead;
0N/A
0N/A /**
0N/A * The internal buffer array where chunk data is available for the
0N/A * application to read.
0N/A */
0N/A private byte chunkData[] = new byte[4096];
0N/A
0N/A /**
0N/A * The current position in the buffer. It contains the index
0N/A * of the next byte to read from <code>chunkData</code>
0N/A */
0N/A private int chunkPos;
0N/A
0N/A /**
0N/A * The index one greater than the index of the last valid byte in the
0N/A * buffer. This value is always in the range <code>0</code> through
0N/A * <code>chunkData.length</code>.
0N/A */
0N/A private int chunkCount;
0N/A
0N/A /**
0N/A * The internal buffer where bytes from the underlying stream can be
0N/A * read. It may contain bytes representing chunk-size, chunk-data, or
0N/A * trailer fields.
0N/A */
0N/A private byte rawData[] = new byte[32];
0N/A
0N/A /**
0N/A * The current position in the buffer. It contains the index
0N/A * of the next byte to read from <code>rawData</code>
0N/A */
0N/A private int rawPos;
0N/A
0N/A /**
0N/A * The index one greater than the index of the last valid byte in the
0N/A * buffer. This value is always in the range <code>0</code> through
0N/A * <code>rawData.length</code>.
0N/A */
0N/A private int rawCount;
0N/A
0N/A /**
0N/A * Indicates if an error was encountered when processing the chunked
0N/A * stream.
0N/A */
0N/A private boolean error;
0N/A
0N/A /**
0N/A * Indicates if the chunked stream has been closed using the
0N/A * <code>close</code> method.
0N/A */
0N/A private boolean closed;
0N/A
5683N/A /*
5683N/A * Maximum chunk header size of 2KB + 2 bytes for CRLF
5683N/A */
5683N/A private final static int MAX_CHUNK_HEADER_SIZE = 2050;
5683N/A
0N/A /**
0N/A * State to indicate that next field should be :-
0N/A * chunk-size [ chunk-extension ] CRLF
0N/A */
0N/A static final int STATE_AWAITING_CHUNK_HEADER = 1;
0N/A
0N/A /**
0N/A * State to indicate that we are currently reading the chunk-data.
0N/A */
0N/A static final int STATE_READING_CHUNK = 2;
0N/A
0N/A /**
0N/A * Indicates that a chunk has been completely read and the next
0N/A * fields to be examine should be CRLF
0N/A */
0N/A static final int STATE_AWAITING_CHUNK_EOL = 3;
0N/A
0N/A /**
0N/A * Indicates that all chunks have been read and the next field
0N/A * should be optional trailers or an indication that the chunked
0N/A * stream is complete.
0N/A */
0N/A static final int STATE_AWAITING_TRAILERS = 4;
0N/A
0N/A /**
0N/A * State to indicate that the chunked stream is complete and
0N/A * no further bytes should be read from the underlying stream.
0N/A */
0N/A static final int STATE_DONE = 5;
0N/A
0N/A /**
0N/A * Indicates the current state.
0N/A */
0N/A private int state;
0N/A
0N/A
0N/A /**
0N/A * Check to make sure that this stream has not been closed.
0N/A */
0N/A private void ensureOpen() throws IOException {
0N/A if (closed) {
0N/A throw new IOException("stream is closed");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Ensures there is <code>size</code> bytes available in
0N/A * <code>rawData</code>. This requires that we either
0N/A * shift the bytes in use to the begining of the buffer
0N/A * or allocate a large buffer with sufficient space available.
0N/A */
0N/A private void ensureRawAvailable(int size) {
0N/A if (rawCount + size > rawData.length) {
0N/A int used = rawCount - rawPos;
0N/A if (used + size > rawData.length) {
0N/A byte tmp[] = new byte[used + size];
0N/A if (used > 0) {
0N/A System.arraycopy(rawData, rawPos, tmp, 0, used);
0N/A }
0N/A rawData = tmp;
0N/A } else {
0N/A if (used > 0) {
0N/A System.arraycopy(rawData, rawPos, rawData, 0, used);
0N/A }
0N/A }
0N/A rawCount = used;
0N/A rawPos = 0;
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Close the underlying input stream by either returning it to the
0N/A * keep alive cache or closing the stream.
0N/A * <p>
0N/A * As a chunked stream is inheritly persistent (see HTTP 1.1 RFC) the
0N/A * underlying stream can be returned to the keep alive cache if the
0N/A * stream can be completely read without error.
0N/A */
0N/A private void closeUnderlying() throws IOException {
0N/A if (in == null) {
0N/A return;
0N/A }
0N/A
0N/A if (!error && state == STATE_DONE) {
0N/A hc.finished();
0N/A } else {
0N/A if (!hurry()) {
0N/A hc.closeServer();
0N/A }
0N/A }
0N/A
0N/A in = null;
0N/A }
0N/A
0N/A /**
0N/A * Attempt to read the remainder of a chunk directly into the
0N/A * caller's buffer.
0N/A * <p>
0N/A * Return the number of bytes read.
0N/A */
0N/A private int fastRead(byte[] b, int off, int len) throws IOException {
0N/A
0N/A // assert state == STATE_READING_CHUNKS;
0N/A
0N/A int remaining = chunkSize - chunkRead;
0N/A int cnt = (remaining < len) ? remaining : len;
0N/A if (cnt > 0) {
0N/A int nread;
0N/A try {
0N/A nread = in.read(b, off, cnt);
0N/A } catch (IOException e) {
0N/A error = true;
0N/A throw e;
0N/A }
0N/A if (nread > 0) {
0N/A chunkRead += nread;
0N/A if (chunkRead >= chunkSize) {
0N/A state = STATE_AWAITING_CHUNK_EOL;
0N/A }
0N/A return nread;
0N/A }
0N/A error = true;
0N/A throw new IOException("Premature EOF");
0N/A } else {
0N/A return 0;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Process any outstanding bytes that have already been read into
0N/A * <code>rawData</code>.
0N/A * <p>
0N/A * The parsing of the chunked stream is performed as a state machine with
0N/A * <code>state</code> representing the current state of the processing.
0N/A * <p>
0N/A * Returns when either all the outstanding bytes in rawData have been
0N/A * processed or there is insufficient bytes available to continue
0N/A * processing. When the latter occurs <code>rawPos</code> will not have
0N/A * been updated and thus the processing can be restarted once further
0N/A * bytes have been read into <code>rawData</code>.
0N/A */
0N/A private void processRaw() throws IOException {
0N/A int pos;
0N/A int i;
0N/A
0N/A while (state != STATE_DONE) {
0N/A
0N/A switch (state) {
0N/A
0N/A /**
0N/A * We are awaiting a line with a chunk header
0N/A */
0N/A case STATE_AWAITING_CHUNK_HEADER:
0N/A /*
0N/A * Find \n to indicate end of chunk header. If not found when there is
0N/A * insufficient bytes in the raw buffer to parse a chunk header.
0N/A */
0N/A pos = rawPos;
0N/A while (pos < rawCount) {
0N/A if (rawData[pos] == '\n') {
0N/A break;
0N/A }
0N/A pos++;
5683N/A if ((pos - rawPos) >= MAX_CHUNK_HEADER_SIZE) {
5683N/A error = true;
5683N/A throw new IOException("Chunk header too long");
5683N/A }
0N/A }
0N/A if (pos >= rawCount) {
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * Extract the chunk size from the header (ignoring extensions).
0N/A */
0N/A String header = new String(rawData, rawPos, pos-rawPos+1, "US-ASCII");
0N/A for (i=0; i < header.length(); i++) {
0N/A if (Character.digit(header.charAt(i), 16) == -1)
0N/A break;
0N/A }
0N/A try {
0N/A chunkSize = Integer.parseInt(header.substring(0, i), 16);
0N/A } catch (NumberFormatException e) {
0N/A error = true;
0N/A throw new IOException("Bogus chunk size");
0N/A }
0N/A
0N/A /*
0N/A * Chunk has been parsed so move rawPos to first byte of chunk
0N/A * data.
0N/A */
0N/A rawPos = pos + 1;
0N/A chunkRead = 0;
0N/A
0N/A /*
0N/A * A chunk size of 0 means EOF.
0N/A */
0N/A if (chunkSize > 0) {
0N/A state = STATE_READING_CHUNK;
0N/A } else {
0N/A state = STATE_AWAITING_TRAILERS;
0N/A }
0N/A break;
0N/A
0N/A
0N/A /**
0N/A * We are awaiting raw entity data (some may have already been
0N/A * read). chunkSize is the size of the chunk; chunkRead is the
0N/A * total read from the underlying stream to date.
0N/A */
0N/A case STATE_READING_CHUNK :
0N/A /* no data available yet */
0N/A if (rawPos >= rawCount) {
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * Compute the number of bytes of chunk data available in the
0N/A * raw buffer.
0N/A */
0N/A int copyLen = Math.min( chunkSize-chunkRead, rawCount-rawPos );
0N/A
0N/A /*
0N/A * Expand or compact chunkData if needed.
0N/A */
0N/A if (chunkData.length < chunkCount + copyLen) {
0N/A int cnt = chunkCount - chunkPos;
0N/A if (chunkData.length < cnt + copyLen) {
0N/A byte tmp[] = new byte[cnt + copyLen];
0N/A System.arraycopy(chunkData, chunkPos, tmp, 0, cnt);
0N/A chunkData = tmp;
0N/A } else {
0N/A System.arraycopy(chunkData, chunkPos, chunkData, 0, cnt);
0N/A }
0N/A chunkPos = 0;
0N/A chunkCount = cnt;
0N/A }
0N/A
0N/A /*
0N/A * Copy the chunk data into chunkData so that it's available
0N/A * to the read methods.
0N/A */
0N/A System.arraycopy(rawData, rawPos, chunkData, chunkCount, copyLen);
0N/A rawPos += copyLen;
0N/A chunkCount += copyLen;
0N/A chunkRead += copyLen;
0N/A
0N/A /*
0N/A * If all the chunk has been copied into chunkData then the next
0N/A * token should be CRLF.
0N/A */
0N/A if (chunkSize - chunkRead <= 0) {
0N/A state = STATE_AWAITING_CHUNK_EOL;
0N/A } else {
0N/A return;
0N/A }
0N/A break;
0N/A
0N/A
0N/A /**
0N/A * Awaiting CRLF after the chunk
0N/A */
0N/A case STATE_AWAITING_CHUNK_EOL:
0N/A /* not available yet */
0N/A if (rawPos + 1 >= rawCount) {
0N/A return;
0N/A }
0N/A
0N/A if (rawData[rawPos] != '\r') {
0N/A error = true;
0N/A throw new IOException("missing CR");
0N/A }
0N/A if (rawData[rawPos+1] != '\n') {
0N/A error = true;
0N/A throw new IOException("missing LF");
0N/A }
0N/A rawPos += 2;
0N/A
0N/A /*
0N/A * Move onto the next chunk
0N/A */
0N/A state = STATE_AWAITING_CHUNK_HEADER;
0N/A break;
0N/A
0N/A
0N/A /**
0N/A * Last chunk has been read so not we're waiting for optional
0N/A * trailers.
0N/A */
0N/A case STATE_AWAITING_TRAILERS:
0N/A
0N/A /*
0N/A * Do we have an entire line in the raw buffer?
0N/A */
0N/A pos = rawPos;
0N/A while (pos < rawCount) {
0N/A if (rawData[pos] == '\n') {
0N/A break;
0N/A }
0N/A pos++;
0N/A }
0N/A if (pos >= rawCount) {
0N/A return;
0N/A }
0N/A
0N/A if (pos == rawPos) {
0N/A error = true;
0N/A throw new IOException("LF should be proceeded by CR");
0N/A }
0N/A if (rawData[pos-1] != '\r') {
0N/A error = true;
0N/A throw new IOException("LF should be proceeded by CR");
0N/A }
0N/A
0N/A /*
0N/A * Stream done so close underlying stream.
0N/A */
0N/A if (pos == (rawPos + 1)) {
0N/A
0N/A state = STATE_DONE;
0N/A closeUnderlying();
0N/A
0N/A return;
0N/A }
0N/A
0N/A /*
0N/A * Extract any tailers and append them to the message
0N/A * headers.
0N/A */
0N/A String trailer = new String(rawData, rawPos, pos-rawPos, "US-ASCII");
0N/A i = trailer.indexOf(':');
0N/A if (i == -1) {
0N/A throw new IOException("Malformed tailer - format should be key:value");
0N/A }
0N/A String key = (trailer.substring(0, i)).trim();
0N/A String value = (trailer.substring(i+1, trailer.length())).trim();
0N/A
0N/A responses.add(key, value);
0N/A
0N/A /*
0N/A * Move onto the next trailer.
0N/A */
0N/A rawPos = pos+1;
0N/A break;
0N/A
0N/A } /* switch */
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Reads any available bytes from the underlying stream into
0N/A * <code>rawData</code> and returns the number of bytes of
0N/A * chunk data available in <code>chunkData</code> that the
0N/A * application can read.
0N/A */
0N/A private int readAheadNonBlocking() throws IOException {
0N/A
0N/A /*
0N/A * If there's anything available on the underlying stream then we read
0N/A * it into the raw buffer and process it. Processing ensures that any
0N/A * available chunk data is made available in chunkData.
0N/A */
0N/A int avail = in.available();
0N/A if (avail > 0) {
0N/A
0N/A /* ensure that there is space in rawData to read the available */
0N/A ensureRawAvailable(avail);
0N/A
0N/A int nread;
0N/A try {
0N/A nread = in.read(rawData, rawCount, avail);
0N/A } catch (IOException e) {
0N/A error = true;
0N/A throw e;
0N/A }
0N/A if (nread < 0) {
0N/A error = true; /* premature EOF ? */
0N/A return -1;
0N/A }
0N/A rawCount += nread;
0N/A
0N/A /*
0N/A * Process the raw bytes that have been read.
0N/A */
0N/A processRaw();
0N/A }
0N/A
0N/A /*
0N/A * Return the number of chunked bytes available to read
0N/A */
0N/A return chunkCount - chunkPos;
0N/A }
0N/A
0N/A /**
0N/A * Reads from the underlying stream until there is chunk data
0N/A * available in <code>chunkData</code> for the application to
0N/A * read.
0N/A */
0N/A private int readAheadBlocking() throws IOException {
0N/A
0N/A do {
0N/A /*
0N/A * All of chunked response has been read to return EOF.
0N/A */
0N/A if (state == STATE_DONE) {
0N/A return -1;
0N/A }
0N/A
0N/A /*
0N/A * We must read into the raw buffer so make sure there is space
0N/A * available. We use a size of 32 to avoid too much chunk data
0N/A * being read into the raw buffer.
0N/A */
0N/A ensureRawAvailable(32);
0N/A int nread;
0N/A try {
0N/A nread = in.read(rawData, rawCount, rawData.length-rawCount);
0N/A } catch (IOException e) {
0N/A error = true;
0N/A throw e;
0N/A }
0N/A
0N/A /**
0N/A * If we hit EOF it means there's a problem as we should never
0N/A * attempt to read once the last chunk and trailers have been
0N/A * received.
0N/A */
0N/A if (nread < 0) {
0N/A error = true;
0N/A throw new IOException("Premature EOF");
0N/A }
0N/A
0N/A /**
0N/A * Process the bytes from the underlying stream
0N/A */
0N/A rawCount += nread;
0N/A processRaw();
0N/A
0N/A } while (chunkCount <= 0);
0N/A
0N/A /*
0N/A * Return the number of chunked bytes available to read
0N/A */
0N/A return chunkCount - chunkPos;
0N/A }
0N/A
0N/A /**
0N/A * Read ahead in either blocking or non-blocking mode. This method
0N/A * is typically used when we run out of available bytes in
0N/A * <code>chunkData</code> or we need to determine how many bytes
0N/A * are available on the input stream.
0N/A */
0N/A private int readAhead(boolean allowBlocking) throws IOException {
0N/A
0N/A /*
0N/A * Last chunk already received - return EOF
0N/A */
0N/A if (state == STATE_DONE) {
0N/A return -1;
0N/A }
0N/A
0N/A /*
0N/A * Reset position/count if data in chunkData is exhausted.
0N/A */
0N/A if (chunkPos >= chunkCount) {
0N/A chunkCount = 0;
0N/A chunkPos = 0;
0N/A }
0N/A
0N/A /*
0N/A * Read ahead blocking or non-blocking
0N/A */
0N/A if (allowBlocking) {
0N/A return readAheadBlocking();
0N/A } else {
0N/A return readAheadNonBlocking();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>ChunkedInputStream</code> and saves its arguments, for
0N/A * later use.
0N/A *
0N/A * @param in the underlying input stream.
0N/A * @param hc the HttpClient
0N/A * @param responses the MessageHeader that should be populated with optional
0N/A * trailers.
0N/A */
0N/A public ChunkedInputStream(InputStream in, HttpClient hc, MessageHeader responses) throws IOException {
0N/A
0N/A /* save arguments */
0N/A this.in = in;
0N/A this.responses = responses;
0N/A this.hc = hc;
0N/A
0N/A /*
0N/A * Set our initial state to indicate that we are first starting to
0N/A * look for a chunk header.
0N/A */
0N/A state = STATE_AWAITING_CHUNK_HEADER;
0N/A }
0N/A
0N/A /**
0N/A * See
0N/A * the general contract of the <code>read</code>
0N/A * method of <code>InputStream</code>.
0N/A *
0N/A * @return the next byte of data, or <code>-1</code> if the end of the
0N/A * stream is reached.
0N/A * @exception IOException if an I/O error occurs.
0N/A * @see java.io.FilterInputStream#in
0N/A */
0N/A public synchronized int read() throws IOException {
0N/A ensureOpen();
0N/A if (chunkPos >= chunkCount) {
0N/A if (readAhead(true) <= 0) {
0N/A return -1;
0N/A }
0N/A }
0N/A return chunkData[chunkPos++] & 0xff;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Reads bytes from this stream into the specified byte array, starting at
0N/A * the given offset.
0N/A *
0N/A * @param b destination buffer.
0N/A * @param off offset at which to start storing bytes.
0N/A * @param len maximum number of bytes to read.
0N/A * @return the number of bytes read, or <code>-1</code> if the end of
0N/A * the stream has been reached.
0N/A * @exception IOException if an I/O error occurs.
0N/A */
0N/A public synchronized int read(byte b[], int off, int len)
0N/A throws IOException
0N/A {
0N/A ensureOpen();
0N/A if ((off < 0) || (off > b.length) || (len < 0) ||
0N/A ((off + len) > b.length) || ((off + len) < 0)) {
0N/A throw new IndexOutOfBoundsException();
0N/A } else if (len == 0) {
0N/A return 0;
0N/A }
0N/A
0N/A int avail = chunkCount - chunkPos;
0N/A if (avail <= 0) {
0N/A /*
0N/A * Optimization: if we're in the middle of the chunk read
0N/A * directly from the underlying stream into the caller's
0N/A * buffer
0N/A */
0N/A if (state == STATE_READING_CHUNK) {
0N/A return fastRead( b, off, len );
0N/A }
0N/A
0N/A /*
0N/A * We're not in the middle of a chunk so we must read ahead
0N/A * until there is some chunk data available.
0N/A */
0N/A avail = readAhead(true);
0N/A if (avail < 0) {
0N/A return -1; /* EOF */
0N/A }
0N/A }
0N/A int cnt = (avail < len) ? avail : len;
0N/A System.arraycopy(chunkData, chunkPos, b, off, cnt);
0N/A chunkPos += cnt;
0N/A
0N/A return cnt;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of bytes that can be read from this input
0N/A * stream without blocking.
0N/A *
0N/A * @return the number of bytes that can be read from this input
0N/A * stream without blocking.
0N/A * @exception IOException if an I/O error occurs.
0N/A * @see java.io.FilterInputStream#in
0N/A */
0N/A public synchronized int available() throws IOException {
0N/A ensureOpen();
0N/A
0N/A int avail = chunkCount - chunkPos;
0N/A if(avail > 0) {
0N/A return avail;
0N/A }
0N/A
0N/A avail = readAhead(false);
0N/A
0N/A if (avail < 0) {
0N/A return 0;
0N/A } else {
0N/A return avail;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Close the stream by either returning the connection to the
0N/A * keep alive cache or closing the underlying stream.
0N/A * <p>
0N/A * If the chunked response hasn't been completely read we
0N/A * try to "hurry" to the end of the response. If this is
0N/A * possible (without blocking) then the connection can be
0N/A * returned to the keep alive cache.
0N/A *
0N/A * @exception IOException if an I/O error occurs.
0N/A */
0N/A public synchronized void close() throws IOException {
0N/A if (closed) {
0N/A return;
0N/A }
0N/A closeUnderlying();
0N/A closed = true;
0N/A }
0N/A
0N/A /**
0N/A * Hurry the input stream by reading everything from the underlying
0N/A * stream. If the last chunk (and optional trailers) can be read without
0N/A * blocking then the stream is considered hurried.
0N/A * <p>
0N/A * Note that if an error has occured or we can't get to last chunk
0N/A * without blocking then this stream can't be hurried and should be
0N/A * closed.
0N/A */
0N/A public synchronized boolean hurry() {
0N/A if (in == null || error) {
0N/A return false;
0N/A }
0N/A
0N/A try {
0N/A readAhead(false);
0N/A } catch (Exception e) {
0N/A return false;
0N/A }
0N/A
0N/A if (error) {
0N/A return false;
0N/A }
0N/A
0N/A return (state == STATE_DONE);
0N/A }
0N/A
0N/A}