Class StreamContainer

Class StreamContainer

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.2.0)

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

[JsonObject(MemberSerialization.OptIn)]
public class StreamContainer : DisposableObject, IDisposable

Inheritance

objectDisposableObjectStreamContainer

Derived

FileStreamContainer, SplitStreamContainer

Implements

IDisposable

Inherited Members

DisposableObject.Dispose(), DisposableObject.ReleaseManagedResources(), DisposableObject.ReleaseUnmanagedResources(), DisposableObject.VerifyNotDisposed(), DisposableObject.Disposed, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

StreamContainer(Stream)

Initializes a new instance of the Aspose.Imaging.StreamContainer class.

public StreamContainer(Stream stream)

Parameters

stream Stream

The stream.

StreamContainer(Stream, bool)

Initializes a new instance of the Aspose.Imaging.StreamContainer class.

public StreamContainer(Stream stream, bool disposeStream)

Parameters

stream Stream

The data stream.

disposeStream bool

if set to true the stream will be disposed when container is disposed.

Fields

ReadWriteBytesCount

Specifies read and write bytes count when reading sequentially.

public const int ReadWriteBytesCount = 4096

Field Value

int

startPosition

The starting position inside the stream.

[JsonIgnore]
protected long startPosition

Field Value

long

Properties

CanRead

Gets a value indicating whether stream supports reading.

public virtual bool CanRead { get; }

Property Value

bool

CanSeek

Gets a value indicating whether stream supports seeking.

public virtual bool CanSeek { get; }

Property Value

bool

CanWrite

Gets a value indicating whether stream supports writing.

public virtual bool CanWrite { get; }

Property Value

bool

IsStreamDisposedOnClose

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

public virtual bool IsStreamDisposedOnClose { get; }

Property Value

bool

Length

Gets or 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.

public virtual long Length { get; set; }

Property Value

long

Position

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

public virtual long Position { get; set; }

Property Value

long

Stream

Gets the data stream.

public virtual Stream Stream { get; }

Property Value

Stream

SyncRoot

Gets an object that can be used to synchronize access to the synchronized resource.

public object SyncRoot { get; }

Property Value

object

Methods

AfterStreamDisposed()

Called after the stream is disposed.

protected virtual void AfterStreamDisposed()

BeforeSave(Stream)

Called before save occurs on the destination stream.

protected virtual void BeforeSave(Stream destinationStream)

Parameters

destinationStream Stream

The destination stream.

BeforeStreamDisposed()

Called before the stream is disposed.

protected virtual void BeforeStreamDisposed()

DisposeStream()

Disposes the stream.

protected virtual void DisposeStream()

Flush()

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

public virtual void Flush()

Read(byte[])

Reads bytes to fill the specified bytes buffer.

public virtual int Read(byte[] bytes)

Parameters

bytes byte[]

The bytes to fill.

Returns

int

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(byte[], int, int)

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

public virtual int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

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 int

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

count int

The maximum number of bytes to be read from the current stream.

Returns

int

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()

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.

public virtual int ReadByte()

Returns

int

The unsigned byte cast to an Int32, or -1 if at the end of the stream.

ReleaseManagedResources()

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

protected override void ReleaseManagedResources()

Save(Stream)

Saves (copies) the stream’s data to the specified stream. Uses default buffer size Aspose.Imaging.StreamContainer.ReadWriteBytesCount and stream Aspose.Imaging.StreamContainer.Length value.

public virtual void Save(Stream destinationStream)

Parameters

destinationStream Stream

The stream to save the data to.

Save(Stream, int)

Saves (copies) all the stream’s data to the specified stream. Uses stream Aspose.Imaging.StreamContainer.Length value.

public virtual void Save(Stream destinationStream, int bufferSize)

Parameters

destinationStream Stream

The stream to save the data to.

bufferSize int

The buffer.

Save(Stream, int, long)

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

public virtual void Save(Stream destinationStream, int bufferSize, long length)

Parameters

destinationStream Stream

The stream to save the data to.

bufferSize int

The buffer size. By default Aspose.Imaging.StreamContainer.ReadWriteBytesCount value is used.

length long

The stream data length to copy. By default the length is set to Aspose.Imaging.StreamContainer.Length value.

Save(string)

Saves (copies) the stream’s data to the specified stream. Uses default buffer size Aspose.Imaging.StreamContainer.ReadWriteBytesCount and stream Aspose.Imaging.StreamContainer.Length value.

public virtual void Save(string filePath)

Parameters

filePath string

The file path to save the stream data to.

Save(string, int)

Saves (copies) the stream’s data to the specified stream. Uses stream Aspose.Imaging.StreamContainer.Length value.

public virtual void Save(string filePath, int bufferSize)

Parameters

filePath string

The file path to save the stream data to.

bufferSize int

The buffer size. By default Aspose.Imaging.StreamContainer.ReadWriteBytesCount value is used.

Save(string, int, long)

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

public virtual void Save(string filePath, int bufferSize, long length)

Parameters

filePath string

The file path to save the stream data to.

bufferSize int

The buffer size. By default Aspose.Imaging.StreamContainer.ReadWriteBytesCount value is used.

length long

The stream data length to copy. By default the length is set to Aspose.Imaging.StreamContainer.Length value.

Seek(long, SeekOrigin)

Sets the position within the current stream.

public virtual long Seek(long offset, SeekOrigin origin)

Parameters

offset long

A byte offset relative to the origin parameter. This value represents offset from the starting stream position passed in the StreamContainer constructor.

origin SeekOrigin

A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.

Returns

long

The new position within the current stream.

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.

public virtual void SeekBegin()

ToBytes()

Converts the stream data to the System.Byte array.

public virtual byte[] ToBytes()

Returns

byte[]

The stream data converted to the System.Byte array.

ToBytes(long, long)

Converts the stream data to the System.Byte array.

public virtual byte[] ToBytes(long position, long bytesCount)

Parameters

position long

The position to start reading bytes from.

bytesCount long

The bytes count to read.

Returns

byte[]

The stream data converted to the System.Byte array.

Write(byte[])

Writes all of the specified bytes to the stream.

public virtual void Write(byte[] bytes)

Parameters

bytes byte[]

The bytes to write.

Write(byte[], int, int)

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

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

Parameters

buffer byte[]

An array of bytes. This method copies count bytes from buffer to the current stream.

offset int

The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

count int

The number of bytes to be written to the current stream.

WriteByte(byte)

Writes a byte to the current position in the stream and advances the position within the stream by one byte.

public virtual void WriteByte(byte value)

Parameters

value byte

The byte to write to the stream.

WriteTo(StreamContainer)

Copies the contained data to another Aspose.Imaging.StreamContainer.

public virtual void WriteTo(StreamContainer streamContainer)

Parameters

streamContainer StreamContainer

The stream container to copy to.

WriteTo(StreamContainer, long)

Copies the contained data to another Aspose.Imaging.StreamContainer.

public virtual void WriteTo(StreamContainer streamContainer, long length)

Parameters

streamContainer StreamContainer

The stream container to copy to.

length long

The bytes count to write.

Exceptions

FrameworkException

Copy operation cannot complete. Cannot read + count + bytes.

Operators

explicit operator Stream(StreamContainer)

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

public static explicit operator Stream(StreamContainer streamContainer)

Parameters

streamContainer StreamContainer

The stream container.

Returns

Stream

The result of the conversion.