FileDocCategorySizeDatePackage
IndexOutput.javaAPI DocApache Lucene 2.2.04686Sat Jun 16 22:20:36 BST 2007org.apache.lucene.store

IndexOutput

public abstract class IndexOutput extends Object
Abstract base class for output to a file in a Directory. A random-access output stream. Used for all Lucene index output operations.
see
Directory
see
IndexInput

Fields Summary
Constructors Summary
Methods Summary
public abstract voidclose()
Closes this stream to further operations.

public abstract voidflush()
Forces any buffered output to be written.

public abstract longgetFilePointer()
Returns the current position in this file, where the next write will occur.

see
#seek(long)

public abstract longlength()
The number of bytes in the file.

public abstract voidseek(long pos)
Sets current position in this file, where the next write will occur.

see
#getFilePointer()

public abstract voidwriteByte(byte b)
Writes a single byte.

see
IndexInput#readByte()

public voidwriteBytes(byte[] b, int length)
Writes an array of bytes.

param
b the bytes to write
param
length the number of bytes to write
see
IndexInput#readBytes(byte[],int,int)

    writeBytes(b, 0, length);
  
public abstract voidwriteBytes(byte[] b, int offset, int length)
Writes an array of bytes.

param
b the bytes to write
param
offset the offset in the byte array
param
length the number of bytes to write
see
IndexInput#readBytes(byte[],int,int)

public voidwriteChars(java.lang.String s, int start, int length)
Writes a sequence of UTF-8 encoded characters from a string.

param
s the source of the characters
param
start the first character in the sequence
param
length the number of characters in the sequence
see
IndexInput#readChars(char[],int,int)

    final int end = start + length;
    for (int i = start; i < end; i++) {
      final int code = (int)s.charAt(i);
      if (code >= 0x01 && code <= 0x7F)
	writeByte((byte)code);
      else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0) {
	writeByte((byte)(0xC0 | (code >> 6)));
	writeByte((byte)(0x80 | (code & 0x3F)));
      } else {
	writeByte((byte)(0xE0 | (code >>> 12)));
	writeByte((byte)(0x80 | ((code >> 6) & 0x3F)));
	writeByte((byte)(0x80 | (code & 0x3F)));
      }
    }
  
public voidwriteInt(int i)
Writes an int as four bytes.

see
IndexInput#readInt()

    writeByte((byte)(i >> 24));
    writeByte((byte)(i >> 16));
    writeByte((byte)(i >>  8));
    writeByte((byte) i);
  
public voidwriteLong(long i)
Writes a long as eight bytes.

see
IndexInput#readLong()

    writeInt((int) (i >> 32));
    writeInt((int) i);
  
public voidwriteString(java.lang.String s)
Writes a string.

see
IndexInput#readString()

    int length = s.length();
    writeVInt(length);
    writeChars(s, 0, length);
  
public voidwriteVInt(int i)
Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers are not supported.

see
IndexInput#readVInt()

    while ((i & ~0x7F) != 0) {
      writeByte((byte)((i & 0x7f) | 0x80));
      i >>>= 7;
    }
    writeByte((byte)i);
  
public voidwriteVLong(long i)
Writes an long in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers are not supported.

see
IndexInput#readVLong()

    while ((i & ~0x7F) != 0) {
      writeByte((byte)((i & 0x7f) | 0x80));
      i >>>= 7;
    }
    writeByte((byte)i);