mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
73 lines
1.5 KiB
C#
73 lines
1.5 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace ClassicalSharp {
|
|
|
|
internal class FixedBufferStream : Stream {
|
|
|
|
public byte[] _buffer;
|
|
private int _position;
|
|
private int _length;
|
|
|
|
public override bool CanRead {
|
|
get { return true; }
|
|
}
|
|
|
|
public override bool CanSeek {
|
|
get { return false; }
|
|
}
|
|
|
|
public override bool CanWrite {
|
|
get { return false; }
|
|
}
|
|
|
|
public override long Length {
|
|
get { return _length; }
|
|
}
|
|
|
|
public override long Position {
|
|
get { return _position; }
|
|
set { _position = (int)value; }
|
|
}
|
|
|
|
public FixedBufferStream( int capacity ) {
|
|
_buffer = new byte[capacity];
|
|
_length = capacity;
|
|
}
|
|
|
|
public override void Flush() {
|
|
}
|
|
|
|
public override int Read( byte[] buffer, int offset, int count ) {
|
|
int numBytes = _length - _position;
|
|
if( numBytes > count ) numBytes = count;
|
|
if( numBytes <= 0 ) return 0;
|
|
|
|
Buffer.BlockCopy( _buffer, _position, buffer, offset, numBytes );
|
|
_position += numBytes;
|
|
return numBytes;
|
|
}
|
|
|
|
public override int ReadByte() {
|
|
if( _position >= _length ) return -1;
|
|
return _buffer[_position++];
|
|
}
|
|
|
|
public override long Seek( long offset, SeekOrigin loc ) {
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void SetLength( long value ) {
|
|
_length = (int)value;
|
|
}
|
|
|
|
public override void Write( byte[] buffer, int offset, int count ) {
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void WriteByte( byte value ) {
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|