com.mucommander.file.impl.zip.provider
Class DeflatedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.mucommander.file.impl.zip.provider.ZipEntryOutputStream
          extended by com.mucommander.file.impl.zip.provider.DeflatedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class DeflatedOutputStream
extends ZipEntryOutputStream

DeflatedOutputStream compresses data using the DEFLATED compression method.

--------------------------------------------------------------------------------------------------------------

This class is based off the org.apache.tools.zip package of the Apache Ant project. The Ant code has been modified under the terms of the Apache License which you can find in the bundled muCommander license file. It was forked at version 1.7.0 of Ant.

Author:
Maxence Bernard

Field Summary
protected  byte[] buf
          Buffer used to deflate data
protected  java.util.zip.Deflater deflater
          Deflater instance that does the actual compression work
 
Fields inherited from class com.mucommander.file.impl.zip.provider.ZipEntryOutputStream
crc, method, out
 
Constructor Summary
DeflatedOutputStream(java.io.OutputStream out, java.util.zip.Deflater deflater, byte[] buf)
          Creates a new DeflatedOutputStream that writes compressed data to the given OutputStream and automatically updates the supplied CRC32 checksum.
 
Method Summary
 void close()
          Completes writing the entry without closing the underlying OutputStream.
protected  void deflate()
          Writes next block of compressed data to the output stream.
 void finishDeflate()
          Finishes writing the DEFLATED-compressed data.
 int getTotalIn()
          Returns the uncompressed size of the data written so far.
 int getTotalOut()
          Returns the compressed size of the data written so far.
 void write(byte[] b, int offset, int length)
          Writes the given bytes to the Zip entry.
 
Methods inherited from class com.mucommander.file.impl.zip.provider.ZipEntryOutputStream
flush, getCrc, getMethod, write
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

deflater

protected java.util.zip.Deflater deflater
Deflater instance that does the actual compression work


buf

protected byte[] buf
Buffer used to deflate data

Constructor Detail

DeflatedOutputStream

public DeflatedOutputStream(java.io.OutputStream out,
                            java.util.zip.Deflater deflater,
                            byte[] buf)
Creates a new DeflatedOutputStream that writes compressed data to the given OutputStream and automatically updates the supplied CRC32 checksum.

Parameters:
out - the OutputStream where the compressed data is sent to
deflater - the Deflater that compresses data, reset before first use
buf - the buffer used to deflate data
Method Detail

deflate

protected void deflate()
                throws java.io.IOException
Writes next block of compressed data to the output stream.

Throws:
java.io.IOException - on error

finishDeflate

public void finishDeflate()
                   throws java.io.IOException
Finishes writing the DEFLATED-compressed data.

Throws:
java.io.IOException - if an I/O occurred

getTotalIn

public int getTotalIn()
Description copied from class: ZipEntryOutputStream
Returns the uncompressed size of the data written so far.

Specified by:
getTotalIn in class ZipEntryOutputStream
Returns:
the uncompressed size of the data written so far

getTotalOut

public int getTotalOut()
Description copied from class: ZipEntryOutputStream
Returns the compressed size of the data written so far.

Specified by:
getTotalOut in class ZipEntryOutputStream
Returns:
the compressed size of the data written so far

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Writes the given bytes to the Zip entry.

Overrides:
write in class java.io.OutputStream
Parameters:
b - the byte array to write
offset - the start position to write from
length - the number of bytes to write
Throws:
java.io.IOException - on error

close

public void close()
           throws java.io.IOException
Completes writing the entry without closing the underlying OutputStream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard