Class ArchiveInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
TapeArchiveInputStream,ZipArchiveInputStream
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionArchiveInputStream(@NonNull InputStream stream) Construct anArchiveInputStreamfrom the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()abstract voidClose the current entry.static @NonNull ArchiveInputStreamdetect(@NonNull InputStream stream) Automatically detects the archive format (and therefore theArchiveInputStreamimplementation) to use for the given stream.abstract @Nullable ArchiveEntryGet the next entry in the archive.abstract voidwriteCurrentEntryTo(@NonNull OutputStream stream) Write the current archive entry to the givenOutputStream.
-
Field Details
-
stream
The stream of compressed data.
-
-
Constructor Details
-
ArchiveInputStream
Construct anArchiveInputStreamfrom the given stream.The stream should not be exposed externally to the class hierarchy of the
ArchiveInputStream.- Parameters:
stream- The stream containing archive data.
-
-
Method Details
-
getNextEntry
Get the next entry in the archive.If there are no (more) entries in the archive, this method returns null, instead.
- Returns:
- The
ArchiveEntry, if there is one. - See Also:
-
writeCurrentEntryTo
Write the current archive entry to the givenOutputStream.The
getNextEntry()must have been called prior, or this method will throw aCompressionException.A common pattern for writing to files, therefore, would be to invoke
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.- Parameters:
stream- The stream to write the file data to.- Throws:
IOException- If writing to the givenOutputStreamfails with anIOException.CompressionException- If decompressing or reading an entry to write fails.- See Also:
-
closeCurrentEntry
public abstract void closeCurrentEntry()Close the current entry.This may be a no-op for some implementations.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
detect
Automatically detects the archive format (and therefore theArchiveInputStreamimplementation) to use for the given stream.- Parameters:
stream- The stream to detect the input stream for.- Returns:
- The
ArchiveInputStreamimplementation for the given stream format. - Throws:
CompressionException- If the archive format is not supported.
-