Class TarStream
java.lang.Object
opennlp.tools.util.archive.TarStream
A forward-only reader for classic v7, POSIX ustar, GNU, and pax tar streams.
next() advances to the following entry and entryStream() exposes
only the current entry's bytes.
The reader validates header checksums, supports ustar name prefixes, GNU long
names, pax path and size records, and GNU base-256 sizes. Sparse
entries and global pax records that change paths or sizes are rejected because this
reader cannot reproduce their content or global semantics.
- Since:
- 3.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionTarStream(InputStream in) Initializes the reader.TarStream(InputStream in, long maxEntries) Initializes a reader with an archive-entry limit. -
Method Summary
-
Constructor Details
-
TarStream
Initializes the reader.- Parameters:
in- The tar content. Notnull. Not closed by this class.- Throws:
IllegalArgumentException- Thrown ifinisnull.
-
TarStream
Initializes a reader with an archive-entry limit. Extension headers count toward the limit.- Parameters:
in- The tar content. Notnull. Not closed by this class.maxEntries- The maximum number of archive headers to read. Must be positive.- Throws:
IllegalArgumentException- Thrown ifinisnullormaxEntriesis not positive.
-
-
Method Details
-
startsWithHeader
Checks whether the given stream is positioned at a tar entry header, leaving its position unchanged.- Parameters:
in- The stream to inspect. Notnulland must supportmarkandreset.- Returns:
trueif the next 512 bytes read as a tar header,falseif they do not or if fewer than 512 bytes are available.- Throws:
IOException- Thrown if reading from or repositioning the stream fails.IllegalArgumentException- Thrown ifinisnullor does not support mark and reset.
-
next
Advances to the next entry.- Returns:
trueif an entry is available,falseat the end of the archive.- Throws:
IOException- Thrown if the archive is truncated or a header is malformed.
-
name
-
size
public long size()- Returns:
- The current entry's size in bytes.
-
isFile
public boolean isFile()- Returns:
trueif the current entry is a regular file.
-
entryStream
Opens the current entry's content.- Returns:
- A stream over exactly this entry's bytes; reading past the end returns end
of stream, and a zero-length read returns
0asInputStream.read(byte[], int, int)requires. Notnull. Closing it is not required.
-