Table of Contents

StreamFactory Class

Definition

Namespace
Cuemon.IO
Assemblies
Cuemon.IO.dll
Source
src/Cuemon.IO/StreamFactory.cs

Provides access to factory methods for creating Stream instances.

public static class StreamFactory
Inheritance
StreamFactory

Examples

The following example demonstrates how to create instances using .

// Program.cs
using System;
using System.IO;
using System.Text;
using Cuemon.IO;
using Cuemon.Text;

// 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

Name Description
Create(Action<IBufferWriter<byte>>, Action<BufferWriterOptions>)

Creates and returns a Stream by the specified delegate writer.

Create(Action<StreamWriter>, Action<StreamWriterOptions>)

Creates and returns a Stream by the specified delegate writer.

Create<T>(Action<IBufferWriter<byte>, T>, T, Action<BufferWriterOptions>)

Creates and returns a Stream by the specified delegate writer.

Create<T>(Action<StreamWriter, T>, T, Action<StreamWriterOptions>)

Creates and returns a Stream by the specified delegate writer.

Create<T1, T2>(Action<IBufferWriter<byte>, T1, T2>, T1, T2, Action<BufferWriterOptions>)

Creates and returns a Stream by the specified delegate writer.

Create<T1, T2>(Action<StreamWriter, T1, T2>, T1, T2, Action<StreamWriterOptions>)

Creates and returns a Stream by the specified 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.

Create<T1, T2, T3>(Action<StreamWriter, T1, T2, T3>, T1, T2, T3, Action<StreamWriterOptions>)

Creates and returns a Stream by the specified 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.

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.

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.

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.