cvsimport
[beagle.git] / beagled / Lucene.Net / Store / IndexOutput.cs
blobbb4907d8409c13e9f9ba8771c0dc55c781ede321
1 /*
2 * Copyright 2004 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.
17 using System;
19 namespace Lucene.Net.Store
22 /// <summary>Abstract base class for output to a file in a Directory. A random-access
23 /// output stream. Used for all Lucene index output operations.
24 /// </summary>
25 /// <seealso cref="Directory">
26 /// </seealso>
27 /// <seealso cref="IndexInput">
28 /// </seealso>
29 public abstract class IndexOutput
32 /// <summary>Writes a single byte.</summary>
33 /// <seealso cref="IndexInput.ReadByte()">
34 /// </seealso>
35 public abstract void WriteByte(byte b);
37 /// <summary>Writes an array of bytes.</summary>
38 /// <param name="b">the bytes to write
39 /// </param>
40 /// <param name="length">the number of bytes to write
41 /// </param>
42 /// <seealso cref="IndexInput.ReadBytes(byte[],int,int)">
43 /// </seealso>
44 public abstract void WriteBytes(byte[] b, int length);
46 /// <summary>Writes an int as four bytes.</summary>
47 /// <seealso cref="IndexInput.ReadInt()">
48 /// </seealso>
49 public virtual void WriteInt(int i)
51 WriteByte((byte) (i >> 24));
52 WriteByte((byte) (i >> 16));
53 WriteByte((byte) (i >> 8));
54 WriteByte((byte) i);
57 /// <summary>Writes an int in a variable-length format. Writes between one and
58 /// five bytes. Smaller values take fewer bytes. Negative numbers are not
59 /// supported.
60 /// </summary>
61 /// <seealso cref="IndexInput.ReadVInt()">
62 /// </seealso>
63 public virtual void WriteVInt(int i)
65 while ((i & ~ 0x7F) != 0)
67 WriteByte((byte) ((i & 0x7f) | 0x80));
68 i = SupportClass.Number.URShift(i, 7);
70 WriteByte((byte) i);
73 /// <summary>Writes a long as eight bytes.</summary>
74 /// <seealso cref="IndexInput.ReadLong()">
75 /// </seealso>
76 public virtual void WriteLong(long i)
78 WriteInt((int) (i >> 32));
79 WriteInt((int) i);
82 /// <summary>Writes an long in a variable-length format. Writes between one and five
83 /// bytes. Smaller values take fewer bytes. Negative numbers are not
84 /// supported.
85 /// </summary>
86 /// <seealso cref="IndexInput.ReadVLong()">
87 /// </seealso>
88 public virtual void WriteVLong(long i)
90 while ((i & ~ 0x7F) != 0)
92 WriteByte((byte) ((i & 0x7f) | 0x80));
93 i = (int) (((uint) i) >> 7); // {{Aroush-1.9}} Is this OK?! long to uint, to int conversion.
95 WriteByte((byte) i);
98 /// <summary>Writes a string.</summary>
99 /// <seealso cref="IndexInput.ReadString()">
100 /// </seealso>
101 public virtual void WriteString(System.String s)
103 int length = s.Length;
104 WriteVInt(length);
105 WriteChars(s, 0, length);
108 /// <summary>Writes a sequence of UTF-8 encoded characters from a string.</summary>
109 /// <param name="s">the source of the characters
110 /// </param>
111 /// <param name="start">the first character in the sequence
112 /// </param>
113 /// <param name="length">the number of characters in the sequence
114 /// </param>
115 /// <seealso cref="IndexInput.ReadChars(char[],int,int)">
116 /// </seealso>
117 public virtual void WriteChars(System.String s, int start, int length)
119 int end = start + length;
120 for (int i = start; i < end; i++)
122 int code = (int) s[i];
123 if (code >= 0x01 && code <= 0x7F)
124 WriteByte((byte) code);
125 else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0)
127 WriteByte((byte) (0xC0 | (code >> 6)));
128 WriteByte((byte) (0x80 | (code & 0x3F)));
130 else
132 WriteByte((byte) (0xE0 | (SupportClass.Number.URShift(code, 12))));
133 WriteByte((byte) (0x80 | ((code >> 6) & 0x3F)));
134 WriteByte((byte) (0x80 | (code & 0x3F)));
139 /// <summary>Forces any buffered output to be written. </summary>
140 public abstract void Flush();
142 /// <summary>Closes this stream to further operations. </summary>
143 public abstract void Close();
145 /// <summary>Returns the current position in this file, where the next write will
146 /// occur.
147 /// </summary>
148 /// <seealso cref="Seek(long)">
149 /// </seealso>
150 public abstract long GetFilePointer();
152 /// <summary>Sets current position in this file, where the next write will occur.</summary>
153 /// <seealso cref="GetFilePointer()">
154 /// </seealso>
155 public abstract void Seek(long pos);
157 /// <summary>The number of bytes in the file. </summary>
158 public abstract long Length();