Class StreamFactory
Provides access to factory methods for creating Stream instances.
public static class StreamFactory
- Inheritance
-
StreamFactory
Examples
The following example demonstrates how to create
using System;
using System.IO;
using System.Text;
using Cuemon.IO;
using Cuemon.Text;
namespace MyApp.Examples;
public static class StreamFactoryExample
{
public static void Demonstrate()
{
// Create a stream by writing to a StreamWriter
Stream stream = StreamFactory.Create(writer =>
{
writer.Write("Hello, StreamFactory!");
});
Console.WriteLine($"Stream length: {stream.Length}");
Console.WriteLine($"Stream position: {stream.Position}");
using var reader = new StreamReader(stream);
string content = reader.ReadToEnd();
Console.WriteLine(content);
// Create a stream with encoding options
Stream utf32Stream = StreamFactory.Create(writer =>
{
writer.Write("UTF-32 encoded content");
}, options =>
{
options.Encoding = Encoding.UTF32;
options.Preamble = PreambleSequence.Remove;
});
using var utf32Reader = new StreamReader(utf32Stream, Encoding.UTF32);
Console.WriteLine(utf32Reader.ReadToEnd());
}
}
Methods
Create(Action<IBufferWriter<byte>>, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create(Action<IBufferWriter<byte>> writer, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>>The delegate that will create an in-memory Stream.
setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Create(Action<StreamWriter>, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create(Action<StreamWriter> writer, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter>The delegate that will create an in-memory Stream.
setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Create<T>(Action<IBufferWriter<byte>, T>, T, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T>(Action<IBufferWriter<byte>, T> writer, T arg, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>, T>The delegate that will create an in-memory Stream.
argTThe parameter of the delegate
writer.setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Type Parameters
TThe type of the parameter of the delegate
writer.
Create<T>(Action<StreamWriter, T>, T, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T>(Action<StreamWriter, T> writer, T arg, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter, T>The delegate that will create an in-memory Stream.
argTThe parameter of the delegate
writer.setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Type Parameters
TThe type of the parameter of the delegate
writer.
Create<T1, T2>(Action<IBufferWriter<byte>, T1, T2>, T1, T2, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2>(Action<IBufferWriter<byte>, T1, T2> writer, T1 arg1, T2 arg2, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>, T1, T2>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.
Create<T1, T2>(Action<StreamWriter, T1, T2>, T1, T2, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2>(Action<StreamWriter, T1, T2> writer, T1 arg1, T2 arg2, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter, T1, T2>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.
Create<T1, T2, T3>(Action<IBufferWriter<byte>, T1, T2, T3>, T1, T2, T3, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3>(Action<IBufferWriter<byte>, T1, T2, T3> writer, T1 arg1, T2 arg2, T3 arg3, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>, T1, T2, T3>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.
Create<T1, T2, T3>(Action<StreamWriter, T1, T2, T3>, T1, T2, T3, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3>(Action<StreamWriter, T1, T2, T3> writer, T1 arg1, T2 arg2, T3 arg3, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter, T1, T2, T3>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.
Create<T1, T2, T3, T4>(Action<IBufferWriter<byte>, T1, T2, T3, T4>, T1, T2, T3, T4, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3, T4>(Action<IBufferWriter<byte>, T1, T2, T3, T4> writer, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>, T1, T2, T3, T4>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.arg4T4The fourth parameter of the delegate
writer.setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.T4The type of the fourth parameter of the delegate
writer.
Create<T1, T2, T3, T4>(Action<StreamWriter, T1, T2, T3, T4>, T1, T2, T3, T4, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3, T4>(Action<StreamWriter, T1, T2, T3, T4> writer, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter, T1, T2, T3, T4>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.arg4T4The fourth parameter of the delegate
writer.setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.T4The type of the fourth parameter of the delegate
writer.
Create<T1, T2, T3, T4, T5>(Action<IBufferWriter<byte>, T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5, Action<BufferWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3, T4, T5>(Action<IBufferWriter<byte>, T1, T2, T3, T4, T5> writer, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<BufferWriterOptions> setup = null)
Parameters
writerAction<IBufferWriter<byte>, T1, T2, T3, T4, T5>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.arg4T4The fourth parameter of the delegate
writer.arg5T5The fifth parameter of the delegate
writer.setupAction<BufferWriterOptions>The BufferWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.T4The type of the fourth parameter of the delegate
writer.T5The type of the fifth parameter of the delegate
writer.
Create<T1, T2, T3, T4, T5>(Action<StreamWriter, T1, T2, T3, T4, T5>, T1, T2, T3, T4, T5, Action<StreamWriterOptions>)
Creates and returns a Stream by the specified delegate writer.
public static Stream Create<T1, T2, T3, T4, T5>(Action<StreamWriter, T1, T2, T3, T4, T5> writer, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Action<StreamWriterOptions> setup = null)
Parameters
writerAction<StreamWriter, T1, T2, T3, T4, T5>The delegate that will create an in-memory Stream.
arg1T1The first parameter of the delegate
writer.arg2T2The second parameter of the delegate
writer.arg3T3The third parameter of the delegate
writer.arg4T4The fourth parameter of the delegate
writer.arg5T5The fifth parameter of the delegate
writer.setupAction<StreamWriterOptions>The StreamWriterOptions which may be configured.
Returns
Type Parameters
T1The type of the first parameter of the delegate
writer.T2The type of the second parameter of the delegate
writer.T3The type of the third parameter of the delegate
writer.T4The type of the fourth parameter of the delegate
writer.T5The type of the fifth parameter of the delegate
writer.