Oracle

com.compoze.util
Class MeteredInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.compoze.util.MeteredInputStream
All Implemented Interfaces:
java.io.Closeable

public class MeteredInputStream
extends java.io.FilterInputStream

This class provides a FilterInputStream that performs several testing/monitoring functions:

  1. Count the number of bytes that are read
  2. Calculate the total average bytes / sec
  3. Calculate the average read length
  4. Optionally allow throughput restrictions for testing purposes
  5. Optionally calculate a checksum of all data read


Nested Class Summary
static class MeteredInputStream.RandomInputStream
          A NullInputStream for testing purposes.
 
Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MeteredInputStream(java.io.InputStream in)
          Constructor.
MeteredInputStream(java.io.InputStream in, boolean bCalculateChecksum)
          Constructor.
MeteredInputStream(java.io.InputStream in, int iMaxBytesPerSecond, boolean bCalculateChecksum)
          Constructor.
 
Method Summary
 void close()
          Closes the InputStream.
 int getAverageWriteLength()
          Gets the average write length that has been issued.
 double getBytesPerSecond()
          Gets the number of bytes per second that have been read since the InputStream was instantiated.
 long getBytesRead()
          Gets the number of bytes that have been read so far.
 long getChecksum()
          Gets a checksum of all of the data that has been read.
static void main(java.lang.String[] args)
          Main.
 int read()
          Writes a single byte.
 int read(byte[] b)
          Reads a byte array.
 int read(byte[] b, int iOffset, int iLength)
          Reads a byte array.
 java.lang.String toString()
          Creates a string representation of the output stream.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MeteredInputStream

public MeteredInputStream(java.io.InputStream in)
Constructor.


MeteredInputStream

public MeteredInputStream(java.io.InputStream in,
                          boolean bCalculateChecksum)
Constructor.


MeteredInputStream

public MeteredInputStream(java.io.InputStream in,
                          int iMaxBytesPerSecond,
                          boolean bCalculateChecksum)
Constructor.

Method Detail

close

public void close()
           throws java.io.IOException
Closes the InputStream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Reads a byte array.

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int iOffset,
                int iLength)
         throws java.io.IOException
Reads a byte array.

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Writes a single byte.

Overrides:
read in class java.io.FilterInputStream
Throws:
java.io.IOException

getBytesRead

public long getBytesRead()
Gets the number of bytes that have been read so far.


getAverageWriteLength

public int getAverageWriteLength()
Gets the average write length that has been issued.


getBytesPerSecond

public double getBytesPerSecond()
Gets the number of bytes per second that have been read since the InputStream was instantiated.


getChecksum

public long getChecksum()
Gets a checksum of all of the data that has been read.


toString

public java.lang.String toString()
Creates a string representation of the output stream.

Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Main.


Oracle

Copyright ©1999-2008 Oracle All rights reserved.