ariba.util.io
Class StatsInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by ariba.util.io.StatsInputStream
All Implemented Interfaces:
java.io.Closeable

public class StatsInputStream
extends java.io.InputStream

StatsInputStream is an InputStream that keeps track of the number of bytes that have been read in. @see InputStream


Field Summary
 long count
          Number of bytes read.
 
Constructor Summary
StatsInputStream(java.io.InputStream base)
          Creates a StatsInputStream.
 
Method Summary
 int available()
          Returns the number of bytes that can be read without blocking.
 void close()
          Closes the input stream.
 void mark(int readlimit)
          Marks the current position in the input stream.
 boolean markSupported()
          Returns a boolean indicating whether or not this stream type supports mark/reset.
 int read()
          Reads a byte of data.
 int read(byte[] b)
          Reads into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads into an array of bytes.
 void reset()
          Repositions the stream to the last marked position.
 long skip(long n)
          Skips n bytes of input.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

public long count
Number of bytes read.

Constructor Detail

StatsInputStream

public StatsInputStream(java.io.InputStream base)
Creates a StatsInputStream.

Parameters:
base - the InputStream
Method Detail

read

public int read()
         throws java.io.IOException
Reads a byte of data.

Specified by:
read in class java.io.InputStream
Returns:
the byte read, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - If an I/O error has occurred.

read

public int read(byte[] b)
         throws java.io.IOException
Reads into an array of bytes. This method will block until some input is available.

Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
Throws:
java.io.IOException - If an I/O error has occurred.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads into an array of bytes. This method will block until some input is available.

Overrides:
read in class java.io.InputStream
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
Throws:
java.io.IOException - If an I/O error has occurred.

skip

public long skip(long n)
          throws java.io.IOException
Skips n bytes of input. We count skipped bytes as "read" in the count field.

Overrides:
skip in class java.io.InputStream
Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - If an I/O error has occurred.

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read without blocking.

Overrides:
available in class java.io.InputStream
Returns:
the number of available bytes.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the input stream. Must be called to release any resources associated with the stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - If an I/O error has occurred.

mark

public void mark(int readlimit)
Marks the current position in the input stream. A subsequent call to reset() will reposition the stream at the last marked position so that subsequent reads will re-read the same bytes. The stream promises to allow readlimit bytes to be read before the mark position gets invalidated.

Overrides:
mark in class java.io.InputStream
Parameters:
readlimit - the maximum limit of bytes allowed to be read before the mark position becomes invalid.

reset

public void reset()
           throws java.io.IOException
Repositions the stream to the last marked position. If the stream has not been marked, or if the mark has been invalidated, an IOException is thrown. Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parser, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails, which, if it happens within readlimit bytes, allows the outer code to reset the stream and try another parser.

Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException - If the stream has not been marked or if the mark has been invalidated.

markSupported

public boolean markSupported()
Returns a boolean indicating whether or not this stream type supports mark/reset.

Overrides:
markSupported in class java.io.InputStream
Returns:
true if this stream type supports mark/reset; false otherwise.


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.