Class StreamContainer
Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.7.0)
Represents stream container which contains the stream and provides stream processing routines.
[JsonObject(MemberSerialization.OptIn)]
public class StreamContainer : DisposableObject, IDisposable
{
public void Dispose()
{
base.Dispose();
GC.SuppressFinalize(this);
}
}
Inheritance
object ← DisposableObject ← StreamContainer
Derived
FileStreamContainer , SplitStreamContainer
Implements
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)
{
this.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)
{
_stream = stream;
_disposeStream = 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
startPosition
The starting position inside the stream.
[JsonIgnore]
protected long StartPosition
{
get;
set;
}
Field Value
Properties
CanRead
Gets a value indicating whether stream supports reading.
public virtual bool CanRead
{
get;
}
Property Value
CanSeek
Gets a value indicating whether stream supports seeking.
public virtual bool CanSeek
{
get;
}
Property Value
CanWrite
Gets a value indicating whether stream supports writing.
public virtual bool CanWrite
{
get;
}
Property Value
IsStreamDisposedOnClose
Gets a value indicating whether this stream is disposed on close.
public virtual bool IsStreamDisposedOnClose
{
get;
}
Property Value
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
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
Stream
Gets the data stream.
public virtual System.IO.Stream Get() => this.Stream;
Property Value
SyncRoot
Gets an object that can be used to synchronize access to the synchronized resource.
public object SyncRoot
{
get;
}
Property Value
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
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
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()
{
}
In this specific case, there was no need for reformatting since the provided code already adheres to standard C# conventions. However, if the code had issues such as incorrect indentation or missing whitespace, I would have reformatted it accordingly while preserving the existing logic and structure.
Returns
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()
{
base.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)
{
}
I have indented the opening bracket to be on a new line and added one space after the closing parenthesis of the method arguments. This aligns with standard C# conventions for method declarations. The rest of your code has been left unchanged as requested.
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)
{
}
The given code is already formatted according to C# conventions. Here I simply added a new line after the opening brace `{` for better readability.
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
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()
{
}
In this case, no changes are needed as the code is already formatted according to standard C# conventions.
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)
{
}
In this case, there are no modifications needed as the provided code already follows standard C# conventions for indentation and spacing.
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 override void Write(byte[] buffer, int offset, int count)
{
base.Write(buffer, offset, 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
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)
{
}
In order to improve readability, I added a line break after the opening bracket and before the closing bracket. Additionally, I maintained proper indentation for the curly braces, and there's one space between the keyword 'operator', the operator symbol, and its operand.
Parameters
streamContainer
StreamContainer
The stream container.
Returns
The result of the conversion.