org.metastatic.rsync.v2
Class MultiplexedInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--org.metastatic.rsync.v2.MultiplexedInputStream
All Implemented Interfaces:
MultiplexedIO

public class MultiplexedInputStream
extends InputStream
implements MultiplexedIO

Handle multiplexed I/O for the rsync protocol.


Field Summary
protected  InputStream in
          The underlying input stream.
protected  boolean multiplex
          Whether or not to actually multiplex.
protected  int remaining
          Used in readUnbuffered.
protected  Statistics stats
           
 
Fields inherited from interface org.metastatic.rsync.v2.MultiplexedIO
FERROR, FINFO, FLOG, FNONE, MPLEX_BASE
 
Constructor Summary
MultiplexedInputStream(InputStream in, boolean multiplex)
           
 
Method Summary
 Statistics getStats()
           
 int read()
           
 int read(byte[] buf)
          Attempt to read as many bytes as will fit into the buffer, blocking until it has been filled.
 int read(byte[] buf, int off, int len)
          Attempt to fully read len bytes, blocking until all data is read.
 int readInt()
          Read a little-endian ordered 32-bit integer.
 long readLong()
          Read a little-endian ordered 64-bit long integer.
 String readString(int len)
          Read len bytes, returning them as a String interpreted as US-ASCII.
protected  int readUnbuffered(byte[] buf, int off, int len)
          Do an unbuffered read from the multiplexed input stream, putting normal data into the byte buffer and sending error stream data to #err.
 void setMultiplex(boolean multiplex)
           
 void setStats(Statistics stats)
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected InputStream in
The underlying input stream.


multiplex

protected boolean multiplex
Whether or not to actually multiplex.


remaining

protected int remaining
Used in readUnbuffered.


stats

protected Statistics stats
Constructor Detail

MultiplexedInputStream

public MultiplexedInputStream(InputStream in,
                              boolean multiplex)
Method Detail

setStats

public void setStats(Statistics stats)

getStats

public Statistics getStats()

setMultiplex

public void setMultiplex(boolean multiplex)

read

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

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Attempt to fully read len bytes, blocking until all data is read.

Overrides:
read in class InputStream
Parameters:
buf - The buffer to read into.
off - From whence to start storage in buf.
len - The number of bytes to read.
IOException

read

public int read(byte[] buf)
         throws IOException
Attempt to read as many bytes as will fit into the buffer, blocking until it has been filled.

Overrides:
read in class InputStream
Parameters:
buf - The buffer to read into.
IOException

readString

public String readString(int len)
                  throws IOException
Read len bytes, returning them as a String interpreted as US-ASCII.

Parameters:
len - The number of bytes to read.
Returns:
An ASCII string of the bytes read.
IOException

readInt

public int readInt()
            throws IOException
Read a little-endian ordered 32-bit integer.

Returns:
The integer read.
IOException

readLong

public long readLong()
              throws IOException
Read a little-endian ordered 64-bit long integer.

Returns:
The long integer read.
IOException

readUnbuffered

protected int readUnbuffered(byte[] buf,
                             int off,
                             int len)
                      throws IOException
Do an unbuffered read from the multiplexed input stream, putting normal data into the byte buffer and sending error stream data to #err.

Parameters:
buf - The byte buffer to read into.
off - From whence in the buffer to begin.
len - The number of bytes to attempt to read.
Returns:
The number of bytes read.
IOException