com.devexperts.io
Class StreamInput

java.lang.Object
  extended by java.io.InputStream
      extended by com.devexperts.io.BufferedInput
          extended by com.devexperts.io.StreamInput
All Implemented Interfaces:
Closeable, DataInput, ObjectInput

public class StreamInput
extends BufferedInput

An implementation of BufferedInput that reads all data from source InputStream.


Field Summary
protected  InputStream in
           
 
Fields inherited from class com.devexperts.io.BufferedInput
buffer, EMPTY_BYTE_ARRAY, limit, markLimit, markPosition, position, totalPositionBase
 
Constructor Summary
StreamInput()
          Creates a new stream input with default buffer capacity.
StreamInput(InputStream in)
          Creates a new stream input with specified source input stream and default buffer capacity.
StreamInput(InputStream in, int size)
          Creates a new stream input with specified source input stream and buffer capacity.
StreamInput(int size)
          Creates a new stream input with specified buffer capacity.
 
Method Summary
 int available()
           
 void close()
           
 int read(byte[] b, int off, int len)
           
protected  int readData()
          This method is invoked when input methods need more bytes to read data.
 void resetInput()
          Resets this stream input by releasing source input stream and resetting position.
 void rewind(long n)
          Rewinds specified number of bytes.
 void setInput(InputStream in)
          Sets new source input stream.
 long skip(long n)
           
 
Methods inherited from class com.devexperts.io.BufferedInput
checkEOB, checkRewind, mark, mark, markSupported, needData, read, read, readBoolean, readByte, readByteArray, readChar, readCompactInt, readCompactLong, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readObject, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTFChar, readUTFString, reset, seek, skipBytes, throwEOFException, totalPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected InputStream in
Constructor Detail

StreamInput

public StreamInput()
Creates a new stream input with default buffer capacity.


StreamInput

public StreamInput(int size)
Creates a new stream input with specified buffer capacity.

Parameters:
size - the initial buffer size
Throws:
IllegalArgumentException - if size is not positive

StreamInput

public StreamInput(InputStream in)
Creates a new stream input with specified source input stream and default buffer capacity.

Parameters:
in - the source to read from

StreamInput

public StreamInput(InputStream in,
                   int size)
Creates a new stream input with specified source input stream and buffer capacity.

Parameters:
in - the source to read from
size - the initial buffer size
Throws:
IllegalArgumentException - if size is not positive
Method Detail

setInput

public void setInput(InputStream in)
Sets new source input stream. Accepts null to release source.

Parameters:
in - the source to read from

resetInput

public void resetInput()
Resets this stream input by releasing source input stream and resetting position.


close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in interface ObjectInput
Overrides:
close in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Specified by:
available in interface ObjectInput
Overrides:
available in class BufferedInput
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Specified by:
read in interface ObjectInput
Overrides:
read in class BufferedInput
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Specified by:
skip in interface ObjectInput
Overrides:
skip in class BufferedInput
Throws:
IOException

rewind

public void rewind(long n)
Description copied from class: BufferedInput
Rewinds specified number of bytes. The input cannot be rewound past the marked position.

Specified by:
rewind in class BufferedInput
Parameters:
n - the number of bytes to rewind

readData

protected int readData()
                throws IOException
Description copied from class: BufferedInput
This method is invoked when input methods need more bytes to read data. This method shall make an attempt to read some bytes into the buffer. This method returns number of bytes actually read or value -1 if no bytes can be read because the end of the stream has been reached. This method may block if needed. This method is allowed to update buffer, position, limit and totalPositionBase fields as needed.

This method shall never throw an EOFException.

Specified by:
readData in class BufferedInput
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
Throws:
IOException - if an I/O error occurs


Copyright © 2013 Devexperts. All Rights Reserved.