com.aspose.imaging
Class StreamContainer

java.lang.Object
  extended by com.aspose.imaging.DisposableObject
      extended by com.aspose.imaging.StreamContainer
Direct Known Subclasses:
FileStreamContainer

public class StreamContainer
extends DisposableObject

Represents stream container which contains the stream and provides stream processing routines.


Constructor Summary
StreamContainer(java.io.InputStream stream)
           Initializes a new instance of the StreamContainer class.
StreamContainer(java.io.InputStream stream, boolean disposeStream)
           Initializes a new instance of the StreamContainer class.
 
Method Summary
protected  void afterStreamDisposed()
           Called after the stream is disposed.
protected  void beforeStreamDisposed()
           Called before the stream is disposed.
 boolean canRead()
           Gets a value indicating whether stream supports reading.
 boolean canSeek()
           Gets a value indicating whether stream supports seeking.
 boolean canWrite()
           Gets a value indicating whether stream supports writing.
 void flush()
           Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 long getLength()
           Gets the stream length in bytes.
 long getPosition()
           Gets the current position within the stream.
 java.io.InputStream getStream()
           
 boolean isStreamDisposedOnClose()
           Gets a value indicating whether this stream is disposed on close.
 int read(byte[] bytes)
           Reads bytes to fill the specified bytes buffer.
 int read(byte[] buffer, int offset, int count)
           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.
protected  void releaseManagedResources()
           Releases the managed resources.
 void save(java.io.InputStream destinationStream)
           
 void save(java.io.InputStream destinationStream, int bufferSize)
           
 void save(java.io.InputStream destinationStream, int bufferSize, long length)
           
 void save(java.lang.String filePath)
           Saves (copies) the stream's data to the specified stream.
 void save(java.lang.String filePath, int bufferSize)
           Saves (copies) the stream's data to the specified stream.
 void save(java.lang.String filePath, int bufferSize, long length)
           Saves (copies) the stream's data to the specified stream.
 long seek(long offset, int origin)
           Sets the position within the current stream.
 void seekBegin()
           Sets the stream position to the beginning of the stream.
 void setLength(long value)
           Sets the stream length in bytes.
 void setPosition(long value)
           Sets the current position within the stream.
 void shift(long shift)
           Shifts the data from the current stream position.
 byte[] toBytes()
           Converts the stream data to the byte array.
 byte[] toBytes(long position, long bytesCount)
           Converts the stream data to the byte array.
static Stream toStream(StreamContainer streamContainer)
           Performs an explicit conversion from StreamContainer to System.IO.Stream.
 void write(byte[] bytes)
           Writes all of the specified bytes to the stream.
 void write(byte[] buffer, int offset, int count)
           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 com.aspose.imaging.DisposableObject
dispose, getDisposed, releaseUnmanagedResources, verifyNotDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamContainer

public StreamContainer(java.io.InputStream stream)

Initializes a new instance of the StreamContainer class.

Parameters:
stream - The stream.

StreamContainer

public StreamContainer(java.io.InputStream stream,
                       boolean disposeStream)

Initializes a new instance of the StreamContainer class.

Parameters:
stream - The data stream.
disposeStream - if set to true the stream will be disposed when container is disposed.
Method Detail

afterStreamDisposed

protected void afterStreamDisposed()

Called after the stream is disposed.


beforeStreamDisposed

protected void beforeStreamDisposed()

Called before the stream is disposed.


canRead

public boolean canRead()

Gets a value indicating whether stream supports reading.

Value: true if stream supports reading; otherwise, false.


canSeek

public boolean canSeek()

Gets a value indicating whether stream supports seeking.

Value: true if stream supports seeking; otherwise, false.


canWrite

public boolean canWrite()

Gets a value indicating whether stream supports writing.

Value: true if stream supports writing; otherwise, false.


flush

public void flush()

Clears all buffers for this stream and causes any buffered data to be written to the underlying device.


getLength

public long getLength()

Gets the stream length in bytes. This value is less than the System.IO.Stream.Length by the starting stream position passed in the StreamContainer constructor.

Value: The stream length.


getPosition

public long getPosition()

Gets the current position within the stream. This value represents offset from the starting stream position passed in the StreamContainer constructor.

Value: The current stream position.


getStream

public java.io.InputStream getStream()

isStreamDisposedOnClose

public boolean isStreamDisposedOnClose()

Gets a value indicating whether this stream is disposed on close.

Value: true if stream is disposed on close; otherwise, false.


read

public int read(byte[] bytes)

Reads bytes to fill the specified bytes buffer.

Parameters:
bytes - The bytes to fill.
Returns:
The number of bytes read. This value can be less than the number of bytes in the buffer if there is not enough bytes in the stream.

read

public int read(byte[] buffer,
                int offset,
                int count)

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.

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.

releaseManagedResources

protected void releaseManagedResources()

Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been already released.

Overrides:
releaseManagedResources in class DisposableObject

save

public void save(java.io.InputStream destinationStream)

save

public void save(java.io.InputStream destinationStream,
                 int bufferSize)

save

public void save(java.io.InputStream destinationStream,
                 int bufferSize,
                 long length)

save

public void save(java.lang.String filePath)

Saves (copies) the stream's data to the specified stream. Uses default buffer size ReadWriteBytesCount and stream Length value.

Parameters:
filePath - The file path to save the stream data to.

save

public void save(java.lang.String filePath,
                 int bufferSize)

Saves (copies) the stream's data to the specified stream. Uses stream Length value.

Parameters:
filePath - The file path to save the stream data to.
bufferSize - The buffer size. By default ReadWriteBytesCount value is used.

save

public void save(java.lang.String filePath,
                 int bufferSize,
                 long length)

Saves (copies) the stream's data to the specified stream.

Parameters:
filePath - The file path to save the stream data to.
bufferSize - The buffer size. By default ReadWriteBytesCount value is used.
length - The stream data length to copy. By default the length is set to Length value.

seek

public long seek(long offset,
                 int origin)

Sets the position within the current stream.

Parameters:
offset - A byte offset relative to the origin parameter. This value represents offset from the starting stream position passed in the StreamContainer constructor.
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.

seekBegin

public void seekBegin()

Sets the stream position to the beginning of the stream. This value represents offset from the starting stream position passed in the StreamContainer constructor.


setLength

public void setLength(long value)

Sets the stream length in bytes. This value is less than the System.IO.Stream.Length by the starting stream position passed in the StreamContainer constructor.

Value: The stream length.


setPosition

public void setPosition(long value)

Sets the current position within the stream. This value represents offset from the starting stream position passed in the StreamContainer constructor.

Value: The current stream position.


shift

public void shift(long shift)

Shifts the data from the current stream position. The data starts from the current byte and continues to the end of the file.

Parameters:
shift - The shift value. Positive value will shift the data to the end of the file, while negative will move the data backwards to the file beginning.

toBytes

public byte[] toBytes()

Converts the stream data to the byte array.

Returns:
The stream data converted to the byte array.

toBytes

public byte[] toBytes(long position,
                      long bytesCount)

Converts the stream data to the byte array.

Parameters:
position - The position to start reading bytes from.
bytesCount - The bytes count to read.
Returns:
The stream data converted to the byte array.

toStream

public static Stream toStream(StreamContainer streamContainer)

Performs an explicit conversion from StreamContainer to System.IO.Stream.

Parameters:
streamContainer - The stream container.
Returns:
The result of the conversion.

write

public void write(byte[] bytes)

Writes all of the specified bytes to the stream.

Parameters:
bytes - The bytes to write.

write

public void write(byte[] buffer,
                  int offset,
                  int count)

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.