edu.rit.m2mp
Class MessageInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by edu.rit.m2mp.MessageInputStream
All Implemented Interfaces:
Closeable

public class MessageInputStream
extends InputStream

Class MessageInputStream provides an input stream for reading the contents of an incoming Many-to-Many Protocol (M2MP) message. A message input stream is not constructed directly. Rather, it is obtained by calling the acceptIncomingMessage() method in class M2MP.


Method Summary
 int available()
          Determine the number of bytes available from this message input stream.
 void close()
          Close this message input stream.
protected  void finalize()
          Finalize this message input stream.
 int read()
          Read the next byte from this message input stream.
 int read(byte[] buf)
          Read the given byte array from this message input stream.
 int read(byte[] buf, int off, int len)
          Read a portion of the given byte array from this message input stream.
 long skip(long len)
          Skip over and discard the given number of bytes from this message input stream.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

read

public int read()
         throws IOException
Read the next byte from this message input stream. The byte is returned as an int in the range 0 to 255. If the end of stream has been reached, -1 is returned. This method blocks until data is available, the end of stream is reached, or an exception is thrown.

Specified by:
read in class InputStream
Returns:
Byte, or -1 if the end of stream has been reached.
Throws:
IOException - Thrown if an I/O error occurred.

read

public int read(byte[] buf)
         throws IOException
Read the given byte array from this message input stream. Bytes are stored in buf starting at index 0. At most buf.length bytes are read. The number of bytes actually read is returned; this may be less than buf.length. If no bytes were read because the end of stream has been reached, -1 is returned. This method blocks until data is available, the end of stream is reached, or an exception is thrown.

Overrides:
read in class InputStream
Parameters:
buf - Byte array.
Returns:
The number of bytes actually read, or -1 if the end of stream has been reached.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IOException - Thrown if an I/O error occurred.

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Read a portion of the given byte array from this message input stream. Bytes are stored in buf starting at index off. At most len bytes are read. The number of bytes actually read is returned; this may be less than len. If no bytes were read because the end of stream has been reached, -1 is returned. This method blocks until data is available, the end of stream is reached, or an exception is thrown.

Overrides:
read in class InputStream
Parameters:
buf - Byte array.
off - Index of first byte to read.
len - Maximum number of bytes to read.
Returns:
The number of bytes actually read, or -1 if the end of stream has been reached.
Throws:
NullPointerException - (unchecked exception) Thrown if buf is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if off < 0, len < 0, or off+len > the length of buf.
IOException - Thrown if an I/O error occurred.

skip

public long skip(long len)
          throws IOException
Skip over and discard the given number of bytes from this message input stream. At most len bytes are skipped. The number of bytes actually skipped is returned; this may be less than len. If no bytes were skipped because the end of stream has been reached, 0 is returned. This method blocks until data is available, the end of stream is reached, or an exception is thrown.

Overrides:
skip in class InputStream
Parameters:
len - Maximum number of bytes to skip.
Returns:
The number of bytes actually skipped, or 0 if the end of stream has been reached.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if len < 0.
IOException - Thrown if an I/O error occurred.

available

public int available()
              throws IOException
Determine the number of bytes available from this message input stream.

Overrides:
available in class InputStream
Returns:
The number of bytes that can be read or skipped without blocking.
Throws:
IOException - Thrown if an I/O error occurred.

close

public void close()
Close this message input stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream

finalize

protected void finalize()
Finalize this message input stream.

Overrides:
finalize in class Object


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.