public abstract class Stream extends java.lang.Object implements IDisposable
Modifier and Type | Field and Description |
---|---|
static System.IO.NullStream |
Null
A Stream with no backing store.
|
Modifier | Constructor and Description |
---|---|
protected |
Stream()
Initializes a new instance of the System.IO.Stream class.
|
Modifier and Type | Method and Description |
---|---|
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()
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
|
abstract boolean |
CanSeek()
When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
|
boolean |
CanTimeout()
Gets a value that determines whether the current stream can time out.
|
abstract boolean |
CanWrite()
When overridden in a derived class, gets a value indicating whether the current stream supports writing.
|
void |
Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream.
|
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()
When overridden in a derived class, gets the position within the current stream.
|
abstract long |
Length()
When overridden in a derived class, gets the length in bytes of the stream.
|
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)
When overridden in a derived class, sets the position within the current stream.
|
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.
|
protected Stream()
public abstract boolean CanRead()
public abstract boolean CanSeek()
public boolean CanTimeout()
public abstract boolean CanWrite()
public abstract long Length()
NotSupportedException
- A class derived from Stream does not support seeking.ObjectDisposedException
- Methods were called after the stream was closed.public abstract long getPosition()
public abstract void setPosition(long value)
value
- The new position within the stream.public IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, java.lang.Object state)
buffer
- The buffer to read the data into.offset
- The byte offset in buffer at which to begin writing data read from the stream.count
- The maximum number of bytes to read.callback
- An optional asynchronous callback, to be called when the read is complete.state
- A user-provided object that distinguishes this particular asynchronous read request from other requests.IOException
- Attempted an asynchronous read 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 read operation.public IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, java.lang.Object state)
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.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.public void Close()
public void Dispose()
Dispose
in interface IDisposable
protected void Dispose(boolean disposing)
disposing
- true to release both managed and unmanaged resources; false to release only unmanaged resources.public int EndRead(IAsyncResult asyncResult)
asyncResult
- The reference to the pending asynchronous request to finish.public void EndWrite(IAsyncResult asyncResult)
asyncResult
- The reference to the pending asynchronous request to finish.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.public abstract void Flush()
IOException
- An I/O error occurs.public abstract int Read(byte[] buffer, int offset, int count)
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.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.public int ReadByte()
NotSupportedException
- The stream does not support reading.ObjectDisposedException
- Methods were called after the stream was closed.public abstract long Seek(long offset, SeekOrigin origin)
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.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.public abstract void SetLength(long value)
value
- The desired length of the current stream in bytes.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.public abstract void Write(byte[] buffer, int offset, int count)
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.public void WriteByte(byte value)
value
- The byte to write to the stream.IOException
- An I/O error occurs.NotSupportedException
- The stream does not support writing, or the stream is already closed.