de.schlichtherle.io
Class FileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by de.schlichtherle.io.FileOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class FileOutputStream
extends FilterOutputStream

A drop-in replacement for FileOutputStream which provides transparent write access to archive entries as if they were (virtual) files. All file system operations in this class are virtually atomic.

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


 FileOutputStream fos = new FileOutputStream(file);
 try {
     // access fos here
 } finally {
     fos.close();
 }
 

Note that for various (mostly archive driver specific) reasons, the close() method may throw an IOException, too. Client applications need to deal with this appropriately, for example by enclosing the entire block with another try-catch-block.

Client applications cannot write to an entry in an archive file if an automatic update is required but cannot get performed because other FileInputStream or FileOutputStream instances haven't been closed or garbage collected yet. A FileBusyException is thrown by the constructors of this class in this case.

Whether or not a client application can write to more than one entry in the same archive archive file concurrently is an implementation detail of the respective archive driver. As of version 6.5, all archive drivers provided by TrueZIP don't restrict this. However, custom archive drivers provided by third parties may do so.

If a client application tries to exceed the number of entry streams supported to operate on the same archive file concurrently, a FileBusyException is thrown by the constructors of this class.

If you would like to use this class in order to copy files, please consider using the *copy* methods in the File class instead. These methods provide ease of use, enhanced features, superior performance and require less space in the temp file folder.

Version:
TrueZIP 6.7
Author:
Christian Schlichtherle
See Also:
Using Archive Entry Streams, FileBusyException, File.cat(java.io.InputStream, java.io.OutputStream), File.umount(), File.update(), File.setLenient(boolean)

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
FileOutputStream(File file)
          Behaves like the super class, but also supports archive entry files.
FileOutputStream(File file, boolean append)
          Behaves like the super class, but also supports archive entry files.
FileOutputStream(FileDescriptor fd)
          Behaves like the super class.
FileOutputStream(String name)
          Behaves like the super class, but also supports archive entry files.
FileOutputStream(String name, boolean append)
          Behaves like the super class, but also supports archive entry files.
 
Method Summary
 void write(byte[] buf, int off, int len)
           
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileOutputStream

public FileOutputStream(String name)
                 throws FileNotFoundException
Behaves like the super class, but also supports archive entry files.

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.

FileOutputStream

public FileOutputStream(String name,
                        boolean append)
                 throws FileNotFoundException
Behaves like the super class, but also supports archive entry files.

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.

FileOutputStream

public FileOutputStream(File file)
                 throws FileNotFoundException
Behaves like the super class, but also supports archive entry files.

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.

FileOutputStream

public FileOutputStream(File file,
                        boolean append)
                 throws FileNotFoundException
Behaves like the super class, but also supports archive entry files.

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.

FileOutputStream

public FileOutputStream(FileDescriptor fd)
Behaves like the super class.

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.
Since:
TrueZIP 6.4
Method Detail

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class FilterOutputStream
Throws:
IOException