public LogRecordStream(Stream inner, bool checksum, BufferPool bufferPool)
		{
			_inner = inner;
			_checksum = checksum;
			_bufferPool = bufferPool;
			_binaryReader = new BinaryReader(inner);
			_buffer = _bufferPool.Take(LogWriter.BlockSize);

			try
			{
				var type = ReadPhysicalRecord();
				switch (type)
				{
					case LogRecordType.FullType:
						_completedRecord = true;
						break;
					case LogRecordType.StartType:
						_inFragmentedRecord = true;
						break;
					case LogRecordType.MiddleType:
					case LogRecordType.EndType:
						throw new CorruptedDataException("missing start of fragmented record(3)");
					default:
						throw new ArgumentOutOfRangeException("Don't know how to handle record type: " + type);
				}
			}
			catch (Exception)
			{
				_bufferPool.Return(_buffer);
				throw;
			}
		}
Exemplo n.º 2
0
		public LogWriter(FileSystem fileSystem, Stream stream, BufferPool bufferPool)
		{
			_isFileSteam = stream is FileStream;
			_fileSystem = fileSystem;
			_bufferPool = bufferPool;
			_buffer = bufferPool.Take(BlockSize);
			_binaryWriter = new BinaryWriter(stream);
			_bufferPos = HeaderSize;

			_lastCompletedRecordStreamLength = 0;
		}
Exemplo n.º 3
0
		public Slice(ref byte[] externalBuffer, Slice other, BufferPool bufferPool)
		{
			if (externalBuffer.Length < other.Count)
			{
				bufferPool.Return(externalBuffer);
				externalBuffer = bufferPool.Take(other.Count);
			}
			_array = externalBuffer;
			_count = other._count;
			_offset = 0;
			Buffer.BlockCopy(other.Array, other.Offset, externalBuffer, 0, other.Count);
		}
		public BufferPoolMemoryStream(BufferPool bufferPool)
		{
			_bufferPool = bufferPool;
			_buffer = _bufferPool.Take(8 * 1024);
		}