edu.emory.mathcs.util.io
Class FragmentInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byedu.emory.mathcs.util.io.FragmentInputStream

public class FragmentInputStream
extends java.io.FilterInputStream

Virtual input stream that reads up to the specified number of bytes from the underlying stream and then reports EOF. Application: handle sequence of streams over a single physical "keepalive-type" stream.

Version:
1.0
Author:
Dawid Kurzyniec

Field Summary
static int ADVANCE_ON_CLOSE
          Closing policy that leaves the underlying stream opened but advances it to the end of this virtual stream.
static int CLOSE_ON_CLOSE
          Closing policy that closes the the underlying stream.
static int STAY_ON_CLOSE
          Closing policy that leaves the underlying stream opened at the current position.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
FragmentInputStream(java.io.InputStream in, long len)
          Creates new fragment input stream over a specified physical stream and with specified fragment length and STAY_ON_CLOSE closing policy.
FragmentInputStream(java.io.InputStream in, long len, int closingPolicy)
          Creates new fragment input stream over a specified physical stream and with specified fragment length and specified closing policy.
 
Method Summary
 int available()
           
 void close()
           
 void mark(int readlimit)
           
 int read()
           
 int read(byte[] buf, int off, int len)
           
 void reset(int readlimit)
           
 long skip(long n)
           
 
Methods inherited from class java.io.FilterInputStream
markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STAY_ON_CLOSE

public static final int STAY_ON_CLOSE
Closing policy that leaves the underlying stream opened at the current position.

See Also:
Constant Field Values

CLOSE_ON_CLOSE

public static final int CLOSE_ON_CLOSE
Closing policy that closes the the underlying stream.

See Also:
Constant Field Values

ADVANCE_ON_CLOSE

public static final int ADVANCE_ON_CLOSE
Closing policy that leaves the underlying stream opened but advances it to the end of this virtual stream. If less bytes were read than the length of the stream as specified at the construction time, the remaining bytes are skipped. Close may block if the data is not yet available.

See Also:
Constant Field Values
Constructor Detail

FragmentInputStream

public FragmentInputStream(java.io.InputStream in,
                           long len)
Creates new fragment input stream over a specified physical stream and with specified fragment length and STAY_ON_CLOSE closing policy.

Parameters:
in - the underlying stream to read from
len - the total length of this fragment stream

FragmentInputStream

public FragmentInputStream(java.io.InputStream in,
                           long len,
                           int closingPolicy)
Creates new fragment input stream over a specified physical stream and with specified fragment length and specified closing policy.

Parameters:
in - the underlying stream to read from
len - the total length of this fragment stream
closingPolicy - policy that decides what to do when this stream is closed
Method Detail

read

public int read()
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Throws:
java.io.IOException

mark

public void mark(int readlimit)

reset

public void reset(int readlimit)
           throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException