Add --enable-deletion option to buildindex. If used, buildindex will remove deleted...
[beagle.git] / beagled / Lucene.Net / Store / IndexOutput.cs
blob9a6d5183f037d6e90a4885335bac1e51a305b608
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>Abstract base class for output to a file in a Directory. A random-access
21 /// output stream. Used for all Lucene index output operations.
22 /// </summary>
23 /// <seealso cref="Directory">
24 /// </seealso>
25 /// <seealso cref="IndexInput">
26 /// </seealso>
27 public abstract class IndexOutput
30 /// <summary>Writes a single byte.</summary>
31 /// <seealso cref="IndexInput#ReadByte()">
32 /// </seealso>
33 public abstract void WriteByte(byte b);
35 /// <summary>Writes an array of bytes.</summary>
36 /// <param name="b">the bytes to write
37 /// </param>
38 /// <param name="length">the number of bytes to write
39 /// </param>
40 /// <seealso cref="IndexInput#ReadBytes(byte[],int,int)">
41 /// </seealso>
42 public abstract void WriteBytes(byte[] b, int length);
44 /// <summary>Writes an int as four bytes.</summary>
45 /// <seealso cref="IndexInput#ReadInt()">
46 /// </seealso>
47 public virtual void WriteInt(int i)
49 WriteByte((byte) (i >> 24));
50 WriteByte((byte) (i >> 16));
51 WriteByte((byte) (i >> 8));
52 WriteByte((byte) i);
55 /// <summary>Writes an int in a variable-length format. Writes between one and
56 /// five bytes. Smaller values take fewer bytes. Negative numbers are not
57 /// supported.
58 /// </summary>
59 /// <seealso cref="IndexInput#ReadVInt()">
60 /// </seealso>
61 public virtual void WriteVInt(int i)
63 while ((i & ~ 0x7F) != 0)
65 WriteByte((byte) ((i & 0x7f) | 0x80));
66 i = (int) (((uint) i) >> 7);
68 WriteByte((byte) i);
71 /// <summary>Writes a long as eight bytes.</summary>
72 /// <seealso cref="IndexInput#ReadLong()">
73 /// </seealso>
74 public virtual void WriteLong(long i)
76 WriteInt((int) (i >> 32));
77 WriteInt((int) i);
80 /// <summary>Writes an long in a variable-length format. Writes between one and five
81 /// bytes. Smaller values take fewer bytes. Negative numbers are not
82 /// supported.
83 /// </summary>
84 /// <seealso cref="IndexInput#ReadVLong()">
85 /// </seealso>
86 public virtual void WriteVLong(long i)
88 while ((i & ~ 0x7F) != 0)
90 WriteByte((byte) ((i & 0x7f) | 0x80));
91 i = (int) (((uint) i) >> 7);
93 WriteByte((byte) i);
96 /// <summary>Writes a string.</summary>
97 /// <seealso cref="IndexInput#ReadString()">
98 /// </seealso>
99 public virtual void WriteString(System.String s)
101 int length = s.Length;
102 WriteVInt(length);
103 WriteChars(s, 0, length);
106 /// <summary>Writes a sequence of UTF-8 encoded characters from a string.</summary>
107 /// <param name="s">the source of the characters
108 /// </param>
109 /// <param name="start">the first character in the sequence
110 /// </param>
111 /// <param name="length">the number of characters in the sequence
112 /// </param>
113 /// <seealso cref="IndexInput#ReadChars(char[],int,int)">
114 /// </seealso>
115 public virtual void WriteChars(System.String s, int start, int length)
117 int end = start + length;
118 for (int i = start; i < end; i++)
120 int code = (int) s[i];
121 if (code >= 0x01 && code <= 0x7F)
122 WriteByte((byte) code);
123 else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0)
125 WriteByte((byte) (0xC0 | (code >> 6)));
126 WriteByte((byte) (0x80 | (code & 0x3F)));
128 else
130 WriteByte((byte) (0xE0 | ((int) (((uint) code) >> 12))));
131 WriteByte((byte) (0x80 | ((code >> 6) & 0x3F)));
132 WriteByte((byte) (0x80 | (code & 0x3F)));
137 /// <summary>Forces any buffered output to be written. </summary>
138 public abstract void Flush();
140 /// <summary>Closes this stream to further operations. </summary>
141 public abstract void Close();
143 /// <summary>Returns the current position in this file, where the next write will
144 /// occur.
145 /// </summary>
146 /// <seealso cref="#Seek(long)">
147 /// </seealso>
148 public abstract long GetFilePointer();
150 /// <summary>Sets current position in this file, where the next write will occur.</summary>
151 /// <seealso cref="#GetFilePointer()">
152 /// </seealso>
153 public abstract void Seek(long pos);
155 /// <summary>The number of bytes in the file. </summary>
156 public abstract long Length();