Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.net
Class ZInputStream  view ZInputStream download ZInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.ByteArrayInputStream
          extended byjava.net.ZInputStream

public class ZInputStream
extends java.io.ByteArrayInputStream

This class implements a growing ByteArrayInputStream. Normally a ByteArrayInputStream is initialized and cannot change its internal byte array. This class provides a method to add byte arrays to the internal buffer thus enlarging it dynamically. Moreover, this class provides an efficient garbage collector that shrink the internal byte array as data gets read, preventing memory trashing!

Version:
1.0

Field Summary
 
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
 
Constructor Summary
ZInputStream()
          This empty constructor builds an object with a preallocated buffer.
ZInputStream(byte[] b)
          This constructor builds an object that initially contains the byte array passed as argument.
ZInputStream(byte[] b, int off, int len)
          This constructor builds an object that initially contains the byte array passed as argument, starting from an offset and going for a limited extent, as specified by the second and third argument.
 
Method Summary
 void addBytes(byte[] b)
          This method adds a byte array to the internal buffer thus enlarging it.
 void dump()
          Internal use only.
protected  void gc()
          This little garbage collector, if invoked, moves the internal buffer towards the start, if some read but unfreed data exists, even if the read and unread region overlaps.
 int read()
          This method reads a single int from the uderlying input stream.
 int read(byte[] b, int off, int len)
          This method reads an array of bytes storing into a specified byte array, starting from an offset and going for a specified number of bytes.
 void reset()
          This method resets the underlying input stream.
 
Methods inherited from class java.io.ByteArrayInputStream
available, mark, markSupported, skip
 
Methods inherited from class java.io.InputStream
close, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZInputStream

public ZInputStream()
This empty constructor builds an object with a preallocated buffer.


ZInputStream

public ZInputStream(byte[] b)
This constructor builds an object that initially contains the byte array passed as argument.


ZInputStream

public ZInputStream(byte[] b,
                    int off,
                    int len)
This constructor builds an object that initially contains the byte array passed as argument, starting from an offset and going for a limited extent, as specified by the second and third argument.

Method Detail

addBytes

public void addBytes(byte[] b)
This method adds a byte array to the internal buffer thus enlarging it. The singularity is that it uses an internal garbage collector to ensure that the buffer size is always the minimum to contain the unread data but never contains read data that occupies memory with old useless data!


read

public int read()
This method reads a single int from the uderlying input stream. The "waiting for available data" situation has been realized using an uncommon waiting loop:
while () Thread.yield();
that's far more efficient than the usual one:
while () ;


read

public int read(byte[] b,
                int off,
                int len)
This method reads an array of bytes storing into a specified byte array, starting from an offset and going for a specified number of bytes. The "waiting for available data" situation has been realized using an uncommon waiting loop:
while () Thread.yield();
that's far more efficient than the usual one:
while () ;


reset

public void reset()
This method resets the underlying input stream.


gc

protected void gc()
This little garbage collector, if invoked, moves the internal buffer towards the start, if some read but unfreed data exists, even if the read and unread region overlaps. And it's composed of only three instructions!


dump

public void dump()
Internal use only.