de.unikassel.android.sdcframework.util
Class ZipCompressionStrategy

Package class diagram package ZipCompressionStrategy
java.lang.Object
  extended by de.unikassel.android.sdcframework.util.ZipCompressionStrategy
All Implemented Interfaces:
CompressionStrategy
Direct Known Subclasses:
JarCompressionStrategy

public class ZipCompressionStrategy
extends Object
implements CompressionStrategy

The compression strategy to create ZIP archives.


Field Summary
private  byte[] buffer
          the internal buffer
private static int BUFFER_SIZE
          The internal buffer size used while piping data
private  int level
          The compression level
private  int method
          The compression method
 
Constructor Summary
  ZipCompressionStrategy()
          Constructor
  ZipCompressionStrategy(boolean deflated)
          Constructor
protected ZipCompressionStrategy(int method, int level)
          Constructor
 
Method Summary
 boolean compress(List<String> files, BufferedOutputStream out)
          The compression method
protected  ZipEntry createArchiveEntry(String file)
          Does create an archive entry for the compressed file
protected  ZipOutputStream createDeflaterOutPutStream(BufferedOutputStream out)
          Does create the deflater output stream
 String getArchiveExtension()
          Getter for an archive file extension of this strategy
 int getMethod()
          Getter for the method
private  void pipeInToOut(BufferedInputStream in, DeflaterOutputStream out)
          Method to pipe input into output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

private static final int BUFFER_SIZE
The internal buffer size used while piping data

See Also:
Constant Field Values

buffer

private final byte[] buffer
the internal buffer


method

private final int method
The compression method


level

private final int level
The compression level

Constructor Detail

ZipCompressionStrategy

public ZipCompressionStrategy()
Constructor


ZipCompressionStrategy

protected ZipCompressionStrategy(int method,
                                 int level)
Constructor


ZipCompressionStrategy

public ZipCompressionStrategy(boolean deflated)
Constructor

Parameters:
deflated - flag for archive content compression ( true for compression )
Method Detail

getMethod

public final int getMethod()
Getter for the method

Returns:
the method

compress

public boolean compress(List<String> files,
                        BufferedOutputStream out)
                 throws IOException
Description copied from interface: CompressionStrategy
The compression method

Specified by:
compress in interface CompressionStrategy
Parameters:
files - a list with the files to compress
out - the output stream to compress files into
Returns:
true if successful, false otherwise
Throws:
IOException - if closing the output stream fails

createArchiveEntry

protected ZipEntry createArchiveEntry(String file)
Does create an archive entry for the compressed file

Parameters:
file - the file name and path
Returns:
the archive entry

createDeflaterOutPutStream

protected ZipOutputStream createDeflaterOutPutStream(BufferedOutputStream out)
                                              throws IOException
Does create the deflater output stream

Parameters:
out - the buffered output stream to wrap
Returns:
the deflater output stream
Throws:
IOException

pipeInToOut

private void pipeInToOut(BufferedInputStream in,
                         DeflaterOutputStream out)
                  throws IOException
Method to pipe input into output stream

Parameters:
in - the input stream
out - the deflater output stream
Throws:
IOException - in case of an IO exception

getArchiveExtension

public String getArchiveExtension()
Description copied from interface: CompressionStrategy
Getter for an archive file extension of this strategy

Specified by:
getArchiveExtension in interface CompressionStrategy
Returns:
the archive file extension of this strategy