HTTPClient
Class BufferedInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byHTTPClient.BufferedInputStream

class BufferedInputStream
extends FilterInputStream

This class is similar to java.io.BufferedInputStream, except that it fixes certain bugs and provides support for finding multipart boundaries.

Note: none of the methods here are synchronized because we assume the caller is already taking care of that.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
(package private) BufferedInputStream(InputStream stream)
          Create a new BufferedInputStream around the given input stream.
 
Method Summary
 int available()
           
(package private)  void markForSearch()
          Mark the current read position so that we can start searching for the end boundary.
(package private)  int pastEnd(byte[] search, int[] search_cmp)
          Figures out how many bytes past the end of the multipart we read.
 int read()
          Read a single byte.
 int read(byte[] buf, int off, int len)
          Read a buffer full.
 long skip(long n)
          Skip the given number of bytes in the stream.
 
Methods inherited from class java.io.FilterInputStream
close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedInputStream

BufferedInputStream(InputStream stream)
Create a new BufferedInputStream around the given input stream.

Parameters:
stream - the underlying input stream to use
Method Detail

read

public int read()
         throws IOException
Read a single byte.

Returns:
the read byte, or -1 if the end of the stream has been reached
Throws:
IOException - if thrown by the underlying stream

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Read a buffer full.

Parameters:
buf - the buffer to read into
off - the offset within buf at which to start writing
len - the number of bytes to read
Returns:
the number of bytes read
Throws:
IOException - if thrown by the underlying stream

skip

public long skip(long n)
          throws IOException
Skip the given number of bytes in the stream.

Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped
Throws:
IOException - if thrown by the underlying stream

available

public int available()
              throws IOException
Returns:
the number of bytes available for reading without blocking
Throws:
IOException - if the buffer is empty and the underlying stream has been closed

markForSearch

void markForSearch()
Mark the current read position so that we can start searching for the end boundary.


pastEnd

int pastEnd(byte[] search,
            int[] search_cmp)
Figures out how many bytes past the end of the multipart we read. If we found the end, it then resets the read pos to just past the end of the boundary and unsets the mark; if not found, is sets the mark_pos back enough from the current position so we can always be sure to find the boundary.

Parameters:
search - the search string (end boundary)
search_cmp - the compiled info of the search string
Returns:
how many bytes past the end of the boundary we went; -1 if we haven't gone passed it yet.