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


Java ZOutputStream类代码示例

本文整理汇总了Java中com.jcraft.jzlib.ZOutputStream的典型用法代码示例。如果您正苦于以下问题:Java ZOutputStream类的具体用法?Java ZOutputStream怎么用?Java ZOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZOutputStream类属于com.jcraft.jzlib包,在下文中一共展示了ZOutputStream类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import com.jcraft.jzlib.ZOutputStream; //导入依赖的package包/类
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,代码行数:25,代码来源:DataStreamSerializer.java

示例2: test

import com.jcraft.jzlib.ZOutputStream; //导入依赖的package包/类
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,代码行数:19,代码来源:TestJZlib.java

示例3: enableCompression

import com.jcraft.jzlib.ZOutputStream; //导入依赖的package包/类
private void enableCompression(Socket socket) throws IOException {
    InputStream inputStream = new InflaterInputStream(socket.getInputStream(), new Inflater(true));
    input = Okio.buffer(Okio.source(inputStream));

    ZOutputStream outputStream = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_SPEED, true);
    outputStream.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
    output = Okio.buffer(Okio.sink(outputStream));
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:9,代码来源:MockSmtpServer.java

示例4: main

import com.jcraft.jzlib.ZOutputStream; //导入依赖的package包/类
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,代码行数:48,代码来源:JZlibBench.java


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