本文整理汇总了C#中StreamMode类的典型用法代码示例。如果您正苦于以下问题:C# StreamMode类的具体用法?C# StreamMode怎么用?C# StreamMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamMode类属于命名空间,在下文中一共展示了StreamMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Request
/// <summary>
/// This method is called when stream is requested, if you return a stream
/// it will return it to the user else it will keep trying all the other StreamFactorys
/// until one does return a stream.
/// </summary>
/// <param name="path">Path of file or object to create stream to.</param>
/// <param name="mode">Determines how to open or create stream.</param>
/// <returns>A Stream instance or NULL if this factory can't open the given stream.</returns>
protected override Stream Request(object path, StreamMode mode)
{
// if (File.Exists(path.ToString()) == false && moede != StreamMode.Open) return null;
try
{
switch (mode)
{
case StreamMode.Append:
if (Directory.Exists(Path.GetDirectoryName(path.ToString()))) Directory.CreateDirectory(Path.GetDirectoryName(path.ToString()));
if (File.Exists(path.ToString()) == false) File.Create(path.ToString()).Close();
return new FileStream(path.ToString(), FileMode.Append);
case StreamMode.Open:
return new FileStream(path.ToString(), FileMode.Open);
case StreamMode.Truncate:
if (Directory.Exists(Path.GetDirectoryName(path.ToString()))) Directory.CreateDirectory(Path.GetDirectoryName(path.ToString()));
if (File.Exists(path.ToString()) == false) File.Create(path.ToString()).Close();
return new FileStream(path.ToString(), FileMode.Truncate);
}
}
catch (Exception) {}
return null;
}
示例2: QueueStream
public QueueStream(Stream stream, StreamMode mode, int bufferSize, BufferManager bufferManager)
{
if (mode == StreamMode.Read)
{
_stream = new ReadStream(stream, bufferSize, bufferManager);
}
else if (mode == StreamMode.Write)
{
_stream = new WriteStream(new CacheStream(stream, QueueStream.BlockSize, bufferManager), bufferSize, bufferManager);
}
}
示例3: FlacStream
public FlacStream(string file, StreamMode mode, StreamAccessMode accessMode)
{
FileMode fileMode;
FileAccess fileAccessMode;
switch (mode)
{
case StreamMode.CreateNew:
{
fileMode = FileMode.Create;
break;
}
case StreamMode.OpenExisting:
{
fileMode = FileMode.Open;
break;
}
default:
{
throw new FlacDebugException();
}
}
switch (accessMode)
{
case StreamAccessMode.Read:
case StreamAccessMode.Write:
case StreamAccessMode.Both:
{
fileAccessMode = (FileAccess)accessMode;
break;
}
default:
{
throw new FlacDebugException();
}
}
fileStream_ = new FileStream(file, fileMode, fileAccessMode, FileShare.Read);
if ((accessMode & StreamAccessMode.Read) == StreamAccessMode.Read)
{
reader_ = new FlacStreamReader(fileStream_);
}
if ((accessMode & StreamAccessMode.Write) == StreamAccessMode.Write)
{
writer_ = new FlacStreamWriter(fileStream_);
}
}
示例4: Request
/// <summary>
/// This method is called when stream is requested, if you return a stream
/// it will return it to the user else it will keep trying all the other StreamFactorys
/// until one does return a stream.
/// </summary>
/// <param name="path">Path of file or object to create stream to.</param>
/// <param name="mode">Determines how to open or create stream.</param>
/// <returns>A Stream instance or NULL if this factory can't open the given stream.</returns>
protected override Stream Request(object path,StreamMode mode)
{
if (path.ToString().ToLower().Substring(0, 4) != "[email protected]") return null;
// Check if we have been handed a capacity as well.
if (path.ToString().Length > 4)
{
string capacityStr = path.ToString().Substring(4, path.ToString().Length - 4);
int capacity = 0;
if (int.TryParse(capacityStr, out capacity) == true)
return new MemoryStream(capacity);
else
return new MemoryStream();
}
else
{
return new MemoryStream();
}
}
示例5: BizTalkMessagePartStream
/// <summary>
/// Initializes a new instance of the <see cref="BizTalkMessagePartStream"/> class.
/// </summary>
/// <param name="stream">The stream from which to read (or write if in compression mode).</param>
/// <param name="mode">The compression mode.</param>
public BizTalkMessagePartStream(Stream stream, StreamMode mode)
{
this.innerStream = stream;
this.streamMode = mode;
if (mode == StreamMode.Write)
{
this.writeStream = new BizTalkBlockStream(this.innerStream);
}
else if (mode == StreamMode.Read)
{
this.reader = new BizTalkBlockReader(stream);
this.readBuffer = new MemoryStream();
}
else
{
throw new ArgumentException("Unknown stream mode specified: " + mode, "mode");
}
}
示例6: lock
Task<int> IStreamReader.ReadAsync(byte[] buffer, int offset, int length, StreamMode mode)
{
Utilities.DebugCheckStreamArguments(buffer, offset, length, mode);
lock (this)
{
int total = 0;
while (length > 0)
{
while (mBuffer == null)
{
if (mComplete)
return Task.FromResult(total);
Monitor.Wait(this);
}
int copied = Math.Min(length, mLength);
System.Diagnostics.Debug.Assert(copied > 0);
Buffer.BlockCopy(mBuffer, mOffset, buffer, offset, copied);
mOffset += copied;
mLength -= copied;
offset += copied;
length -= copied;
total += copied;
if (mLength == 0)
{
mBuffer = null;
Monitor.PulseAll(this);
}
if (mode == StreamMode.Partial)
break;
}
return Task.FromResult(total);
}
}
示例7: Write
public override void Write(System.Byte[] buffer, int offset, int count)
{
// workitem 7159
// calculate the CRC on the unccompressed data (before writing)
if (crc != null)
crc.SlurpBlock(buffer, offset, count);
if (_streamMode == StreamMode.Undefined)
_streamMode = StreamMode.Writer;
else if (_streamMode != StreamMode.Writer)
throw new ZlibException("Cannot Write after Reading.");
if (count == 0)
return;
// first reference of z property will initialize the private var _z
z.InputBuffer = buffer;
_z.NextIn = offset;
_z.AvailableBytesIn = count;
bool done = false;
do
{
_z.OutputBuffer = workingBuffer;
_z.NextOut = 0;
_z.AvailableBytesOut = _workingBuffer.Length;
int rc = (_wantCompress)
? _z.Deflate(_flushMode)
: _z.Inflate(_flushMode);
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message);
//if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
_stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;
// If GZIP and de-compress, we're done when 8 bytes remain.
if (_flavor == ZlibStreamFlavor.GZIP && !_wantCompress)
done = (_z.AvailableBytesIn == 8 && _z.AvailableBytesOut != 0);
}
while (!done);
}
示例8: Write
/// <param name="buffer"></param><param name="offset"></param> <param name="count"></param><exception cref = "ZlibException"></exception><exception cref = "ZlibException"></exception>
public override void Write(byte[] buffer, int offset, int count)
{
// workitem 7159
// calculate the CRC on the unccompressed data (before writing)
if (this.crc != null)
{
this.crc.SlurpBlock(buffer, offset, count);
}
if (this.Mode == StreamMode.Undefined)
{
this.Mode = StreamMode.Writer;
}
else if (this.Mode != StreamMode.Writer)
{
throw new ZlibException("Cannot Write after Reading.");
}
if (count == 0)
{
return;
}
// first reference of z property will initialize the private var _z
this.Z.InputBuffer = buffer;
this.ZlibCodec.NextIn = offset;
this.ZlibCodec.AvailableBytesIn = count;
bool done;
do
{
this.ZlibCodec.OutputBuffer = this.WorkingBuffer;
this.ZlibCodec.NextOut = 0;
this.ZlibCodec.AvailableBytesOut = this.workBuffer.Length;
int rc = this.WantCompress ? this.ZlibCodec.Deflate(this.flushMode) : this.ZlibCodec.Inflate();
if (rc != ZlibConstants.Zok && rc != ZlibConstants.ZStreamEnd)
{
throw new ZlibException((this.WantCompress ? "de" : "in") + "flating: " + this.ZlibCodec.Message);
}
// if (_workingBuffer.Length - _z.AvailableBytesOut > 0)
this.Stream.Write(this.workBuffer, 0, this.workBuffer.Length - this.ZlibCodec.AvailableBytesOut);
done = this.ZlibCodec.AvailableBytesIn == 0 && this.ZlibCodec.AvailableBytesOut != 0;
// If GZIP and de-compress, we're done when 8 bytes remain.
if (this.flavor == ZlibStreamFlavor.Gzip && !this.WantCompress)
{
done = this.ZlibCodec.AvailableBytesIn == 8 && this.ZlibCodec.AvailableBytesOut != 0;
}
}
while (!done);
}
示例9: RealizeFont
/// <summary>
/// Makes the specified font and brush to the current graphics objects.
/// </summary>
void RealizeFont(Glyphs glyphs)
{
if (this.streamMode != StreamMode.Text)
{
this.streamMode = StreamMode.Text;
WriteLiteral("BT\n");
// Text matrix is empty after BT
this.graphicsState.realizedTextPosition = new XPoint();
}
this.graphicsState.RealizeFont(glyphs);
}
示例10: Realize
/// <summary>
/// Makes the specified font and brush to the current graphics objects.
/// </summary>
void Realize(XFont font, XBrush brush, int renderMode)
{
BeginPage();
RealizeTransform();
if (this.streamMode != StreamMode.Text)
{
this.streamMode = StreamMode.Text;
this.content.Append("BT\n");
// Text matrix is empty after BT
this.gfxState.realizedTextPosition = new XPoint();
}
this.gfxState.RealizeFont(font, brush, renderMode);
}
示例11: Write
public override void Write(System.Byte[] buffer, int offset, int length)
{
if (_streamMode == StreamMode.Undefined) _streamMode = StreamMode.Writer;
if (_streamMode != StreamMode.Writer)
throw new ZlibException("Cannot Write after Reading.");
if (length == 0)
return;
_z.InputBuffer = buffer;
_z.NextIn = offset;
_z.AvailableBytesIn = length;
do
{
_z.OutputBuffer = _workingBuffer;
_z.NextOut = 0;
_z.AvailableBytesOut = _workingBuffer.Length;
int rc = (_wantCompress)
? 1
: _z.Inflate(_flushMode);
if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message);
_stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
}
while (_z.AvailableBytesIn > 0 || _z.AvailableBytesOut == 0);
}
示例12: Read
public override int Read( byte [] buffer, int offset, int count )
{
if ( streamMode == StreamMode.Undefined )
{
if ( !this.stream.CanRead ) throw new CompressionProcessException ( "The stream is not readable." );
streamMode = StreamMode.Reader;
z.AvailableBytesIn = 0;
}
if ( streamMode != StreamMode.Reader )
throw new CompressionProcessException ( "Cannot Read after Writing." );
if ( count == 0 ) return 0;
if ( nomoreinput && _wantCompress ) return 0;
if ( buffer == null ) throw new ArgumentNullException ( "buffer" );
if ( count < 0 ) throw new ArgumentOutOfRangeException ( "count" );
if ( offset < buffer.GetLowerBound ( 0 ) ) throw new ArgumentOutOfRangeException ( "offset" );
if ( ( offset + count ) > buffer.GetLength ( 0 ) ) throw new ArgumentOutOfRangeException ( "count" );
int rc = 0;
_z.OutputBuffer = buffer;
_z.NextOut = offset;
_z.AvailableBytesOut = count;
_z.InputBuffer = workingBuffer;
do
{
if ( ( _z.AvailableBytesIn == 0 ) && ( !nomoreinput ) )
{
_z.NextIn = 0;
_z.AvailableBytesIn = stream.Read ( _workingBuffer, 0, _workingBuffer.Length );
if ( _z.AvailableBytesIn == 0 )
nomoreinput = true;
}
rc = ( _wantCompress )
? _z.Deflate ( flushMode )
: _z.Inflate ( flushMode );
if ( nomoreinput && ( rc == ZlibConstants.Z_BUF_ERROR ) )
return 0;
if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
throw new CompressionProcessException ( String.Format ( "{0}flating: rc={1} msg={2}", ( _wantCompress ? "de" : "in" ), rc, _z.Message ) );
if ( ( nomoreinput || rc == ZlibConstants.Z_STREAM_END ) && ( _z.AvailableBytesOut == count ) )
break;
}
while ( _z.AvailableBytesOut > 0 && !nomoreinput && rc == ZlibConstants.Z_OK );
if ( _z.AvailableBytesOut > 0 )
{
if ( rc == ZlibConstants.Z_OK && _z.AvailableBytesIn == 0 )
{
}
if ( nomoreinput )
{
if ( _wantCompress )
{
rc = _z.Deflate ( FlushType.Finish );
if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
throw new CompressionProcessException ( String.Format ( "Deflating: rc={0} msg={1}", rc, _z.Message ) );
}
}
}
rc = ( count - _z.AvailableBytesOut );
return rc;
}
示例13: WriteAsync
public Task<int> WriteAsync(byte[] buffer, int offset, int length, StreamMode mode)
{
Utilities.CheckStreamArguments(buffer, offset, length, mode);
int processed = 0;
while (length > 0)
{
Frame frame;
lock (mSyncObject)
{
System.Diagnostics.Debug.Assert(mRunning);
if (mDisposeTask != null)
throw new OperationCanceledException();
while (mQueue.Count == 0)
{
Monitor.Wait(mSyncObject);
if (mDisposeTask != null)
throw new OperationCanceledException();
}
frame = mQueue.Peek();
}
var capacity = frame.mEnding - frame.mOffset;
var copySize = Math.Min(capacity, length > Int32.MaxValue ? Int32.MaxValue : (int)length);
Buffer.BlockCopy(buffer, offset, frame.mBuffer, frame.mOffset, copySize);
frame.mOffset += copySize;
offset += copySize;
processed += copySize;
length -= copySize;
if (copySize == capacity || frame.mMode == StreamMode.Partial)
{
frame.mCompletion.SetResult(frame.mOffset - frame.mOrigin);
lock (mSyncObject)
{
System.Diagnostics.Debug.Assert(mRunning);
var other = mQueue.Dequeue();
System.Diagnostics.Debug.Assert(other == frame);
}
}
}
return Task.FromResult(processed);
}
示例14: ReadAsync
public Task<int> ReadAsync(byte[] buffer, int offset, int length, StreamMode mode)
{
Utilities.CheckStreamArguments(buffer, offset, length, mode);
var frame = new Frame();
frame.mBuffer = buffer;
frame.mOrigin = offset;
frame.mOffset = offset;
frame.mEnding = offset + length;
frame.mMode = mode;
lock (mSyncObject)
{
if (mDisposeTask != null)
throw new ObjectDisposedException(null);
mQueue.Enqueue(frame);
Monitor.Pulse(mSyncObject);
}
return frame.mCompletion.Task;
}
示例15: Write
public override void Write( System.Byte [] buffer, int offset, int count )
{
if ( streamMode == StreamMode.Undefined )
streamMode = StreamMode.Writer;
else if ( streamMode != StreamMode.Writer )
throw new CompressionProcessException ( "Cannot Write after Reading." );
if ( count == 0 )
return;
z.InputBuffer = buffer;
_z.NextIn = offset;
_z.AvailableBytesIn = count;
bool done = false;
do
{
_z.OutputBuffer = workingBuffer;
_z.NextOut = 0;
_z.AvailableBytesOut = _workingBuffer.Length;
int rc = ( _wantCompress )
? _z.Deflate ( flushMode )
: _z.Inflate ( flushMode );
if ( rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END )
throw new CompressionProcessException ( ( _wantCompress ? "de" : "in" ) + "flating: " + _z.Message );
stream.Write ( _workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut );
done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0;
}
while ( !done );
}