com.izforge.izpack.io
Class FileSpanningOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.izforge.izpack.io.FileSpanningOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class FileSpanningOutputStream
extends java.io.OutputStream

An outputstream which transparently spans over multiple volumes. The size of the volumes and an additonal space for the first volume can be specified.

Author:
Dennis Reil,

Field Summary
protected  java.io.File currentfile
           
protected  int currentvolumeindex
           
static long DEFAULT_ADDITIONAL_FIRST_VOLUME_FREE_SPACE_SIZE
           
protected static java.lang.String DEFAULT_VOLUME_NAME
           
static long DEFAULT_VOLUME_SIZE
           
protected static long FILE_NOT_AVAILABLE
           
private  java.io.FileOutputStream fileoutputstream
           
protected  long filepointer
           
protected  long firstvolumefreespacesize
           
static long KB
           
static int MAGIC_NUMER_LENGTH
           
private  byte[] magicnumber
           
protected  long maxvolumesize
           
static long MB
           
protected  long totalbytesofpreviousvolumes
           
protected  java.lang.String volumename
           
static java.lang.String VOLUMES_INFO
           
private  java.util.zip.GZIPOutputStream zippedoutputstream
           
 
Constructor Summary
  FileSpanningOutputStream()
           
  FileSpanningOutputStream(java.io.File volume)
           
  FileSpanningOutputStream(java.io.File volume, long maxvolumesize)
          Creates a new spanning output stream with specified volume names and a maximum volume size
protected FileSpanningOutputStream(java.io.File volume, long maxvolumesize, int currentvolume)
          Creates a new spanning output stream with specified volume names and a maximum volume size
  FileSpanningOutputStream(java.lang.String volumename)
           
  FileSpanningOutputStream(java.lang.String volumename, long maxvolumesize)
          Creates a new spanning output stream with specified volume names and a maximum volume size
 
Method Summary
 void close()
           
protected  void createStreamToNextVolume()
          Closes the stream to the current volume and reopens to the next volume
private  void createVolumeOutputStream(java.io.File volume, long maxvolumesize, int currentvolume)
          Actually creates the outputstream for writing a volume with index currentvolume and a maximum of maxvolumesize
 void flush()
           
private  void generateMagicNumber()
           
 long getCompressedFilepointer()
          Returns the current position in this file
protected  long getCurrentVolumeSize()
          Returns the size of the current volume
 long getFilepointer()
           
 long getFirstvolumefreespacesize()
           
 int getVolumeCount()
          Returns the amount of currently created volumes
 void setFirstvolumefreespacesize(long firstvolumefreespacesize)
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KB

public static final long KB
See Also:
Constant Field Values

MB

public static final long MB
See Also:
Constant Field Values

DEFAULT_VOLUME_SIZE

public static final long DEFAULT_VOLUME_SIZE
See Also:
Constant Field Values

DEFAULT_ADDITIONAL_FIRST_VOLUME_FREE_SPACE_SIZE

public static final long DEFAULT_ADDITIONAL_FIRST_VOLUME_FREE_SPACE_SIZE
See Also:
Constant Field Values

DEFAULT_VOLUME_NAME

protected static final java.lang.String DEFAULT_VOLUME_NAME
See Also:
Constant Field Values

FILE_NOT_AVAILABLE

protected static final long FILE_NOT_AVAILABLE
See Also:
Constant Field Values

maxvolumesize

protected long maxvolumesize

firstvolumefreespacesize

protected long firstvolumefreespacesize

VOLUMES_INFO

public static final java.lang.String VOLUMES_INFO
See Also:
Constant Field Values

MAGIC_NUMER_LENGTH

public static final int MAGIC_NUMER_LENGTH
See Also:
Constant Field Values

currentfile

protected java.io.File currentfile

volumename

protected java.lang.String volumename

currentvolumeindex

protected int currentvolumeindex

fileoutputstream

private java.io.FileOutputStream fileoutputstream

zippedoutputstream

private java.util.zip.GZIPOutputStream zippedoutputstream

magicnumber

private byte[] magicnumber

filepointer

protected long filepointer

totalbytesofpreviousvolumes

protected long totalbytesofpreviousvolumes
Constructor Detail

FileSpanningOutputStream

public FileSpanningOutputStream(java.lang.String volumename,
                                long maxvolumesize)
                         throws java.io.IOException
Creates a new spanning output stream with specified volume names and a maximum volume size

Parameters:
volumename - - the name of the volumes
maxvolumesize - - the maximum volume size
Throws:
java.io.IOException

FileSpanningOutputStream

public FileSpanningOutputStream(java.io.File volume,
                                long maxvolumesize)
                         throws java.io.IOException
Creates a new spanning output stream with specified volume names and a maximum volume size

Parameters:
volume - - the first volume
maxvolumesize - - the maximum volume size
Throws:
java.io.IOException

FileSpanningOutputStream

protected FileSpanningOutputStream(java.io.File volume,
                                   long maxvolumesize,
                                   int currentvolume)
                            throws java.io.IOException
Creates a new spanning output stream with specified volume names and a maximum volume size

Parameters:
volume - - the first volume
maxvolumesize - - the maximum volume size
currentvolume - - the current volume
Throws:
java.io.IOException

FileSpanningOutputStream

public FileSpanningOutputStream(java.io.File volume)
                         throws java.io.IOException
Parameters:
volume -
Throws:
java.io.IOException

FileSpanningOutputStream

public FileSpanningOutputStream(java.lang.String volumename)
                         throws java.io.IOException
Parameters:
volumename -
Throws:
java.io.IOException

FileSpanningOutputStream

public FileSpanningOutputStream()
                         throws java.io.IOException
Throws:
java.io.IOException
Method Detail

generateMagicNumber

private void generateMagicNumber()

createVolumeOutputStream

private void createVolumeOutputStream(java.io.File volume,
                                      long maxvolumesize,
                                      int currentvolume)
                               throws java.io.IOException
Actually creates the outputstream for writing a volume with index currentvolume and a maximum of maxvolumesize

Parameters:
volume - - the volume to write to
maxvolumesize - - the maximum volume size
currentvolume - - the currentvolume index
Throws:
java.io.IOException

getCurrentVolumeSize

protected long getCurrentVolumeSize()
Returns the size of the current volume

Returns:
the size of the current volume FILE_NOT_AVAILABLE, if there's no current volume

createStreamToNextVolume

protected void createStreamToNextVolume()
                                 throws java.io.IOException
Closes the stream to the current volume and reopens to the next volume

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.close()

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(byte[], int, int)

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(byte[])

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.write(int)

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException
See Also:
OutputStream.flush()

getVolumeCount

public int getVolumeCount()
Returns the amount of currently created volumes

Returns:
the amount of created volumes

getFirstvolumefreespacesize

public long getFirstvolumefreespacesize()
Returns:

setFirstvolumefreespacesize

public void setFirstvolumefreespacesize(long firstvolumefreespacesize)
Parameters:
firstvolumefreespacesize -

getCompressedFilepointer

public long getCompressedFilepointer()
                              throws java.io.IOException
Returns the current position in this file

Returns:
the position in this file
Throws:
java.io.IOException

getFilepointer

public long getFilepointer()