United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4505111 : Support for pluggable ZipFile compression methods.

Details
Type:
Enhancement
Submit Date:
2001-09-20
Status:
Open
Updated Date:
2009-08-25
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
generic
Sub-Component:
java.util.jar
CPU:
generic
Priority:
P4
Resolution:
Unresolved
Affected Versions:
1.4.0
Targeted Versions:

Related Reports

Sub Tasks

Description

Name: bsT130419			Date: 09/20/2001


java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

As some people probably know, the Zip file format has built-in support for
arbitrary compression methods. As far as I can tell, however, the support for
this format in java.util.zip only supports the Deflate method. It may be useful
to be able to use Java's Zip file support with some other compression algorithm
-- most notably, bzip2, which is somewhat popular in the Linux world because
it's better at compressing plain text, source code, and the like. I'm aware that
this would be a non-standard extension to the Zip format, but this doesn't make
it completely useless -- it could be useful, for instance, in a corporate
intranet, where everyone has installed the appropriate compression method handler.

  To allow for pluggable compression methods, I envision an interface looking like
this:

--- BEGIN CODE ---

public interface CompressionMethod {
  /**
   * Algorithm hint for when speed is more important than
   * compression ratio.
   *
   * @see #setAlgorithmHints
   * @see #AH_BEST_COMPRESSION
   */
  public static final int AH_BEST_SPEED = 0x1;

  /**
   * Algorithm hint for when compression ratio is more
   * important than speed.
   *
   * @see #setAlgorithmHints
   * @see #AH_BEST_SPEED
   */
  public static final int AH_BEST_COMPRESSION = 0x2;

  /**
   * Algorithm hint for when the algorithm should avoid
   * using a large amount of memory, on systems with a
   * limited amount of memory to spare.
   *
   * @see #setAlgorithmHints
   */
  public static final int AH_LOW_MEMORY = 0x4;

  /**
   * Returns the Zip file compression method number to
   * be used by files compressed with this algorithm.
   */
  short getMethodNumber();

  /**
   * Compresses the bytes of <code>input</code>, between
   * <code>off</code>, inclusive, and <code>off+len</code>,
   * noninclusive. Produces a new <code>byte</code> array
   * with the compressed data, which may subsequently be
   * decompressed with the {@link #decompress} method.
   *
   * <p>This method does not alter the contents of the
   * <code>input</code> parameter. The return value is a
   * newly allocated <code>byte</code> array.
   */
  byte[] compress(byte[] input, int off, int len);

  /**
   * Decompresses the bytes of <code>input</code>, between
   * <code>off</code>, inclusive, and <code>off+len</code>,
   * noninclusive. Produces a new <code>byte</code> array
   * with the decompressed data, which may subsequently be
   * compressed again with the {@link #compress} method,
   * though the return value from that method may not be
   * identical to the <code>input</code> parameter.
   *
   * <p>This method does not alter the contents of the
   * <code>input</code> parameter. The return value is a
   * newly allocated <code>byte</code> array.
   */
  byte[] decompress(byte[] input, int off, int len);

  /**
   * Sets the <dfn>algorithm hints</dfn> for this
   * compression method. Algorithm hints are any of up
   * to 32 bits, which are either on or off, and give the
   * algorithm additional information about what type of
   * performance is desired, such as increased speed being
   * given favor over a high compression ratio.
   *
   * @param hints a bitwise OR of any of the algorithm
   *              hint constants defined in the fields of
   *              this interface that begin with AH_.
   * @see #getAlgorithmHints
   */
  void setAlgorithmHints(int hints);

  /**
   * Returns the set of algorithm hints currently in effect,
   * as a result of an invocation of the
   * {@link #setAlgorithmHints} method.
   *
   * @return the value which was previously passed as the
   *         <code>hints</code> parameter to the
   *         <code>setAlgorithmHints</code> method.
   */
  int getAlgorithmHints();
}

--- END CODE ---
Obviously, the doc comments should have all their usual tags
that I've left -- @author, etc.

Creating an implementation of this interface for support of
the Deflate compression method should be straightforward,
though some default values may need to be used for the
compression strategy.
Using this interface exclusively to determine which compression
method is used in ZipOutputStream, et al. is my ultimate vision
here.
(Review ID: 132218) 
======================================================================

                                    

Comments
EVALUATION

Will be considered for future releases.


###@###.### 2002-04-23

bzip2 has better compression depending on the file for example take our
own rt.jar, 
rt.jar	     32.34
rt.jar.bz2    8.23
rt.jar.gz    10.02

this will help deployment applications
if the bzip2 is supported as a deflate algorithm.


###@###.### 2004-02-12
                                     
2004-02-12
WORK AROUND



Name: bsT130419			Date: 09/20/2001


Use Deflate. :)
======================================================================
                                     
2004-09-09



Hardware and Software, Engineered to Work Together