System.IO
Class Stream

java.lang.Object
  extended by System.IO.Stream
All Implemented Interfaces:
IDisposable
Direct Known Subclasses:
MemoryStream

public abstract class Stream
extends java.lang.Object
implements IDisposable

Provides a generic view of a sequence of bytes.

Author:
Halofreak1990

Field Summary
static System.IO.NullStream Null
           
 
Constructor Summary
protected Stream()
          Initializes a new instance of the System.IO.Stream class.
 
Method Summary
 IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, java.lang.Object state)
          Begins an asynchronous read operation.
 IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, java.lang.Object state)
          Begins an asynchronous write operation.
abstract  boolean CanRead()
           
abstract  boolean CanSeek()
           
 boolean CanTimeout()
           
abstract  boolean CanWrite()
           
 void Close()
           
 void Dispose()
          Releases all resources used by the System.IO.Stream.
protected  void Dispose(boolean disposing)
          Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.
 int EndRead(IAsyncResult asyncResult)
          Waits for the pending asynchronous read to complete.
 void EndWrite(IAsyncResult asyncResult)
          Ends an asynchronous write operation.
abstract  void Flush()
          When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
abstract  long getPosition()
           
abstract  long Length()
           
abstract  int Read(byte[] buffer, int offset, int count)
          When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
 int ReadByte()
          Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
abstract  long Seek(long offset, SeekOrigin origin)
          When overridden in a derived class, sets the position within the current stream.
abstract  void SetLength(long value)
          When overridden in a derived class, sets the length of the current stream.
abstract  void setPosition(long value)
           
abstract  void Write(byte[] buffer, int offset, int count)
          When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
 void WriteByte(byte value)
          Writes a byte to the current position in the stream and advances the position within the stream by one byte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Null

public static final System.IO.NullStream Null
Constructor Detail

Stream

protected Stream()
Initializes a new instance of the System.IO.Stream class.

Method Detail

CanRead

public abstract boolean CanRead()

CanSeek

public abstract boolean CanSeek()

CanTimeout

public boolean CanTimeout()

CanWrite

public abstract boolean CanWrite()

Length

public abstract long Length()

getPosition

public abstract long getPosition()

setPosition

public abstract void setPosition(long value)

BeginRead

public IAsyncResult BeginRead(byte[] buffer,
                              int offset,
                              int count,
                              AsyncCallback callback,
                              java.lang.Object state)
Begins an asynchronous read operation.

Parameters:
buffer -
offset -
count -
callback -
state -
Returns:

BeginWrite

public IAsyncResult BeginWrite(byte[] buffer,
                               int offset,
                               int count,
                               AsyncCallback callback,
                               java.lang.Object state)
Begins an asynchronous write operation.

Parameters:
buffer - The buffer to write data from.
offset - The byte offset in buffer from which to begin writing.
count - The maximum number of bytes to write.
callback - An optional asynchronous callback, to be called when the write is complete.
state - A user-provided object that distinguishes this particular asynchronous write request from other requests.
Returns:
An IAsyncResult that represents the asynchronous write, which could still be pending.
Throws:
IOException - Attempted an asynchronous write past the end of the stream, or a disk error occurs.
ArgumentException - One or more of the arguments is invalid.
ObjectDisposedException - Methods were called after the stream was closed.
NotSupportedException - The current Stream implementation does not support the write operation.

Close

public void Close()

Dispose

public void Dispose()
Releases all resources used by the System.IO.Stream.

Specified by:
Dispose in interface IDisposable

Dispose

protected void Dispose(boolean disposing)
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.

Parameters:
disposing - true to release both managed and unmanaged resources; false to release only unmanaged resources.

EndRead

public int EndRead(IAsyncResult asyncResult)
Waits for the pending asynchronous read to complete.

Parameters:
asyncResult - The reference to the pending asynchronous request to finish.
Returns:
The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.

EndWrite

public void EndWrite(IAsyncResult asyncResult)
Ends an asynchronous write operation.

Parameters:
asyncResult - The reference to the pending asynchronous request to finish.
Throws:
ArgumentNullException - asyncResult is null.
ArgumentException - asyncResult did not originate from a System.IO.Stream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object) method on the current stream.
IOException - The stream is closed or an internal error has occurred.

Flush

public abstract void Flush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Throws:
IOException - An I/O error occurs.

Read

public abstract int Read(byte[] buffer,
                         int offset,
                         int count)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters:
buffer - An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offset - The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count - The maximum number of bytes to be read from the current stream.
Returns:
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
Throws:
ArgumentException - The sum of offset and count is larger than the buffer length.
ArgumentNullException - buffer is null.
ArgumentOutOfRangeException - offset or count is negative.
IOException - An I/O error occurs.
NotSupportedException - The stream does not support reading.
ObjectDisposedException - Methods were called after the stream was closed.

ReadByte

public int ReadByte()
Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

Returns:
The unsigned byte cast to an Int32, or -1 if at the end of the stream.
Throws:
NotSupportedException - The stream does not support reading.
ObjectDisposedException - Methods were called after the stream was closed.

Seek

public abstract long Seek(long offset,
                          SeekOrigin origin)
When overridden in a derived class, sets the position within the current stream.

Parameters:
offset - A byte offset relative to the origin parameter.
origin - A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.
Returns:
The new position within the current stream.
Throws:
IOException - An I/O error occurs.
NotSupportedException - The stream does not support seeking, such as if the stream is constructed from a pipe or console output.
ObjectDisposedException - Methods were called after the stream was closed.

SetLength

public abstract void SetLength(long value)
When overridden in a derived class, sets the length of the current stream.

Parameters:
value - The desired length of the current stream in bytes.
Throws:
IOException - An I/O error occurs.
NotSupportedException - The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.
ObjectDisposedException - Methods were called after the stream was closed.

Write

public abstract void Write(byte[] buffer,
                           int offset,
                           int count)
When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Parameters:
buffer - An array of bytes. This method copies count bytes from buffer to the current stream.
offset - The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count - The number of bytes to be written to the current stream.

WriteByte

public void WriteByte(byte value)
Writes a byte to the current position in the stream and advances the position within the stream by one byte.

Parameters:
value - The byte to write to the stream.
Throws:
IOException - An I/O error occurs.
NotSupportedException - The stream does not support writing, or the stream is already closed.