Top Fields Constructors Methods
de.siegmar.fastcsv.reader

pack-priv final Class BomUtil

extends Object
Class Inheritance
Annotations
@SuppressWarnings:checkstyle:MagicNumber
Imports
java.io.IOException, java.nio.file.Files, .Path, .StandardOpenOption, java.util.Optional

Field Summary

Modifier and TypeField and Description
pack-priv static final int
POTENTIAL_BOM_SIZE

The maximum number of bytes a BOM header can have.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static Optional<BomHeader>

Returns:

an Optional containing the detected BomHeader if a BOM header is found, or an empty Optional if no BOM header is found
detectCharset
(final byte[]
the byte array to detect the character encoding from
buf
)

Detects the character encoding of a byte array based on the presence of a Byte Order Mark (BOM) header.

pack-priv static Optional<BomHeader>

Returns:

an Optional containing the detected BomHeader if a BOM header is found, or Optional#EMPTY if no BOM header is found
detectCharset
(final Path
the file to detect the character encoding from
file
)

Detects the character encoding of a file based on the presence of a Byte Order Mark (BOM) header.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

POTENTIAL_BOM_SIZEback to summary
pack-priv static final int POTENTIAL_BOM_SIZE

The maximum number of bytes a BOM header can have.

Constructor Detail

BomUtilback to summary
private BomUtil()

Method Detail

detectCharsetback to summary
pack-priv static Optional<BomHeader> detectCharset(final byte[] buf)

Detects the character encoding of a byte array based on the presence of a Byte Order Mark (BOM) header. The method supports the following BOM headers:

Encoding BOM
UTF-8 EF BB BF
UTF-16 BE FE FF
UTF-16 LE FF FE
UTF-32 BE 00 00 FE FF
UTF-32 LE FF FE 00 00

See Byte order mark.

Parameters
buf:byte[]

the byte array to detect the character encoding from

Returns:Optional<BomHeader>

an Optional containing the detected BomHeader if a BOM header is found, or an empty Optional if no BOM header is found

Annotations
@SuppressWarnings:checkstyle:CyclomaticComplexity, checkstyle:BooleanExpressionComplexity, checkstyle:NestedIfDepth, checkstyle:ReturnCount, PMD.AvoidLiteralsInIfCondition
detectCharsetback to summary
pack-priv static Optional<BomHeader> detectCharset(final Path file) throws IOException

Detects the character encoding of a file based on the presence of a Byte Order Mark (BOM) header.

Parameters
file:Path

the file to detect the character encoding from

Returns:Optional<BomHeader>

an Optional containing the detected BomHeader if a BOM header is found, or Optional#EMPTY if no BOM header is found

Exceptions
IOException:
if an I/O error occurs reading the file