com.novell.java.io
Class NInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--com.novell.java.io.NInputStream

public class NInputStream
extends java.io.InputStream

Provides input stream functionality to various data device object, which implements the DataAccessable interface.

The various constructors open an input stream on (or with) the DataAccessable object passed into the constructors. The DataAccessable object might have container capabilities and support subordinate streams, or it may support only a stream to itself. The constructors with a name parameter (which must be atomic) will attempt to open a subordinate stream through the given DataAccessable object. The constructors without a name parameter attempt to open a stream on the given DataAcessable object.

A set of constructors is provided for the support of provider based custom parameters. A given implementation of a DataAccessable object might require custom parameters to open the stream. For example, a file system provider might require open flags, fork selectors, name space information, size, and so forth, to open the stream. The custom Object parameter allows for passing known provider-supplied objects to their DataAccessable implementations, allowing the user full control over the opening of the stream if needed. The various providers must implement reasonable defaults for any custom parameters if the non-custom constructors are used (open flags == READ). See Novell's DataAccessableParameters and NFileInputStream for an example of how a provider might implement this support.

A NoSubordinateAccessException will be thrown if the given DataAccessable object does not support subordinate streams (subordinate constructors). A SubordinateAccessOnlyException will be thrown if the given DataAccessable object does not support a stream on itself.

See Also:
DataAccessable, NOutputStream, RandomAccess, NFileInputStream, DataAccessableParameters

Constructor Summary
NInputStream(DataAccessable accessor)
          Creates an instance of the NInputStream.
NInputStream(DataAccessable accessor, java.lang.Object custom)
          Creates an instance of NInputStream with the custom parameter.
NInputStream(java.lang.String name, DataAccessable accessor)
          Creates a subordinate instance of NInputStream.
NInputStream(java.lang.String name, DataAccessable accessor, java.lang.Object custom)
          Creates a subordinate instance of NInputStream with the custom parameter.
 
Method Summary
 int available()
          Returns bytes that are available to read without blocking.
 void close()
          Closes the stream.
 void mark(int readLimit)
          Saves the current position, which can then be restored by calling reset().
 boolean markSupported()
          Determines whether the mark() and reset() methods are valid for the stream.
 int read()
          Reads a byte.
 int read(byte[] b)
          Reads an array of bytes.
 int read(byte[] b, int off, int len)
          Reads the specified number of bytes into an array.
 void reset()
          Resets the stream position to the last position saved by calling mark().
 long skip(long n)
          Skips the specified number of bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NInputStream

public NInputStream(DataAccessable accessor)
             throws java.io.IOException
Creates an instance of the NInputStream.

Opens an input stream to the DataAccessable accessor parameter.

Parameters:
accessor - The DataAccessable object to use.
Throws:
java.io.IOException - If the stream cannot be opened.
SubordinateAccessOnlyException - If the accessor does not support a stream to itself, for example, a directory.
InputStreamNotSupportedException - If the accessor does not support an input stream.

NInputStream

public NInputStream(DataAccessable accessor,
                    java.lang.Object custom)
             throws java.io.IOException
Creates an instance of NInputStream with the custom parameter.

Opens an input stream to the DataAccessable accessor parameter, passing the provider-based custom parameter to the accessor for the open.

Parameters:
accessor - The DataAccessable object to use.
custom - Provider-specific custom object containing any needed parameters to open the stream.
Throws:
SubordinateAccessOnlyException - If the accessor does not support a stream to itself, for example, a directory.
InputStreamNotSupportedException - If the accessor does not support an input stream.
java.lang.IllegalArgumentException - If the custom object is not of the expected type for the given provider.

NInputStream

public NInputStream(java.lang.String name,
                    DataAccessable accessor)
             throws java.io.IOException
Creates a subordinate instance of NInputStream.

Opens a subordinate input stream to the DataAccessable accessor parameter.

Parameters:
name - The atomic subordinate stream name to open.
accessor - The DataAccessable object to use.
Throws:
java.io.IOException - If the stream cannot be opened.
NoSubordinateAccessException - If the accessor does not support opening a subordinate stream.
InputStreamNotSupportedException - If the accessor does not support an input stream.

NInputStream

public NInputStream(java.lang.String name,
                    DataAccessable accessor,
                    java.lang.Object custom)
             throws java.io.IOException
Creates a subordinate instance of NInputStream with the custom parameter.

Opens a subordinate input stream to the DataAccessable accessor parameter, passing the provider based custom parameter to the accessor for the open.

Parameters:
name - The atomic subordinate stream name to open.
accessor - The DataAccessable object to use.
custom - Provider-specific custom object containing any needed parameters to open the stream.
Throws:
java.io.IOException - If the stream cannot be opened.
NoSubordinateAccessException - If the accessor does not support opening a subordinate stream.
InputStreamNotSupportedException - If the accessor does not support an input stream.
java.lang.IllegalArgumentException - If the custom object is not of the expected type for the given provider.
Method Detail

available

public int available()
              throws java.io.IOException
Returns bytes that are available to read without blocking.
Returns:
Bytes that can be read without blocking.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
available in class java.io.InputStream

close

public void close()
           throws java.io.IOException
Closes the stream.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
close in class java.io.InputStream

mark

public void mark(int readLimit)
Saves the current position, which can then be restored by calling reset().

If markSupported() returns FALSE, mark() does nothing.

Parameters:
readLimit - The limit to number of bytes that can be read before the mark becomes invalid.
Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Determines whether the mark() and reset() methods are valid for the stream.
Returns:
A boolean set to TRUE if mark() and reset() are valid for this stream, otherwise FALSE is returned.
Overrides:
markSupported in class java.io.InputStream

read

public int read()
         throws java.io.IOException
Reads a byte.
Returns:
The byte read. -1 is returned if there are no more bytes to read in the stream.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
read in class java.io.InputStream

read

public int read(byte[] b)
         throws java.io.IOException
Reads an array of bytes.
Parameters:
b - The array into which to read the bytes.
Returns:
The number of bytes read, or if there were no bytes available to read, -1 is returned. If 'b' is zero bytes long, 0 is returned.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
read in class java.io.InputStream

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads the specified number of bytes into an array.
Parameters:
b - The array into which to read the bytes.
off - The offset in 'b' at which to start storing the bytes read.
len - The number of bytes to read. At most, this number of bytes will be read, but it could be less.
Returns:
The number of bytes read, or -1/ is returned if there were no bytes available to read. If 'len' is zero, 0 is returned.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
read in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
Resets the stream position to the last position saved by calling mark().
Throws:
java.io.IOException - If mark() and reset() are not supported or when an I/O error occurs.
Overrides:
reset in class java.io.InputStream

skip

public long skip(long n)
          throws java.io.IOException
Skips the specified number of bytes.
Parameters:
n - The number of bytes to skip.
Returns:
The number of bytes skipped or -1 if already at the end of the stream.
Throws:
java.io.IOException - When an I/O error occurs.
Overrides:
skip in class java.io.InputStream