com.gc.iotools.stream.is
Class SizeReaderInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.gc.iotools.stream.is.SizeReaderInputStream
All Implemented Interfaces:
Closeable

public class SizeReaderInputStream
extends InputStream

Counts the bytes of the InputStream passed in the constructor. It can be used to determine the size of a document passed as a stream. This is possible only after the stream has been fully processed (by other parts of the application).

Usage:

 SizeReaderInputStream srIstream = new SizeReaderInputStream(originalStream);
 //performs all the application operation on stream
 performTasksOnStream(srIstream);
 srIstream.close();
 long size = srIstream.getSize();
 

Since:
1.0.6
Author:
dvd.smnt

Constructor Summary
SizeReaderInputStream(InputStream istream)
           
SizeReaderInputStream(InputStream istream, boolean fullReadOnClose)
          Constructs an SizeReaderInputStream and allow to specify actions to do on close.
 
Method Summary
 int available()
           
 void close()
          Closes the inner stream.
 long getSize()
          Returns the bytes read until now or total length of the stream if the close method has been called or EOF was reached.
 boolean isFullReadOnClose()
           
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SizeReaderInputStream

public SizeReaderInputStream(InputStream istream)

SizeReaderInputStream

public SizeReaderInputStream(InputStream istream,
                             boolean fullReadOnClose)
Constructs an SizeReaderInputStream and allow to specify actions to do on close.

Parameters:
istream - Stream whose bytes must be counted.
fullReadOnClose - if true after the close the inner stream is read completely and the effective size of the inner stream is calculated.
Method Detail

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Closes the inner stream. If fullReadOnClose was set in the constructor it also count all the bytes of the underlying stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occurs reading the whole content of the stream.
See Also:
InputStream.close()

getSize

public long getSize()
Returns the bytes read until now or total length of the stream if the close method has been called or EOF was reached.

Returns:
bytes read until now or the total length of the stream if close() was called.

isFullReadOnClose

public boolean isFullReadOnClose()

mark

public void mark(int readlimit)
Overrides:
mark in class InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException


Copyright © 2008-2009. All Rights Reserved.