当前位置: 首页>>代码示例>>Java>>正文


Java JZlib.Z_BEST_COMPRESSION属性代码示例

本文整理汇总了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();
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:24,代码来源:DataStreamSerializer.java

示例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);
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:18,代码来源:TestJZlib.java

示例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);
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:47,代码来源:JZlibBench.java


注:本文中的com.jcraft.jzlib.JZlib.Z_BEST_COMPRESSION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。