20 namespace Lucene.Net.Store
26 internal const int BUFFER_SIZE = 16384;
28 private byte[] buffer =
new byte[BUFFER_SIZE];
29 private long bufferStart = 0;
30 private int bufferPosition = 0;
32 private bool isDisposed;
37 public override void WriteByte(byte b)
39 if (bufferPosition >= BUFFER_SIZE)
41 buffer[bufferPosition++] = b;
51 public override void WriteBytes(byte[] b,
int offset,
int length)
53 int bytesLeft = BUFFER_SIZE - bufferPosition;
55 if (bytesLeft >= length)
58 Array.Copy(b, offset, buffer, bufferPosition, length);
59 bufferPosition += length;
61 if (BUFFER_SIZE - bufferPosition == 0)
67 if (length > BUFFER_SIZE)
70 if (bufferPosition > 0)
73 FlushBuffer(b, offset, length);
74 bufferStart += length;
83 pieceLength = (length - pos < bytesLeft)?length - pos:bytesLeft;
84 Array.Copy(b, pos + offset, buffer, bufferPosition, pieceLength);
86 bufferPosition += pieceLength;
88 bytesLeft = BUFFER_SIZE - bufferPosition;
92 bytesLeft = BUFFER_SIZE;
100 public override void Flush()
102 FlushBuffer(buffer, bufferPosition);
103 bufferStart += bufferPosition;
114 private void FlushBuffer(byte[] b,
int len)
116 FlushBuffer(b, 0, len);
128 public abstract void FlushBuffer(byte[] b,
int offset,
int len);
131 protected override void Dispose(
bool disposing)
133 if (isDisposed)
return;
148 public override long FilePointer
150 get {
return bufferStart + bufferPosition; }
156 public override void Seek(
long pos)
163 public abstract override long Length {
get; }