本文整理汇总了C#中ChunkedMemoryStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# ChunkedMemoryStream.Seek方法的具体用法?C# ChunkedMemoryStream.Seek怎么用?C# ChunkedMemoryStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChunkedMemoryStream
的用法示例。
在下文中一共展示了ChunkedMemoryStream.Seek方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSeekInternalStateNotChanged1
public void TestSeekInternalStateNotChanged1()
{
using (var stream = new ChunkedMemoryStream()) {
Assert.AreEqual(0L, stream.Position);
Assert.AreEqual(0L, stream.Length);
Assert.AreEqual(0L, stream.Seek(0L, SeekOrigin.Begin));
Assert.AreEqual(0L, stream.Length);
stream.Write(new byte[] {0x00, 0x01, 0x02, 0x03}, 0, 4);
Assert.AreEqual(4L, stream.Position);
Assert.AreEqual(4L, stream.Length);
}
}
示例2: TestSeekEnd
public void TestSeekEnd()
{
using (var stream = new ChunkedMemoryStream(8)) {
for (var i = 0; i < 0x20; i++) {
stream.WriteByte((byte)i);
}
Assert.AreEqual(0x00, stream.Seek(-0x20, SeekOrigin.End));
Assert.AreEqual(0x00, stream.ReadByte());
Assert.AreEqual(0x18, stream.Seek(-0x08, SeekOrigin.End));
Assert.AreEqual(0x18, stream.ReadByte());
Assert.AreEqual(0x0f, stream.Seek(-0x11, SeekOrigin.End));
Assert.AreEqual(0x0f, stream.ReadByte());
Assert.AreEqual(0x40, stream.Seek(+0x20, SeekOrigin.End));
try {
stream.Seek(-0x41, SeekOrigin.End);
Assert.Fail("IOException not thrown");
}
catch (IOException) {
}
}
}
示例3: TestSeekAndReadRandom
public void TestSeekAndReadRandom()
{
using (var stream = new ChunkedMemoryStream(8)) {
for (var i = 0; i < 12; i++) {
stream.WriteByte((byte)i);
}
Assert.IsTrue(stream.CanSeek);
Assert.AreEqual(12L, stream.Position);
Assert.AreEqual(12L, stream.Length);
Assert.AreEqual(6L, stream.Seek(6L, SeekOrigin.Begin));
Assert.AreEqual(6L, stream.Position);
var pair = new long[][] {
// offset / position
new long[] { 0, 6},
new long[] {-2, 5},
new long[] { 1, 7},
new long[] {-4, 4},
new long[] { 3, 8},
new long[] {-6, 3},
new long[] { 5, 9},
new long[] {-8, 2},
new long[] { 7,10},
new long[] {-10, 1},
new long[] { 9,11},
};
for (var index = 0; index < pair.Length; index++) {
try {
Assert.AreEqual(pair[index][1], stream.Seek(pair[index][0], SeekOrigin.Current), "seeked position {0}", index);
}
catch (IOException) {
Assert.Fail("IOException thrown while seeking ({0})", index);
}
Assert.AreEqual(pair[index][1], stream.Position);
Assert.AreEqual(pair[index][1], stream.ReadByte(), "read value {0}", index);
Assert.AreEqual(pair[index][1] + 1, stream.Position);
}
Assert.AreEqual(-1, stream.ReadByte());
Assert.AreEqual(13, stream.Seek(1, SeekOrigin.Current));
Assert.AreEqual(-1, stream.ReadByte());
Assert.AreEqual(13, stream.Position);
}
}
示例4: TestReadByte
public void TestReadByte()
{
using (var stream = new ChunkedMemoryStream(8)) {
for (var i = 0; i < 32; i++) {
stream.WriteByte((byte)i);
}
Assert.AreEqual(0L, stream.Seek(0L, SeekOrigin.Begin));
Assert.AreEqual(0L, stream.Position);
Assert.AreEqual(32L, stream.Length);
for (var i = 0; i < 32; i++) {
Assert.AreEqual((long)i, stream.Position);
Assert.AreEqual(i, stream.ReadByte());
Assert.AreEqual((long)i + 1, stream.Position);
}
Assert.AreEqual(-1, stream.ReadByte());
}
}
示例5: TestRead
public void TestRead()
{
using (var stream = new ChunkedMemoryStream(8)) {
for (var i = 0; i < 32; i++) {
stream.WriteByte((byte)i);
}
Assert.AreEqual(0L, stream.Seek(0, SeekOrigin.Begin));
var buffer = new byte[16];
Assert.AreEqual(1, stream.Read(buffer, 0, 1));
Assert.AreEqual(new byte[] {0x00}, buffer.Slice(0, 1));
Assert.AreEqual(1L, stream.Position);
Assert.AreEqual(3, stream.Read(buffer, 0, 3));
Assert.AreEqual(new byte[] {0x01, 0x02, 0x03}, buffer.Slice(0, 3));
Assert.AreEqual(4L, stream.Position);
Assert.AreEqual(4, stream.Read(buffer, 0, 4));
Assert.AreEqual(new byte[] {0x04, 0x05, 0x06, 0x07}, buffer.Slice(0, 4));
Assert.AreEqual(8L, stream.Position);
Assert.AreEqual(7, stream.Read(buffer, 0, 7));
Assert.AreEqual(new byte[] {0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e}, buffer.Slice(0, 7));
Assert.AreEqual(15L, stream.Position);
Assert.AreEqual(2, stream.Read(buffer, 0, 2));
Assert.AreEqual(new byte[] {0x0f, 0x10}, buffer.Slice(0, 2));
Assert.AreEqual(17L, stream.Position);
Assert.AreEqual(15, stream.Read(buffer, 0, 16));
Assert.AreEqual(new byte[] {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, buffer.Slice(0, 15));
Assert.AreEqual(32L, stream.Position);
}
}
示例6: ReadNextRecord
/// <summary>
/// Read the next unread record from the stream. Will return <see cref="QueueStreamRecord.Empty"/> if there is no next record in the stream.
/// </summary>
/// <returns></returns>
public QueueStreamRecord ReadNextRecord()
{
EnsureInstanceNotDisposed();
if(_recordQueue.Count == 0) {
return QueueStreamRecord.Empty;
}
var next = _recordQueue.Dequeue();
var streamInfo = GetStreamInfoFromHandle(next);
if(streamInfo == null) {
EnsureInstanceNotDisposed();
throw new InvalidOperationException("unable to access stream for head file");
}
streamInfo.Stream.Seek(next.Position + HEADER_SIZE, SeekOrigin.Begin);
var data = new ChunkedMemoryStream();
var copied = streamInfo.Stream.CopyTo(data, next.Length);
if(copied != next.Length) {
_log.WarnFormat("reached EOF in the middle of the record");
return QueueStreamRecord.Empty;
}
data.Seek(0, SeekOrigin.Begin);
return new QueueStreamRecord(data, next);
}