C# Class Revenj.Utility.ChunkedMemoryStream

In memory stream with 8192 blocks to avoid LOH issues. Since .NET places objects larger that 85000 bytes into LOH, avoid it as much as possible by using list of smaller blocks.
Inheritance: Stream
Afficher le fichier Open project: ngs-doo/revenj Class Usage Examples

Méthodes publiques

Свойство Type Description
CharBuffer char[]
SmallBuffer char[]

Méthodes publiques

Méthode Description
ChunkedMemoryStream ( Stream another ) : System

Create in memory stream based on another stream. Provided stream will not be disposed.

ChunkedMemoryStream ( Stream another, bool dispose, bool reset ) : System

Create in memory stream based on another stream. Specify whether should provided stream be disposed after copying.

Close ( ) : void

Close current stream. Stream will be added to pool if required. Doesn't release allocated buffers

CopyTo ( ChunkedMemoryStream other ) : void
CopyTo ( Stream stream ) : void

Optimized version of copy to stream

CopyTo ( byte target, int offset ) : void

Copy stream to target buffer

Create ( ) : ChunkedMemoryStream

Create or get a new instance of memory stream Stream is bound to thread and must be released from the same thread

Equals ( Stream another ) : bool

Compare two streams. Length and content will be compared.

Flush ( ) : void

Flush stream. Does nothing.

GetReader ( ) : TextReader

Reuse same text reader on this stream.

GetWriter ( ) : TextWriter

Reuse same text writer on this stream.

Matches ( byte compare ) : bool

Check if stream starts with provided byte[] and matches it's length Provided byte[] must be smaller than 8192 bytes

Read ( byte buffer, int offset, int count ) : int

Read buffer from the stream. Can return less then specified count if remaining block size is less than specified count

ReadByte ( ) : int

Read a single byte

Reset ( ) : void

Set length and position to 0

Seek ( long offset, SeekOrigin origin ) : long

Seek to position in the stream.

Send ( Socket socket ) : void

Send entire stream to provided socket.

SetLength ( long value ) : void

Set new length of the stream. Adjusts the current position if new length is larger then it.

Static ( ) : ChunkedMemoryStream

Create reusable stream. Disposing the stream only has the effect of resetting it.

ToBase64Stream ( ) : Stream

Convert stream to Base 64 String representation in stream.

ToBase64Writer ( TextWriter sw ) : void

Convert stream to Base 64 String representation in the provided writer.

ToPostgresBytea ( TextWriter sw ) : void

Convert stream to Postgres representation of bytea

ToString ( ) : string

Show content of the stream as string

UseBufferedReader ( TextReader reader ) : BufferedTextReader

Reuse buffered text reader associated with this stream. Provide input text reader as data source. Buffered text reader will be initialized with provided input

UseBufferedReader ( string value ) : BufferedTextReader

Reuse buffered text reader associated with this stream. Provide input string as data source. Buffered text reader will be initialized with provided input

Write ( byte buffer, int offset, int count ) : void

Write buffer to stream. Advances current position by count. Increases length if necessary. New blocks will be added as required. It's best to use buffer of size 8192

WriteByte ( byte value ) : void

Write byte to stream. Advances current position by one. Adds a new block if necessary.

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void

Dispose current stream. Stream will be added to pool if required. Used to reset position and length. Doesn't release allocated buffers

Private Methods

Méthode Description
ChunkedMemoryStream ( ) : System
ChunkedMemoryStream ( byte block ) : System

Method Details

ChunkedMemoryStream() public méthode

Create in memory stream based on another stream. Provided stream will not be disposed.
public ChunkedMemoryStream ( Stream another ) : System
another Stream stream to copy
Résultat System

ChunkedMemoryStream() public méthode

Create in memory stream based on another stream. Specify whether should provided stream be disposed after copying.
public ChunkedMemoryStream ( Stream another, bool dispose, bool reset ) : System
another Stream stream to copy
dispose bool dispose provided stream
reset bool reset provided stream to original position
Résultat System

Close() public méthode

Close current stream. Stream will be added to pool if required. Doesn't release allocated buffers
public Close ( ) : void
Résultat void

CopyTo() public méthode

public CopyTo ( ChunkedMemoryStream other ) : void
other ChunkedMemoryStream
Résultat void

CopyTo() public méthode

Optimized version of copy to stream
public CopyTo ( Stream stream ) : void
stream Stream destination stream
Résultat void

CopyTo() public méthode

Copy stream to target buffer
public CopyTo ( byte target, int offset ) : void
target byte target array buffer
offset int start at offset
Résultat void

Create() public static méthode

Create or get a new instance of memory stream Stream is bound to thread and must be released from the same thread
public static Create ( ) : ChunkedMemoryStream
Résultat ChunkedMemoryStream

Dispose() protected méthode

Dispose current stream. Stream will be added to pool if required. Used to reset position and length. Doesn't release allocated buffers
protected Dispose ( bool disposing ) : void
disposing bool
Résultat void

Equals() public méthode

Compare two streams. Length and content will be compared.
public Equals ( Stream another ) : bool
another Stream stream to compare
Résultat bool

Flush() public méthode

Flush stream. Does nothing.
public Flush ( ) : void
Résultat void

GetReader() public méthode

Reuse same text reader on this stream.
public GetReader ( ) : TextReader
Résultat TextReader

GetWriter() public méthode

Reuse same text writer on this stream.
public GetWriter ( ) : TextWriter
Résultat System.IO.TextWriter

Matches() public méthode

Check if stream starts with provided byte[] and matches it's length Provided byte[] must be smaller than 8192 bytes
public Matches ( byte compare ) : bool
compare byte
Résultat bool

Read() public méthode

Read buffer from the stream. Can return less then specified count if remaining block size is less than specified count
public Read ( byte buffer, int offset, int count ) : int
buffer byte copy to buffer
offset int offset in the buffer
count int maximum size to read
Résultat int

ReadByte() public méthode

Read a single byte
public ReadByte ( ) : int
Résultat int

Reset() public méthode

Set length and position to 0
public Reset ( ) : void
Résultat void

Seek() public méthode

Seek to position in the stream.
public Seek ( long offset, SeekOrigin origin ) : long
offset long offset at stream
origin SeekOrigin position type
Résultat long

Send() public méthode

Send entire stream to provided socket.
public Send ( Socket socket ) : void
socket System.Net.Sockets.Socket where to send
Résultat void

SetLength() public méthode

Set new length of the stream. Adjusts the current position if new length is larger then it.
public SetLength ( long value ) : void
value long new length
Résultat void

Static() public static méthode

Create reusable stream. Disposing the stream only has the effect of resetting it.
public static Static ( ) : ChunkedMemoryStream
Résultat ChunkedMemoryStream

ToBase64Stream() public méthode

Convert stream to Base 64 String representation in stream.
public ToBase64Stream ( ) : Stream
Résultat Stream

ToBase64Writer() public méthode

Convert stream to Base 64 String representation in the provided writer.
public ToBase64Writer ( TextWriter sw ) : void
sw System.IO.TextWriter
Résultat void

ToPostgresBytea() public méthode

Convert stream to Postgres representation of bytea
public ToPostgresBytea ( TextWriter sw ) : void
sw System.IO.TextWriter
Résultat void

ToString() public méthode

Show content of the stream as string
public ToString ( ) : string
Résultat string

UseBufferedReader() public méthode

Reuse buffered text reader associated with this stream. Provide input text reader as data source. Buffered text reader will be initialized with provided input
public UseBufferedReader ( TextReader reader ) : BufferedTextReader
reader TextReader input for processing
Résultat BufferedTextReader

UseBufferedReader() public méthode

Reuse buffered text reader associated with this stream. Provide input string as data source. Buffered text reader will be initialized with provided input
public UseBufferedReader ( string value ) : BufferedTextReader
value string input for processing
Résultat BufferedTextReader

Write() public méthode

Write buffer to stream. Advances current position by count. Increases length if necessary. New blocks will be added as required. It's best to use buffer of size 8192
public Write ( byte buffer, int offset, int count ) : void
buffer byte provided bytes
offset int offset in bytes
count int total length
Résultat void

WriteByte() public méthode

Write byte to stream. Advances current position by one. Adds a new block if necessary.
public WriteByte ( byte value ) : void
value byte byte to write
Résultat void

Property Details

CharBuffer public_oe property

Temporary char buffer for reuse (8192*4/3 + 2 chars)
public char[] CharBuffer
Résultat char[]

SmallBuffer public_oe property

Temporary small char buffer for reuse (64 chars)
public char[] SmallBuffer
Résultat char[]