com.voytechs.jnetstream.io
Class StackInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.voytechs.jnetstream.io.StackInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
BitStackInputStream

public class StackInputStream
extends java.io.InputStream


Field Summary
protected  byte[] buf
          This is where we cache data read from the stream after the first push() method has been called.
protected  int count
          Keep track of current positions and sizes in our buffer.
protected  java.util.Stack markers
           
protected  int offset
           
protected  java.util.Stack positions
          A stack which contains the pushed byte arrays.
 
Constructor Summary
StackInputStream(java.io.InputStream inputStream)
           
StackInputStream(java.io.InputStream inputStream, int bufSize)
           
 
Method Summary
 void clear()
          Clears the last entry on the stack without rewinding to the position on the entry being cleared.
static java.lang.String hex(int b)
           
static void main(java.lang.String[] args)
          Test function for StackInputStream
 long position()
          Returns the exact offset within the over-all stream starting at 0.
static void printStream(java.io.InputStream in, int count)
           
 int read()
          read next byte from our source inputStream.
 void reset()
          Resets the current stack buffer to initial states.
 long skip(long n)
          Skips N bytes of data in the stream and advances the position.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

positions

protected java.util.Stack positions
A stack which contains the pushed byte arrays. within the stream.


markers

protected java.util.Stack markers

count

protected int count
Keep track of current positions and sizes in our buffer.


offset

protected int offset

buf

protected byte[] buf
This is where we cache data read from the stream after the first push() method has been called. Data has to be rewound to a given position after a pop() operation.

Constructor Detail

StackInputStream

public StackInputStream(java.io.InputStream inputStream)
Parameters:
inputStream -

StackInputStream

public StackInputStream(java.io.InputStream inputStream,
                        int bufSize)
Method Detail

skip

public long skip(long n)
          throws java.io.IOException
Skips N bytes of data in the stream and advances the position. Because this stream object does buffering of stream data and if the position within the stream was rewound previously by using the pop() method the data skipped may or may not be actually skipped in the underlying input stream. This may have the effect that read()/skip() calls may not be actually called in the uderlying stream.

Overrides:
skip in class java.io.InputStream
Parameters:
n - Number of bytes to skip from this stream.
Throws:
java.io.IOException

clear

public void clear()
           throws java.io.IOException
Clears the last entry on the stack without rewinding to the position on the entry being cleared.

Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
read next byte from our source inputStream.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException - any IO condition reported by source input stream.

reset

public void reset()
Resets the current stack buffer to initial states. Any pushed positions are cleared and offset and count are reset. The existing "buf" is not dealocated and reused for future stack usage.

Overrides:
reset in class java.io.InputStream

position

public long position()
Returns the exact offset within the over-all stream starting at 0. After a pop() method is called and the stream is rewound, the position() is updated appropriately. Thus second call to position() may return position index that is lower then the index return by the first position() call if a pop() was called in between.

Returns:
Exact position within the stream. Position starts at 0 and increases. Since a signed long is used for return values, a really long stream could could theoretically wrap.

main

public static void main(java.lang.String[] args)
Test function for StackInputStream

Parameters:
args - command line arguments

printStream

public static void printStream(java.io.InputStream in,
                               int count)
                        throws java.io.IOException
Throws:
java.io.IOException

hex

public static java.lang.String hex(int b)