Package nl.knaw.dans.bagit.reader
Class BagitTextFileReader
java.lang.Object
nl.knaw.dans.bagit.reader.BagitTextFileReader
This class is responsible for reading and parsing bagit.txt files from the filesystem
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final byte[]
private static final String
private static final String
private static final org.slf4j.Logger
private static final ResourceBundle
private static final Version
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Version
parseVersion
(String version) readBagitTextFile
(Path bagitFile) Read the bagit.txt file and return the version and encoding.private static void
throwErrorIfByteOrderMarkIsPresent
(Path bagitFile) (package private) static void
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
BOM
private static final byte[] BOM -
messages
-
VERSION_1_0
-
LINE1_REGEX
- See Also:
-
LINE2_REGEX
- See Also:
-
-
Constructor Details
-
BagitTextFileReader
private BagitTextFileReader()
-
-
Method Details
-
readBagitTextFile
public static AbstractMap.SimpleImmutableEntry<Version,Charset> readBagitTextFile(Path bagitFile) throws IOException, UnparsableVersionException, InvalidBagMetadataException, InvalidBagitFileFormatException Read the bagit.txt file and return the version and encoding.- Parameters:
bagitFile
- the bagit.txt file- Returns:
- the bag
Version
andCharset
encoding of the tag files - Throws:
IOException
- if there is a problem reading a file. The file MUST be in UTF-8 encoding.UnparsableVersionException
- if there is a problem parsing the bagit version numberInvalidBagMetadataException
- if the bagit.txt file does not conform to "key: value"InvalidBagitFileFormatException
- if the bagit.txt file does not conform to the bagit spec
-
throwErrorIfByteOrderMarkIsPresent
private static void throwErrorIfByteOrderMarkIsPresent(Path bagitFile) throws IOException, InvalidBagitFileFormatException -
throwErrorIfLinesDoNotMatchStrict
static void throwErrorIfLinesDoNotMatchStrict(List<String> lines) throws InvalidBagitFileFormatException - Throws:
InvalidBagitFileFormatException
-
parseVersion
- Throws:
UnparsableVersionException
-