@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) @Immutable public final class TFileInputStream extends DecoratingInputStream
FileInputStream for reading plain old
files or entries in an archive file.
Mind that applications cannot read archive files directly - just their
entries!
To prevent exceptions to be thrown subsequently, applications should always close their streams using the following idiom:
TFileInputStream in = new TFileInputStream(file);
try {
// Do I/O here...
} finally {
in.close(); // ALWAYS close the stream!
}
Note that the DecoratingInputStream.close() method may throw an IOException, too.
Applications need to deal with this appropriately, for example by enclosing
the entire block with another try-catch-block:
try {
TFileInputStream in = new TFileInputStream(file);
try {
// Do I/O here...
} finally {
in.close(); // ALWAYS close the stream!
}
} catch (IOException ex) {
ex.printStackTrace();
}
Applications cannot read from an entry in an archive file if an implicit
unmount is required but cannot get performed because
another TFileInputStream or TFileOutputStream object hasn't
been closed or garbage collected yet.
A FileNotFoundException is thrown by the constructors of this class
in this case.
If you would like to use this class in order to cp files,
please consider using one of the
cp methods of the class TFile
instead.
These methods provide ease of use, enhanced features, superior performance
and require less space in the temp file folder.
TFile.cat(InputStream, OutputStream),
TFileOutputStreamdelegate| Constructor and Description |
|---|
TFileInputStream(File file)
Constructs a new input stream for reading plain old files or entries
in an archive file.
|
TFileInputStream(String path)
Constructs a new input stream for reading plain old files or entries
in an archive file.
|
| Modifier and Type | Method and Description |
|---|---|
private static InputStream |
newInputStream(File src) |
public TFileInputStream(File file) throws FileNotFoundException
file - the plain old file or entry in an archive file to read.FileBusyException - If the path denotes an archive entry and the
archive driver does not support to create an additional input
stream for the archive file.FileNotFoundException - On any other I/O related issue.public TFileInputStream(String path) throws FileNotFoundException
new TFile(path) for
the given path.path - the path of the plain old file or entry in an archive file
to read.FileBusyException - If the path denotes an archive entry and the
archive driver does not support to create an additional input
stream for the archive file.FileNotFoundException - On any other I/O related issue.private static InputStream newInputStream(File src) throws FileNotFoundException
FileNotFoundExceptionCopyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.