Class TapeArchiveInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Implementation Notes
To better support unbuffered streams, this API is not random access. (That
is, once an entry's header has been read, the content must be read by calling
writeCurrentEntryTo(OutputStream) or skipped by calling
getNextEntry()).
closeCurrentEntry() is a no-op. Close entries by calling
getNextEntry() or close the stream by calling close(),
instead.
-
Field Summary
Fields inherited from class xyz.apollosoftware.bibliothiki.compression.ArchiveInputStream
stream -
Constructor Summary
ConstructorsConstructorDescriptionTapeArchiveInputStream(@NonNull InputStream stream) Construct aTapeArchiveInputStreamthat encapsulates the givenInputStream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidClose the current entry.@Nullable ArchiveEntryGet the next entry in the archive.static booleanisGzipStream(@NonNull InputStream stream) Peek the first two bytes of the stream to see if they match the GZIP magic number.static booleanisTarStream(@NonNull InputStream stream) Peek the first 512 bytes (TAR header) of the stream to see if the stream contains TAR data.voidwriteCurrentEntryTo(@NonNull OutputStream stream) Write the current archive entry to the givenOutputStream.Methods inherited from class xyz.apollosoftware.bibliothiki.compression.ArchiveInputStream
detect
-
Constructor Details
-
TapeArchiveInputStream
Construct aTapeArchiveInputStreamthat encapsulates the givenInputStream.- Parameters:
stream- The input stream that will provide tar data.
-
-
Method Details
-
isGzipStream
Peek the first two bytes of the stream to see if they match the GZIP magic number.- Parameters:
stream- The stream to check.- Returns:
- True, if the stream is a GZIP stream, otherwise false.
-
isTarStream
Peek the first 512 bytes (TAR header) of the stream to see if the stream contains TAR data.- Parameters:
stream- The stream to check.- Returns:
- True, if the stream is a TAR stream, otherwise false.
-
getNextEntry
Description copied from class:ArchiveInputStreamGet the next entry in the archive.If there are no (more) entries in the archive, this method returns null, instead.
- Specified by:
getNextEntryin classArchiveInputStream- Returns:
- The
ArchiveEntry, if there is one. - See Also:
-
writeCurrentEntryTo
Description copied from class:ArchiveInputStreamWrite the current archive entry to the givenOutputStream.The
ArchiveInputStream.getNextEntry()must have been called prior, or this method will throw aCompressionException.A common pattern for writing to files, therefore, would be to invoke
ArchiveInputStream.getNextEntry()and then write the file data with this method.Some implementations may return a
CompressionExceptionfor format or decompression failures. Implementations that do this will still returnIOExceptionwhen an exception is raised writing to the given output stream. In cases where it is not possible to disambiguate, anIOExceptionis always thrown instead.- Specified by:
writeCurrentEntryToin classArchiveInputStream- Parameters:
stream- The stream to write the file data to.- Throws:
IOException- If writing to the givenOutputStreamfails with anIOException.- See Also:
-
closeCurrentEntry
public void closeCurrentEntry()Description copied from class:ArchiveInputStreamClose the current entry.This may be a no-op for some implementations.
- Specified by:
closeCurrentEntryin classArchiveInputStream
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classArchiveInputStream
-