TrueZIP File* 7.0

de.schlichtherle.truezip.file
Class TFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by de.schlichtherle.truezip.io.DecoratingOutputStream
          extended by de.schlichtherle.truezip.file.TFileOutputStream
All Implemented Interfaces:
Closeable, Flushable

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
@Immutable
public final class TFileOutputStream
extends DecoratingOutputStream

A replacement for the class FileOutputStream for writing plain old files or entries in an archive file. Note that applications cannot write archive files directly using this class - just their entries.

To prevent exceptions to be thrown subsequently, applications should always close their streams using the following idiom:

TFileOutputStream out = new TFileOutputStream(file);
 try {
     // Do I/O here...
 } finally {
     out.close(); // ALWAYS close the stream!
 }
 

Note that the DecoratingOutputStream.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 {
     TFileOutputStream out = new TFileOutputStream(file);
     try {
         // Do I/O here...
     } finally {
         out.close(); // ALWAYS close the stream!
     }
 } catch (IOException ex) {
     ex.printStackTrace();
 }
 

Applications cannot write to 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.

Author:
Christian Schlichtherle
See Also:
TFile.cat(InputStream, OutputStream), TFile.setLenient(boolean), TFileInputStream

Field Summary
private static BitField<FsOutputOption> DEFAULT_OPTIONS
           
 
Fields inherited from class de.schlichtherle.truezip.io.DecoratingOutputStream
delegate
 
Constructor Summary
TFileOutputStream(File file)
          Constructs a new output stream for writing plain old files or entries in an archive file.
TFileOutputStream(File file, boolean append)
          Constructs a new output stream for writing plain old files or entries in an archive file.
TFileOutputStream(String path)
          Constructs a new output stream for writing plain old files or entries in an archive file.
TFileOutputStream(String path, boolean append)
          Constructs a new output stream for writing plain old files or entries in an archive file.
 
Method Summary
private static OutputStream newOutputStream(File dst, boolean append)
           
 
Methods inherited from class de.schlichtherle.truezip.io.DecoratingOutputStream
close, flush, toString, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_OPTIONS

private static final BitField<FsOutputOption> DEFAULT_OPTIONS
Constructor Detail

TFileOutputStream

public TFileOutputStream(String path)
                  throws FileNotFoundException
Constructs a new output stream for writing plain old files or entries in an archive file. This constructor calls new TFile(path) for the given path.

Parameters:
path - the path of the plain old file or entry in an archive file to write.
Throws:
FileBusyException - If the path denotes an archive entry and the archive driver does not support to create an additional output stream for the archive file.
FileNotFoundException - On any other I/O related issue.

TFileOutputStream

public TFileOutputStream(String path,
                         boolean append)
                  throws FileNotFoundException
Constructs a new output stream for writing plain old files or entries in an archive file. This constructor calls new TFile(path) for the given path.

Parameters:
path - the path of the plain old file or entry in an archive file to write.
append - if the data shall get appended to the file rather than replacing it.
Throws:
FileBusyException - If the path denotes an archive entry and the archive driver does not support to create an additional output stream for the archive file.
FileNotFoundException - On any other I/O related issue.

TFileOutputStream

public TFileOutputStream(File file)
                  throws FileNotFoundException
Constructs a new output stream for writing plain old files or entries in an archive file.

Parameters:
file - the plain old file or entry in an archive file to write.
Throws:
FileBusyException - If the path denotes an archive entry and the archive driver does not support to create an additional output stream for the archive file.
FileNotFoundException - On any other I/O related issue.

TFileOutputStream

public TFileOutputStream(File file,
                         boolean append)
                  throws FileNotFoundException
Constructs a new output stream for writing plain old files or entries in an archive file.

Parameters:
file - the plain old file or entry in an archive file to write.
append - if the data shall get appended to the file rather than replacing it.
Throws:
FileBusyException - If the path denotes an archive entry and the archive driver does not support to create an additional output stream for the archive file.
FileNotFoundException - On any other I/O related issue.
Method Detail

newOutputStream

private static OutputStream newOutputStream(File dst,
                                            boolean append)
                                     throws FileNotFoundException
Throws:
FileNotFoundException

TrueZIP File* 7.0

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.