LevelGZIPOutputStream — GZIPOutputStream mit Kompressionslevel

Der normale GZIPOutputStream nutzt einen Standardkompressionswert. Um diesen zu ändern, ruft man beim Deflator, der eigentlich hinter der Kompresssion steckt, setLevel() auf, um den Kompressionslevel setzen. Die folgende Unterklasse regelt das für uns:

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

public class LevelGZIPOutputStream extends GZIPOutputStream
{
/**
* Creates a new output stream with a default buffer size and
* sets the current compression level to the specified value.
*
* @param out the output stream.
* @param level the new compression level (0-9).
* @exception IOException If an I/O error has occurred.
* @exception IllegalArgumentException if the compression level is invalid.
*/
public LevelGZIPOutputStream( OutputStream out, int compressionLevel )
throws IOException
{
super( out );
def.setLevel( compressionLevel );
}
}

Ähnliche Beiträge

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert