本文整理汇总了Java中com.jcraft.jzlib.JZlib.Z_BEST_COMPRESSION属性的典型用法代码示例。如果您正苦于以下问题:Java JZlib.Z_BEST_COMPRESSION属性的具体用法?Java JZlib.Z_BEST_COMPRESSION怎么用?Java JZlib.Z_BEST_COMPRESSION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.jcraft.jzlib.JZlib
的用法示例。
在下文中一共展示了JZlib.Z_BEST_COMPRESSION属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
public static void write( DataStreamSerializable entity, OutputStream out )
throws IOException
{
ByteArrayOutputStream baos = serializePersistent( entity );
ZOutputStream gzip = new ZOutputStream( out, JZlib.Z_BEST_COMPRESSION );
DataOutputStream dos = new DataOutputStream( gzip );
try
{
byte[] res = baos.toByteArray();
dos.write( res );
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
dos.flush();
dos.close();
//gzip.finish();
}
}
示例2: test
public void test(TestHarness th) {
String value = "Hello, world!";
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZOutputStream zOut = new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION);
DataOutputStream dataOut = new DataOutputStream(zOut);
dataOut.writeUTF(value);
zOut.close();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ZInputStream zIn = new ZInputStream(in);
DataInputStream dataIn = new DataInputStream(zIn);
th.check(dataIn.readUTF(), value);
} catch (IOException e) {
th.fail("Unexpected exception: " + e);
}
}
示例3: main
public static void main(String args[]) {
String str = "";
String part = "abcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZabcdefghilmnopqrstuvzABCDEFGHILMNOPQRSTUVZ";
for (int i = 0; i < 1000; i++) {
str += part;
}
byte[] bytes = str.getBytes();
byte[] compressedBytes;
long start, time = 0;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = 0; i < 5; i++) {
ZOutputStream zOut = new ZOutputStream(out, JZlib.Z_BEST_COMPRESSION);
DataOutputStream dataOut = new DataOutputStream(zOut);
start = JVM.monotonicTimeMillis();
dataOut.write(bytes);
zOut.close();
time += JVM.monotonicTimeMillis() - start;
}
System.out.println("compress: " + time);
time = 0;
compressedBytes = out.toByteArray();
start = JVM.monotonicTimeMillis();
for (int i = 0; i < 5; i++) {
ByteArrayInputStream in = new ByteArrayInputStream(compressedBytes);
ZInputStream zIn = new ZInputStream(in);
DataInputStream dataIn = new DataInputStream(zIn);
start = JVM.monotonicTimeMillis();
dataIn.read(bytes);
time += JVM.monotonicTimeMillis() - start;
zIn.close();
}
System.out.println("uncompress: " + time);
} catch (IOException e) {
System.out.println("Unexpected exception: " + e);
}
}