Add --enable-deletion option to buildindex. If used, buildindex will remove deleted...
[beagle.git] / beagled / Lucene.Net / Store / BufferedIndexOutput.cs
blob27a27788ab1acc85daa4bd67fdaf90775668f5c1
1 /*
2 * Copyright 2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 using System;
17 namespace Lucene.Net.Store
20 /// <summary>Base implementation class for buffered {@link IndexOutput}. </summary>
21 public abstract class BufferedIndexOutput:IndexOutput
23 internal const int BUFFER_SIZE = 1024;
25 private byte[] buffer = new byte[BUFFER_SIZE];
26 private long bufferStart = 0; // position in file of buffer
27 private int bufferPosition = 0; // position in buffer
29 /// <summary>Writes a single byte.</summary>
30 /// <seealso cref="IndexInput#ReadByte()">
31 /// </seealso>
32 public override void WriteByte(byte b)
34 if (bufferPosition >= BUFFER_SIZE)
35 Flush();
36 buffer[bufferPosition++] = b;
39 /// <summary>Writes an array of bytes.</summary>
40 /// <param name="b">the bytes to write
41 /// </param>
42 /// <param name="length">the number of bytes to write
43 /// </param>
44 /// <seealso cref="IndexInput#ReadBytes(byte[],int,int)">
45 /// </seealso>
46 public override void WriteBytes(byte[] b, int length)
48 for (int i = 0; i < length; i++)
49 WriteByte(b[i]);
52 /// <summary>Forces any buffered output to be written. </summary>
53 public override void Flush()
55 FlushBuffer(buffer, bufferPosition);
56 bufferStart += bufferPosition;
57 bufferPosition = 0;
60 /// <summary>Expert: implements buffer write. Writes bytes at the current position in
61 /// the output.
62 /// </summary>
63 /// <param name="b">the bytes to write
64 /// </param>
65 /// <param name="len">the number of bytes to write
66 /// </param>
67 public abstract void FlushBuffer(byte[] b, int len);
69 /// <summary>Closes this stream to further operations. </summary>
70 public override void Close()
72 Flush();
75 /// <summary>Returns the current position in this file, where the next write will
76 /// occur.
77 /// </summary>
78 /// <seealso cref="#Seek(long)">
79 /// </seealso>
80 public override long GetFilePointer()
82 return bufferStart + bufferPosition;
85 /// <summary>Sets current position in this file, where the next write will occur.</summary>
86 /// <seealso cref="#GetFilePointer()">
87 /// </seealso>
88 public override void Seek(long pos)
90 Flush();
91 bufferStart = pos;
94 /// <summary>The number of bytes in the file. </summary>
95 public abstract override long Length();