HTTPClient
Class BufferedInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--HTTPClient.BufferedInputStream

class BufferedInputStream
extends java.io.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.


Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
(package private) BufferedInputStream(java.io.InputStream stream)
          Create a new BufferedInputStream around the given input stream.
 
Method Summary
TypeMethod
 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(java.io.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 java.io.IOException
Read a single byte.
Overrides:
read in class java.io.FilterInputStream
Returns:
the read byte, or -1 if the end of the stream has been reached
Throws:
java.io.IOException - if thrown by the underlying stream

read

public int read(byte[] buf,
                int off,
                int len)
         throws java.io.IOException
Read a buffer full.
Overrides:
read in class java.io.FilterInputStream
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:
java.io.IOException - if thrown by the underlying stream

skip

public long skip(long n)
          throws java.io.IOException
Skip the given number of bytes in the stream.
Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped
Throws:
java.io.IOException - if thrown by the underlying stream

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.FilterInputStream
Returns:
the number of bytes available for reading without blocking
Throws:
java.io.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.