Package org.apache.lucene.store

## Class IndexOutput

- java.lang.Object
- - org.apache.lucene.store.DataOutput
  - - org.apache.lucene.store.IndexOutput

- All Implemented Interfaces:
    `Closeable`, `AutoCloseable`
  Direct Known Subclasses:
    `ByteBuffersIndexOutput`, `FilterIndexOutput`, `OutputStreamIndexOutput`

      public abstract class IndexOutput
      extends DataOutput
      implements Closeable

  A `DataOutput` for appending data to a file in a `Directory`.

  Instances of this class are not thread-safe.

  See Also:
    `Directory`, `IndexInput`

- - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `IndexOutput​(String resourceDescription, String name)` | Sole constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `long` | `alignFilePointer​(int alignmentBytes)` | Aligns the current file pointer to multiples of `alignmentBytes` bytes to improve reads with mmap.
    `static long` | `alignOffset​(long offset, int alignmentBytes)` | Aligns the given `offset` to multiples of `alignmentBytes` bytes by rounding up.
    `abstract void` | `close()` | Closes this stream to further operations.
    `abstract long` | `getChecksum()` | Returns the current checksum of bytes written so far
    `abstract long` | `getFilePointer()` | Returns the current position in this file, where the next write will occur.
    `String` | `getName()` | Returns the name used to create this `IndexOutput`.
    `String` | `toString()` |

    - ### Methods inherited from class org.apache.lucene.store.DataOutput

      `copyBytes, writeByte, writeBytes, writeBytes, writeGroupVInts, writeInt, writeLong, writeMapOfStrings, writeSetOfStrings, writeShort, writeString, writeVInt, writeVLong, writeZInt, writeZLong`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### IndexOutput

          protected IndexOutput​(String resourceDescription,
                                String name)

      Sole constructor. resourceDescription should be non-null, opaque string describing this resource; it's returned from `toString()`.

  - ### Method Detail

    - #### getName

          public String getName()

      Returns the name used to create this `IndexOutput`. This is especially useful when using `Directory.createTempOutput(java.lang.String, java.lang.String, org.apache.lucene.store.IOContext)`.

    - #### close

          public abstract void close()
                              throws IOException

      Closes this stream to further operations.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Closeable`
      Throws:
        `IOException`

    - #### getFilePointer

          public abstract long getFilePointer()

      Returns the current position in this file, where the next write will occur.

    - #### getChecksum

          public abstract long getChecksum()
                                    throws IOException

      Returns the current checksum of bytes written so far
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### alignFilePointer

          public final long alignFilePointer​(int alignmentBytes)
                                      throws IOException

      Aligns the current file pointer to multiples of `alignmentBytes` bytes to improve reads with mmap. This will write between 0 and `(alignmentBytes-1)` zero bytes using `DataOutput.writeByte(byte)`.
      Parameters:
        `alignmentBytes` - the alignment to which it should forward file pointer (must be a power of 2)
      Returns:
        the new file pointer after alignment
      Throws:
        `IOException`
      See Also:
        `alignOffset(long, int)`

    - #### alignOffset

          public static final long alignOffset​(long offset,
                                               int alignmentBytes)

      Aligns the given `offset` to multiples of `alignmentBytes` bytes by rounding up. The alignment must be a power of 2.