CodecUtil

object CodecUtil

Utility class for reading and writing versioned headers.

Writing codec headers is useful to ensure that a file is in the format you think it is.

Properties

Link copied to clipboard
const val CODEC_MAGIC: Int = 1071082519

Constant to identify the start of a codec header.

Link copied to clipboard
const val FOOTER_MAGIC: Int

Constant to identify the start of a codec footer.

Functions

Link copied to clipboard

Validates the codec footer previously written by .writeFooter.

fun checkFooter(in: ChecksumIndexInput, priorException: Throwable?)

Validates the codec footer previously written by .writeFooter, optionally passing an unexpected exception that has already occurred.

Link copied to clipboard
fun checkHeader(in: DataInput, codec: String?, minVersion: Int, maxVersion: Int): Int

Reads and validates a header previously written with .writeHeader.

Link copied to clipboard
fun checkHeaderNoMagic(in: DataInput, codec: String?, minVersion: Int, maxVersion: Int): Int

Like .checkHeader except this version assumes the first int has already been read and validated from the input.

Link copied to clipboard
fun checkIndexHeader(in: DataInput, codec: String?, minVersion: Int, maxVersion: Int, expectedID: ByteArray?, expectedSuffix: String?): Int

Reads and validates a header previously written with .writeIndexHeader.

Link copied to clipboard

Expert: just reads and verifies the object ID of an index header

Link copied to clipboard
fun checkIndexHeaderSuffix(in: DataInput, expectedSuffix: String?): String

Expert: just reads and verifies the suffix of an index header

Link copied to clipboard

Clones the provided input, reads all bytes from the file, and calls .checkFooter

Link copied to clipboard

Computes the length of a codec footer.

Link copied to clipboard
fun headerLength(codec: String): Int

Computes the length of a codec header.

Link copied to clipboard
fun indexHeaderLength(codec: String, suffix: String): Int

Computes the length of an index header.

Link copied to clipboard

read int value from header / footer with big endian order

Link copied to clipboard

read long value from header / footer with big endian order

Link copied to clipboard
fun readCRC(input: IndexInput): Long

Reads CRC32 value as a 64-bit long from the input.

Link copied to clipboard

Retrieves the full footer from the provided IndexInput. This throws [ ] if this file does not have a valid footer.

Link copied to clipboard

Retrieves the full index header from the provided IndexInput. This throws [ ] if this file does not appear to be an index file.

Link copied to clipboard
fun retrieveChecksum(in: IndexInput, expectedLength: Long): Long

Returns (but does not validate) the checksum previously written by .checkFooter.

Link copied to clipboard

Expert: verifies the incoming IndexInput has an index header and that its segment ID matches the expected one, and then copies that index header into the provided [ ]. This is useful when building compound files.

Link copied to clipboard
fun writeBEInt(out: DataOutput, i: Int)

write int value on header / footer with big endian order

Link copied to clipboard

write long value on header / footer with big endian order

Link copied to clipboard
fun writeCRC(output: IndexOutput)

Writes CRC32 value as a 64-bit long to the output.

Link copied to clipboard

Writes a codec footer, which records both a checksum algorithm ID and a checksum. This footer can be parsed and validated with .checkFooter.

Link copied to clipboard
fun writeHeader(out: DataOutput, codec: String, version: Int)

Writes a codec header, which records both a string to identify the file and a version number. This header can be parsed and validated with .checkHeader.

Link copied to clipboard
fun writeIndexHeader(out: DataOutput, codec: String, version: Int, id: ByteArray, suffix: String)

Writes a codec header for an index file, which records both a string to identify the format of the file, a version number, and data to identify the file instance (ID and auxiliary suffix such as generation).