org.melati.util
Class DelimitedBufferedInputStream

Package class diagram package DelimitedBufferedInputStream
java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by org.melati.util.DelimitedBufferedInputStream
All Implemented Interfaces:
Closeable

public class DelimitedBufferedInputStream
extends BufferedInputStream

Like a BufferedInputStream except it has a new function readToDelimiter(byte[], int, int, byte[]) which will only read bytes upto the start of any occurrence of the delimiter in the InputStream.

See Also:
BufferedInputStream

Field Summary
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DelimitedBufferedInputStream(InputStream in)
          Creates a DelimitedBufferedInputStream and saves its argument, the input stream in, for later use.
DelimitedBufferedInputStream(InputStream in, int size)
          Creates a DelimitedBufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use.
 
Method Summary
 int getBufferLength()
          Used in tests.
 int getPotentialMatch()
          Used in tests.
 int indexOf(byte[] data1, byte[] data2, int fromIndex)
          Calculates length.
 int indexOf(byte[] data1, byte[] data2, int fromIndex, int len)
          Returns the index within data1 of the byte array data2.
 int readToDelimiter(byte[] b, int off, int len, byte[] delim)
          Reads bytes from this byte-input stream into the specified byte array, starting at the given offset, but we stop at the first occurrence of delim.
 
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelimitedBufferedInputStream

public DelimitedBufferedInputStream(InputStream in)
Creates a DelimitedBufferedInputStream and saves its argument, the input stream in, for later use. An internal buffer array is created and stored in buf.

Parameters:
in - the underlying input stream.

DelimitedBufferedInputStream

public DelimitedBufferedInputStream(InputStream in,
                                    int size)
Creates a DelimitedBufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use. An internal buffer array of length size is created and stored in buf.

Parameters:
in - the underlying input stream.
size - the buffer size.
Method Detail

readToDelimiter

public int readToDelimiter(byte[] b,
                           int off,
                           int len,
                           byte[] delim)
                    throws IOException
Reads bytes from this byte-input stream into the specified byte array, starting at the given offset, but we stop at the first occurrence of delim.

This method implements the general contract of the corresponding read method of the InputStream class. As an additional convenience, it attempts to read as many bytes as possible by repeatedly invoking the read method of the underlying stream. This iterated read continues until one of the following conditions becomes true:

If the first read on the underlying stream returns -1 to indicate end-of-file then this method returns -1. Otherwise this method returns the number of bytes actually read.

Subclasses of this class are encouraged, but not required, to attempt to read as many bytes as possible in the same fashion.

Parameters:
b - destination buffer.
off - offset at which to start storing bytes.
len - maximum number of bytes to read.
delim - the delimiter which we should stop reading at.
Returns:
the number of bytes read, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

indexOf

public int indexOf(byte[] data1,
                   byte[] data2,
                   int fromIndex)
Calculates length.

Returns the index within data1 of the byte array data2. It starts looking in data1 at fromIndex and only considers len bytes of data1

Parameters:
data1 - array to look in.
data2 - array to look for.
fromIndex - where to start looking from in data1.
Returns:
the index of data2 within data1 or -1 if data2 does not occur within data1

indexOf

public int indexOf(byte[] data1,
                   byte[] data2,
                   int fromIndex,
                   int len)
Returns the index within data1 of the byte array data2. It starts looking in data1 at fromIndex and only considers len bytes of data1

Parameters:
data1 - array to look in.
data2 - array to look for.
fromIndex - where to start looking from in data1.
len - maximum number of bytes of data1 to look in.
Returns:
the index of data2 within data1 or -1 if data2 does not occur within data1

getBufferLength

public int getBufferLength()
Used in tests.

Returns:
the buffer length

getPotentialMatch

public int getPotentialMatch()
Used in tests.

Returns:
the potentialMatch


Copyright © 2000-2010 PanEris. All Rights Reserved.