org.basex.io.in
Class BufferInput

java.lang.Object
  extended by java.io.InputStream
      extended by org.basex.io.in.BufferInput
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
ArrayInput, DataInput, TextInput

public class BufferInput
extends java.io.InputStream

This class uses an internal buffer to speed up input stream processing.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
protected  int bpos
          Current buffer position.
protected  int bsize
          Current buffer size.
protected  byte[] buffer
          Byte buffer.
protected  IO input
          Input file.
protected  long length
          Total length of input to be processed (-1 if unknown).
 
Constructor Summary
protected BufferInput(byte[] array)
          Empty constructor with fixed input.
  BufferInput(java.io.InputStream is)
          Constructor.
  BufferInput(java.io.InputStream is, int bs)
          Initializes the file reader.
  BufferInput(IO io)
          Constructor.
 
Method Summary
 void close()
           
 byte[] content()
          Retrieves and returns the whole data and closes the stream.
 IO io()
          Returns the IO reference, or null.
 long length()
          Returns the input length (may be -1).
 void mark(int m)
           
 boolean markSupported()
           
 int read()
          Returns the next byte.
protected  int readByte()
          Returns the next unsigned byte.
 byte[] readBytes()
          Reads a byte array from the input stream, suffixed by a 0 byte.
 java.lang.String readString()
          Reads a string from the input stream, suffixed by a 0 byte.
 void reset()
           
 int size()
          Returns the number of read bytes.
 
Methods inherited from class java.io.InputStream
available, read, read, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected final byte[] buffer
Byte buffer.


bpos

protected int bpos
Current buffer position.


bsize

protected int bsize
Current buffer size.


length

protected long length
Total length of input to be processed (-1 if unknown).


input

protected IO input
Input file.

Constructor Detail

BufferInput

public BufferInput(IO io)
            throws java.io.IOException
Constructor.

Parameters:
io - input to be read
Throws:
java.io.IOException - I/O Exception

BufferInput

public BufferInput(java.io.InputStream is)
Constructor.

Parameters:
is - input stream

BufferInput

public BufferInput(java.io.InputStream is,
                   int bs)
Initializes the file reader.

Parameters:
is - input stream
bs - buffer size

BufferInput

protected BufferInput(byte[] array)
Empty constructor with fixed input.

Parameters:
array - array input
Method Detail

io

public IO io()
Returns the IO reference, or null.

Returns:
file reference

read

public int read()
         throws java.io.IOException
Returns the next byte. By default, this method calls readByte(); -1 is returned if all bytes have been read.

Specified by:
read in class java.io.InputStream
Returns:
next byte
Throws:
java.io.IOException - I/O exception
See Also:
InputStream.read()

readByte

protected int readByte()
                throws java.io.IOException
Returns the next unsigned byte. -1 is returned if all bytes have been read.

Returns:
next unsigned byte
Throws:
java.io.IOException - I/O exception
See Also:
InputStream.read()

readString

public final java.lang.String readString()
                                  throws java.io.IOException
Reads a string from the input stream, suffixed by a 0 byte.

Returns:
string
Throws:
java.io.IOException - I/O Exception

readBytes

public final byte[] readBytes()
                       throws java.io.IOException
Reads a byte array from the input stream, suffixed by a 0 byte.

Returns:
token
Throws:
java.io.IOException - I/O Exception

close

public final void close()
                 throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

size

public final int size()
Returns the number of read bytes.

Returns:
read bytes

length

public final long length()
Returns the input length (may be -1).

Returns:
input length

markSupported

public final boolean markSupported()
Overrides:
markSupported in class java.io.InputStream

mark

public void mark(int m)
Overrides:
mark in class java.io.InputStream

reset

public final void reset()
                 throws java.io.IOException
Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

content

public byte[] content()
               throws java.io.IOException
Retrieves and returns the whole data and closes the stream.

Returns:
contents
Throws:
java.io.IOException - I/O exception