wt.wrmf.transport
Class RewindableInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended bywt.wrmf.transport.RewindableInputStream
All Implemented Interfaces:
Serializable

public class RewindableInputStream
extends InputStream
implements Serializable

This class provides another choice (compared to ChunkInputStream) to keep (limited) memory of the bytes it has read. By calling rewindFrom (position), the input stream will be "rewinded" so that the next byte read will be starting from "position".

Supported API: false

Extendable: false

See Also:
Serialized Form

Field Summary
private  long bytesRead
           
private  int bytesRewinded
           
private  int capacity
           
private static String CLASSNAME
           
private  InputStream is
           
private static String RESOURCE
           
private  byte[] rewindableData
           
private  byte[] tempData
           
private  int tempIndex
           
private static String versionID
           
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
RewindableInputStream(InputStream is)
          

Supported API: false
RewindableInputStream(InputStream is, int memorySize)
          

Supported API: false
 
Method Summary
 void close()
           
 long getBytesRead()
          Get number of bytes being read.
private  void initialize()
           
 int read()
          

Supported API: false
 int read(byte[] buf)
          

Supported API: false
 int read(byte[] buf, int off, int len)
          

Supported API: false
private  int read0(byte[] buf, int off, int len)
           
 void rewind()
          Try to rewind fully.
 void rewindFrom(long position)
          Try to rewind the InputStream starting at the position as specified, as if (position -1) bytes have been successfully read only.
private  void saveData()
           
 long skip(long n)
          Skip exactly n bytes.
private  void tempDataReset()
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

is

private InputStream is

bytesRead

private long bytesRead

capacity

private int capacity

rewindableData

private byte[] rewindableData

versionID

private static final String versionID
See Also:
Constant Field Values

tempData

private byte[] tempData

tempIndex

private int tempIndex

bytesRewinded

private int bytesRewinded
Constructor Detail

RewindableInputStream

public RewindableInputStream(InputStream is,
                             int memorySize)


Supported API: false

Parameters:
is -
memorySize -

RewindableInputStream

public RewindableInputStream(InputStream is)


Supported API: false

Parameters:
is -
Method Detail

read

public int read()
         throws IOException


Supported API: false

Returns:
int
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException


Supported API: false

Parameters:
buf -
off -
len -
Returns:
int
Throws:
IOException

read

public int read(byte[] buf)
         throws IOException


Supported API: false

Parameters:
buf -
Returns:
int
Throws:
IOException

getBytesRead

public long getBytesRead()
Get number of bytes being read. The returned value is different before and after calling the rewind method. Do not count -1.

Supported API: false

Returns:
long

rewindFrom

public void rewindFrom(long position)
                throws IOException
Try to rewind the InputStream starting at the position as specified, as if (position -1) bytes have been successfully read only. IOException will be thrown if unable to rewind to the position due to limited memory.

Supported API: false

Parameters:
position -
Throws:
IOException

rewind

public void rewind()
            throws IOException
Try to rewind fully. All data in memory will be converted to input stream.

Supported API: false

Throws:
IOException

skip

public long skip(long n)
          throws IOException
Skip exactly n bytes. This may overwrite the skip() method implemented for the input stream as in the constructor.

Supported API: false

Parameters:
n -
Returns:
long
Throws:
IOException

initialize

private void initialize()

saveData

private void saveData()

tempDataReset

private void tempDataReset()

read0

private int read0(byte[] buf,
                  int off,
                  int len)
           throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException