Package org.refcodes.io
Class ZipFileInputStreamImpl
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- org.refcodes.io.ZipFileInputStreamImpl
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ZipFileInputStreamImpl extends BufferedInputStream
Represents anInputStream
from a providedFile
: In case the file points to a ZIP compressed file, then the uncompressed data of the therein contained file with the same name excluding the ".zip" extension is provided by theInputStream
.
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description ZipFileInputStreamImpl(File aFile)
Instantiates a new zip file input stream impl.ZipFileInputStreamImpl(File parent, String child)
Instantiates a new zip file input stream impl.ZipFileInputStreamImpl(String pathname)
Instantiates a new zip file input stream impl.ZipFileInputStreamImpl(String parent, String child)
Instantiates a new zip file input stream impl.ZipFileInputStreamImpl(URI uri)
Instantiates a new zip file input stream impl.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static String
toFileNameFromZip(String aZipFileName)
Truncates the ".zip" suffix from the filename and returns the result.protected static InputStream
toInputStream(File aFile)
Returns anInputStream
from the providedFile
.-
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, reset, skip
-
Methods inherited from class java.io.FilterInputStream
read
-
Methods inherited from class java.io.InputStream
readAllBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
ZipFileInputStreamImpl
public ZipFileInputStreamImpl(File parent, String child) throws ZipException, FileNotFoundException, IOException
Instantiates a new zip file input stream impl.- Parameters:
parent
- the parentchild
- the child- Throws:
ZipException
- the zip exceptionFileNotFoundException
- the file not found exceptionIOException
- Signals that an I/O exception has occurred.
-
ZipFileInputStreamImpl
public ZipFileInputStreamImpl(String parent, String child) throws ZipException, FileNotFoundException, IOException
Instantiates a new zip file input stream impl.- Parameters:
parent
- the parentchild
- the child- Throws:
ZipException
- the zip exceptionFileNotFoundException
- the file not found exceptionIOException
- Signals that an I/O exception has occurred.
-
ZipFileInputStreamImpl
public ZipFileInputStreamImpl(String pathname) throws ZipException, FileNotFoundException, IOException
Instantiates a new zip file input stream impl.- Parameters:
pathname
- the pathname- Throws:
ZipException
- the zip exceptionFileNotFoundException
- the file not found exceptionIOException
- Signals that an I/O exception has occurred.
-
ZipFileInputStreamImpl
public ZipFileInputStreamImpl(URI uri) throws ZipException, FileNotFoundException, IOException
Instantiates a new zip file input stream impl.- Parameters:
uri
- the uri- Throws:
ZipException
- the zip exceptionFileNotFoundException
- the file not found exceptionIOException
- Signals that an I/O exception has occurred.
-
ZipFileInputStreamImpl
public ZipFileInputStreamImpl(File aFile) throws ZipException, FileNotFoundException, IOException
Instantiates a new zip file input stream impl.- Parameters:
aFile
- the file- Throws:
ZipException
- the zip exceptionFileNotFoundException
- the file not found exceptionIOException
- Signals that an I/O exception has occurred.
-
-
Method Detail
-
toInputStream
protected static InputStream toInputStream(File aFile) throws ZipException, IOException, FileNotFoundException
Returns anInputStream
from the providedFile
. In case the file points to a ZIP compressed file, then the uncompressed data is provided by theInputStream
.- Parameters:
aFile
- TheFile
for which to get theInputStream
.- Returns:
- An
InputStream
, in case of a ZIP compressedFile
, an uncompressedInputStream
is returned. - Throws:
ZipException
- in case there were problems when accessing the ZIP compressedFile
.IOException
- in case there were problems working with theFile
.FileNotFoundException
- in case there was none suchFile
found.
-
toFileNameFromZip
protected static String toFileNameFromZip(String aZipFileName)
Truncates the ".zip" suffix from the filename and returns the result. For example a file with name "log-2023-07-12.txt.zip" results in "log-2023-07-12.txt".- Parameters:
aZipFileName
- The file name of the ZIP file for which to get the "inner" file name.- Returns:
- The "inner" file name if the file suffix was ".zip", else null.
-
-