2 * Copyright 2005 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 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.
23 /// <seealso cref="Directory">
25 /// <seealso cref="IndexInput">
27 public abstract class IndexOutput
30 /// <summary>Writes a single byte.</summary>
31 /// <seealso cref="IndexInput#ReadByte()">
33 public abstract void WriteByte(byte b
);
35 /// <summary>Writes an array of bytes.</summary>
36 /// <param name="b">the bytes to write
38 /// <param name="length">the number of bytes to write
40 /// <seealso cref="IndexInput#ReadBytes(byte[],int,int)">
42 public abstract void WriteBytes(byte[] b
, int length
);
44 /// <summary>Writes an int as four bytes.</summary>
45 /// <seealso cref="IndexInput#ReadInt()">
47 public virtual void WriteInt(int i
)
49 WriteByte((byte) (i
>> 24));
50 WriteByte((byte) (i
>> 16));
51 WriteByte((byte) (i
>> 8));
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
59 /// <seealso cref="IndexInput#ReadVInt()">
61 public virtual void WriteVInt(int i
)
63 while ((i
& ~
0x7F) != 0)
65 WriteByte((byte) ((i
& 0x7f) | 0x80));
66 i
= (int) (((uint) i
) >> 7);
71 /// <summary>Writes a long as eight bytes.</summary>
72 /// <seealso cref="IndexInput#ReadLong()">
74 public virtual void WriteLong(long i
)
76 WriteInt((int) (i
>> 32));
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
84 /// <seealso cref="IndexInput#ReadVLong()">
86 public virtual void WriteVLong(long i
)
88 while ((i
& ~
0x7F) != 0)
90 WriteByte((byte) ((i
& 0x7f) | 0x80));
91 i
= (int) (((uint) i
) >> 7);
96 /// <summary>Writes a string.</summary>
97 /// <seealso cref="IndexInput#ReadString()">
99 public virtual void WriteString(System
.String s
)
101 int length
= s
.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
109 /// <param name="start">the first character in the sequence
111 /// <param name="length">the number of characters in the sequence
113 /// <seealso cref="IndexInput#ReadChars(char[],int,int)">
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)));
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
146 /// <seealso cref="#Seek(long)">
148 public abstract long GetFilePointer();
150 /// <summary>Sets current position in this file, where the next write will occur.</summary>
151 /// <seealso cref="#GetFilePointer()">
153 public abstract void Seek(long pos
);
155 /// <summary>The number of bytes in the file. </summary>
156 public abstract long Length();