com.monica.javacom.streams
Class MJCReaderIsAIS

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--com.monica.javacom.streams.MJCReaderIsAIS
All Implemented Interfaces:
MJCReader

public class MJCReaderIsAIS
extends java.io.InputStream
implements MJCReader

Class for enabling to read from the MJC layer hierarchy using the conventional InputStream methods. Objects of this class act as InputStreams, they read the data from their MJCReadable.


Constructor Summary
MJCReaderIsAIS()
          Default constructor.
 
Method Summary
 int available()
          Returns the number of bytes that are currently available for reading from the stream.
 void close()
          Closes the InputStream.
 void connectionClosedEvent(MJCReadable readable)
          Handles the asynchronous connectionClosedEvents from the MJCReadable.
 void errorEvent(java.lang.String errorDescription, MJCReadable readable)
          Handles the asynchronous errorEvents from the MJCReadable.
 MJCReadable getReadable()
          Queries the MJCReadable from which data will be read.
 java.lang.String getReaderName()
          Returns the MJC name of the MJCReader.
 java.lang.String getReaderVersion()
          Returns the MJC version of the MJCReader.
 void mark(int readlimit)
          MJCReaderIsAIS does not support mark/reset.
 boolean markSupported()
          MJCReaderIsAIS does not support mark/reset.
 int read()
          Reads 1 single byte from the stream.
 int read(byte[] b)
          Reads b.length bytes from the stream.
 int read(byte[] b, int off, int len)
          Reads len bytes from the stream.
 void readEvent(MJCReadable readable)
          Handles the asynchronous readEvents from the MJCReadable.
 void reset()
          MJCReaderIsAIS does not support mark/reset.
 void setReadable(MJCReadable readable)
          Sets the MJCReadable from which data ha to be read, this means which will send the readEvents.
 long skip(long n)
          Skips n bytes in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MJCReaderIsAIS

public MJCReaderIsAIS()
Default constructor.
Method Detail

getReaderName

public java.lang.String getReaderName()
Returns the MJC name of the MJCReader.
Specified by:
getReaderName in interface MJCReader
Returns:
String: the MJC name of the MJCReader

getReaderVersion

public java.lang.String getReaderVersion()
Returns the MJC version of the MJCReader.
Specified by:
getReaderVersion in interface MJCReader
Returns:
String: the MJC version of the MJCReader

readEvent

public void readEvent(MJCReadable readable)
Handles the asynchronous readEvents from the MJCReadable. Data read from the MJCReadable will be buffered and can then be read from the InputStream.
Specified by:
readEvent in interface MJCReader
Parameters:
MJCReadable - readable: the MJCReadable from which the readEvent came

connectionClosedEvent

public void connectionClosedEvent(MJCReadable readable)
Handles the asynchronous connectionClosedEvents from the MJCReadable. After this event if the buffer gets empty, nothing more can be read from the InputStream.
Specified by:
connectionClosedEvent in interface MJCReader
Parameters:
MJCReadable - readable: the MJCReadable from which the connectionClosedEvent came

errorEvent

public void errorEvent(java.lang.String errorDescription,
                       MJCReadable readable)
Handles the asynchronous errorEvents from the MJCReadable. After this event if the buffer gets empty, nothing more can be read from the InputStream.
Specified by:
errorEvent in interface MJCReader
Parameters:
String - errorDescription: the error message
MJCReadable - readable: the MJCReadable from which the connectionClosedEvent came

setReadable

public void setReadable(MJCReadable readable)
Sets the MJCReadable from which data ha to be read, this means which will send the readEvents.
Specified by:
setReadable in interface MJCReader
Parameters:
MJCReadable - readable: the MJCReadable from which data has to be read

getReadable

public MJCReadable getReadable()
Queries the MJCReadable from which data will be read.
Specified by:
getReadable in interface MJCReader
Returns:
MJCReadable: the MJCReadable from which data will be read

read

public int read()
         throws java.io.IOException
Reads 1 single byte from the stream. The read blocks till data is available. If the stream is closed, -1 will be returned, otherwise the byte read.
Overrides:
read in class java.io.InputStream
Returns:
int: -1 if stream end, otherwise the byte read
Throws:
IOException: - if the InputStream has been closed

read

public int read(byte[] b)
         throws java.io.IOException
Reads b.length bytes from the stream. The read blocks till data is available. If the stream is closed, -1 will be returned, otherwise the number of bytes read.
Overrides:
read in class java.io.InputStream
Parameters:
byte[] - b: the byte array into the data will be read
Returns:
int: -1 if stream end, otherwise the number of bytes read
Throws:
IOException: - if the InputStream has been closed

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads len bytes from the stream. The read blocks till data is available. If the stream is closed, -1 will be returned, otherwise the number of bytes read.
Overrides:
read in class java.io.InputStream
Parameters:
byte[] - b: the byte array into the data will be read
int - off: the beginning offset from which the bytes will be written into b (inclusive)
int - len: the number of bytes to be read
Returns:
int: -1 if stream end, otherwise the number of bytes read
Throws:
IOException: - if the InputStream has been closed
IndexOutOfBoundsException: - if (b.length<(off+len))

skip

public long skip(long n)
          throws java.io.IOException
Skips n bytes in the stream. Skipped data will be lost. For some reasons the stream may skip less bytes than n.
Overrides:
skip in class java.io.InputStream
Parameters:
long - n: number of bytes to be skipped
Returns:
long: number of bytes actually skipped
Throws:
IOException: - if the InputStream has been closed

available

public int available()
              throws java.io.IOException
Returns the number of bytes that are currently available for reading from the stream.
Overrides:
available in class java.io.InputStream
Returns:
int: the number of bytes available from the stream
Throws:
IOException: - if the InputStream has been closed

close

public void close()
           throws java.io.IOException
Closes the InputStream. After close(), no read, close and available methods can be called without IOException.
Overrides:
close in class java.io.InputStream
Throws:
IOException: - if the InputStream has been closed

mark

public void mark(int readlimit)
MJCReaderIsAIS does not support mark/reset. This method does actually nothing.
Overrides:
mark in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
MJCReaderIsAIS does not support mark/reset. This method will always throw an IOException.
Overrides:
reset in class java.io.InputStream
Throws:
IOException: - MJCReaderIsAIS does not support mark/reset

markSupported

public boolean markSupported()
MJCReaderIsAIS does not support mark/reset.
Overrides:
markSupported in class java.io.InputStream
Returns:
boolean: false