Java by API/java.util.zip/Deflater — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:22, 31 мая 2010
Содержание
Deflater.BEST_COMPRESSION
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] input = "asdf".getBytes();
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
byte[] compressedData = bos.toByteArray();
}
}
Deflater: deflate(byte[] b)
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] input = "asdf".getBytes();
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
byte[] compressedData = bos.toByteArray();
}
}
Deflater: finish()
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] input = "asdf".getBytes();
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
byte[] compressedData = bos.toByteArray();
}
}
Deflater: setInput(byte[] b)
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] input = "asdf".getBytes();
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
byte[] compressedData = bos.toByteArray();
}
}
Deflater: setLevel(int level)
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] input = "asdf".getBytes();
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
bos.close();
byte[] compressedData = bos.toByteArray();
}
}