Class 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.
Inheritance
Inherited Members
Namespace: Lucene.Net.Codecs
Assembly: Lucene.Net.dll
Syntax
public static class CodecUtil
Fields
| Improve this Doc View SourceCODEC_MAGIC
Constant to identify the start of a codec header.
Declaration
public static readonly int CODEC_MAGIC
Field Value
Type | Description |
---|---|
System. |
FOOTER_MAGIC
Constant to identify the start of a codec footer.
Declaration
public static readonly int FOOTER_MAGIC
Field Value
Type | Description |
---|---|
System. |
Methods
| Improve this Doc View SourceCheckEOF(IndexInput)
Checks that the stream is positioned at the end, and throws exception if it is not.
Declaration
[Obsolete("Use CheckFooter(ChecksumIndexInput) instead, this should only used for files without checksums.")]
public static void CheckEOF(IndexInput in)
Parameters
Type | Name | Description |
---|---|---|
Index |
in |
CheckFooter(ChecksumIndexInput)
Validates the codec footer previously written by Write
Declaration
public static long CheckFooter(ChecksumIndexInput in)
Parameters
Type | Name | Description |
---|---|---|
Checksum |
in |
Returns
Type | Description |
---|---|
System. |
Actual checksum value. |
Exceptions
Type | Condition |
---|---|
System. |
If the footer is invalid, if the checksum does not match,
or if |
CheckHeader(DataInput, String, Int32, Int32)
Reads and validates a header previously written with
Write
When reading a file, supply the expected codec
and
an expected version range (minVersion
to maxVersion
).
Declaration
public static int CheckHeader(DataInput in, string codec, int minVersion, int maxVersion)
Parameters
Type | Name | Description |
---|---|---|
Data |
in | Input stream, positioned at the point where the header was previously written. Typically this is located at the beginning of the file. |
System. |
codec | The expected codec name. |
System. |
minVersion | The minimum supported expected version number. |
System. |
maxVersion | The maximum supported expected version number. |
Returns
Type | Description |
---|---|
System. |
The actual version found, when a valid header is found
that matches |
Exceptions
Type | Condition |
---|---|
Corrupt |
If the first four bytes are not
CODEC_MAGIC, or if the actual codec found is
not |
Index |
If the actual version is less
than |
Index |
If the actual version is greater
than |
System. |
If there is an I/O error reading from the underlying medium. |
See Also
| Improve this Doc View SourceCheckHeaderNoMagic(DataInput, String, Int32, Int32)
Like
Check
Declaration
public static int CheckHeaderNoMagic(DataInput in, string codec, int minVersion, int maxVersion)
Parameters
Type | Name | Description |
---|---|---|
Data |
in | |
System. |
codec | |
System. |
minVersion | |
System. |
maxVersion |
Returns
Type | Description |
---|---|
System. |
ChecksumEntireFile(IndexInput)
Clones the provided input, reads all bytes from the file, and calls Check
Note that this method may be slow, as it must process the entire file.
If you just need to extract the checksum value, call Retrieve
Declaration
public static long ChecksumEntireFile(IndexInput input)
Parameters
Type | Name | Description |
---|---|---|
Index |
input |
Returns
Type | Description |
---|---|
System. |
FooterLength()
Computes the length of a codec footer.
Declaration
public static int FooterLength()
Returns
Type | Description |
---|---|
System. |
Length of the entire codec footer. |
See Also
| Improve this Doc View SourceHeaderLength(String)
Computes the length of a codec header.
Declaration
public static int HeaderLength(string codec)
Parameters
Type | Name | Description |
---|---|---|
System. |
codec | Codec name. |
Returns
Type | Description |
---|---|
System. |
Length of the entire codec header. |
See Also
| Improve this Doc View SourceRetrieveChecksum(IndexInput)
Returns (but does not validate) the checksum previously written by Check
Declaration
public static long RetrieveChecksum(IndexInput in)
Parameters
Type | Name | Description |
---|---|---|
Index |
in |
Returns
Type | Description |
---|---|
System. |
actual checksum value |
Exceptions
Type | Condition |
---|---|
System. |
If the footer is invalid. |
WriteFooter(IndexOutput)
Writes a codec footer, which records both a checksum
algorithm ID and a checksum. This footer can
be parsed and validated with
Check
CodecFooter --> Magic,AlgorithmID,Checksum
- Magic --> Uint32 (Write
Int32(Int32) ). this identifies the start of the footer. It is always FOOTER_MAGIC. - AlgorithmID --> Uint32 (Write
Int32(Int32) ). this indicates the checksum algorithm used. Currently this is always 0, for zlib-crc32. - Checksum --> Uint32 (Write
Int64(Int64) ). The actual checksum value for all previous bytes in the stream, including the bytes from Magic and AlgorithmID.
Declaration
public static void WriteFooter(IndexOutput out)
Parameters
Type | Name | Description |
---|---|---|
Index |
out | Output stream |
Exceptions
Type | Condition |
---|---|
System. |
If there is an I/O error writing to the underlying medium. |
WriteHeader(DataOutput, String, Int32)
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
Check
CodecHeader --> Magic,CodecName,Version
- Magic --> Uint32 (Write
Int32(Int32) ). this identifies the start of the header. It is always CODEC_MAGIC. - CodecName --> String (Write
String(String) ). this is a string to identify this file. - Version --> Uint32 (Write
Int32(Int32) ). Records the version of the file.
Note that the length of a codec header depends only upon the
name of the codec, so this length can be computed at any time
with Header
Declaration
public static void WriteHeader(DataOutput out, string codec, int version)
Parameters
Type | Name | Description |
---|---|---|
Data |
out | Output stream |
System. |
codec | String to identify this file. It should be simple ASCII, less than 128 characters in length. |
System. |
version | Version number |
Exceptions
Type | Condition |
---|---|
System. |
If there is an I/O error writing to the underlying medium. |