2 * Copyright 2004 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.
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.
25 /// <seealso cref="Directory">
27 /// <seealso cref="IndexInput">
29 public abstract class IndexOutput
32 /// <summary>Writes a single byte.</summary>
33 /// <seealso cref="IndexInput.ReadByte()">
35 public abstract void WriteByte(byte b
);
37 /// <summary>Writes an array of bytes.</summary>
38 /// <param name="b">the bytes to write
40 /// <param name="length">the number of bytes to write
42 /// <seealso cref="IndexInput.ReadBytes(byte[],int,int)">
44 public abstract void WriteBytes(byte[] b
, int length
);
46 /// <summary>Writes an int as four bytes.</summary>
47 /// <seealso cref="IndexInput.ReadInt()">
49 public virtual void WriteInt(int i
)
51 WriteByte((byte) (i
>> 24));
52 WriteByte((byte) (i
>> 16));
53 WriteByte((byte) (i
>> 8));
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
61 /// <seealso cref="IndexInput.ReadVInt()">
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);
73 /// <summary>Writes a long as eight bytes.</summary>
74 /// <seealso cref="IndexInput.ReadLong()">
76 public virtual void WriteLong(long i
)
78 WriteInt((int) (i
>> 32));
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
86 /// <seealso cref="IndexInput.ReadVLong()">
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.
98 /// <summary>Writes a string.</summary>
99 /// <seealso cref="IndexInput.ReadString()">
101 public virtual void WriteString(System
.String s
)
103 int length
= s
.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
111 /// <param name="start">the first character in the sequence
113 /// <param name="length">the number of characters in the sequence
115 /// <seealso cref="IndexInput.ReadChars(char[],int,int)">
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)));
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
148 /// <seealso cref="Seek(long)">
150 public abstract long GetFilePointer();
152 /// <summary>Sets current position in this file, where the next write will occur.</summary>
153 /// <seealso cref="GetFilePointer()">
155 public abstract void Seek(long pos
);
157 /// <summary>The number of bytes in the file. </summary>
158 public abstract long Length();