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


Java JZlib类代码示例

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


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

示例1: write

import com.jcraft.jzlib.JZlib; //导入依赖的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: compress

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
public byte[] compress(byte[] data, int offset, int length) {
    byte[] out = null;

    /* i'm not a big fan of the ZStream API here. */
    mDeflateStream.next_in = data;
    mDeflateStream.next_in_index = offset;
    mDeflateStream.avail_in = length;

    do {
        mDeflateStream.next_out = mBuffer;
        mDeflateStream.next_out_index = 0;
        mDeflateStream.avail_out = BUFFER_SIZE;
        int status = mDeflateStream.deflate(JZlib.Z_PARTIAL_FLUSH);
        out = appendBytes(out, mBuffer, 0, BUFFER_SIZE
                - mDeflateStream.avail_out);
        if (status != JZlib.Z_OK) {
            return out;
        }
    } while ((mDeflateStream.avail_in > 0)
            || (mDeflateStream.avail_out == 0));
    return out;
}
 
开发者ID:freznicek,项目名称:jaramiko,代码行数:23,代码来源:ZlibCompressor.java

示例3: uncompress

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
public byte[] uncompress(byte[] data, int offset, int length) {
    byte[] out = null;

    /* i'm not a big fan of the ZStream API here. */
    mInflateStream.next_in = data;
    mInflateStream.next_in_index = offset;
    mInflateStream.avail_in = length;

    do {
        mInflateStream.next_out = mBuffer;
        mInflateStream.next_out_index = 0;
        mInflateStream.avail_out = BUFFER_SIZE;
        int status = mInflateStream.inflate(JZlib.Z_PARTIAL_FLUSH);
        out = appendBytes(out, mBuffer, 0, BUFFER_SIZE
                - mInflateStream.avail_out);
        if (status != JZlib.Z_OK) {
            return out;
        }
    } while ((mInflateStream.avail_in > 0)
            || (mInflateStream.avail_out == 0));
    return out;
}
 
开发者ID:freznicek,项目名称:jaramiko,代码行数:23,代码来源:ZlibCompressor.java

示例4: convertWrapperType

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
static JZlib.WrapperType convertWrapperType(ZlibWrapper wrapper) {
    JZlib.WrapperType convertedWrapperType;
    switch (wrapper) {
    case NONE:
        convertedWrapperType = JZlib.W_NONE;
        break;
    case ZLIB:
        convertedWrapperType = JZlib.W_ZLIB;
        break;
    case GZIP:
        convertedWrapperType = JZlib.W_GZIP;
        break;
    case ZLIB_OR_NONE:
        convertedWrapperType = JZlib.W_ANY;
        break;
    default:
        throw new Error();
    }
    return convertedWrapperType;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:21,代码来源:ZlibUtil.java

示例5: process

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
public SafeByteArray process(SafeByteArray input) throws ZLibException {
       SafeByteArray output = new SafeByteArray();
stream_.avail_in = input.getSize();
stream_.next_in = input.getData();
       stream_.next_in_index = 0;
       do {
           byte[] outputArray = new byte[CHUNK_SIZE];
           stream_.avail_out = CHUNK_SIZE;
           stream_.next_out = outputArray;
           stream_.next_out_index = 0;
           int result = processZStream();
           if (result != JZlib.Z_OK && result != JZlib.Z_BUF_ERROR) {
               throw new ZLibException(/* stream_.msg */);
           }
           output.append(outputArray, CHUNK_SIZE - stream_.avail_out);
}
while (stream_.avail_out == 0);
if (stream_.avail_in != 0) {
	throw new ZLibException();
}
return output;
   }
 
开发者ID:swift,项目名称:stroke,代码行数:23,代码来源:ZLibCodecompressor.java

示例6: compress

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
public byte[] compress(byte[] buf, int start, int len) throws IOException {

		compressOut.reset();
		stream.next_in = buf;
		stream.next_in_index = start;
		stream.avail_in = len - start;
		int status;

		do {
			stream.next_out = tmpbuf;
			stream.next_out_index = 0;
			stream.avail_out = BUF_SIZE;
			status = stream.deflate(JZlib.Z_PARTIAL_FLUSH);
			switch (status) {
			case JZlib.Z_OK:
				compressOut.write(tmpbuf, 0, BUF_SIZE - stream.avail_out);
				break;
			default:
				throw new IOException("compress: deflate returnd " + status);
			}
		} while (stream.avail_out == 0);

		return compressOut.toByteArray();
	}
 
开发者ID:sshtools,项目名称:j2ssh-maverick,代码行数:25,代码来源:ZLibCompression.java

示例7: encode

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
private void encode(ByteBuf compressed) {
    try {
        byte[] out = new byte[(int) Math.ceil(z.next_in.length * 1.001) + 12];
        z.next_out = out;
        z.next_out_index = 0;
        z.avail_out = out.length;

        int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException("compression failure: " + resultCode);
        }

        if (z.next_out_index != 0) {
            compressed.writeBytes(out, 0, z.next_out_index);
        }
    } finally {
        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:25,代码来源:SpdyHeaderBlockJZlibEncoder.java

示例8: test

import com.jcraft.jzlib.JZlib; //导入依赖的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

示例9: zip

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
byte[] zip(byte[] input) {
    if (input == null) return null;

    try {
        com.jcraft.jzlib.Deflater deflater = new com.jcraft.jzlib.Deflater(6, -15, 8);
        deflater.params(6, JZlib.Z_DEFAULT_STRATEGY);

        final byte[] output = new byte[(int)(input.length * 1.1 + 16)];
        deflater.setOutput(output);
        deflater.setInput(input);
        if (deflater.deflate(JZlib.Z_SYNC_FLUSH) != JZlib.Z_OK)
            throw new GZIPException(deflater.getMessage());
        if (deflater.total_out < 4)
            throw new GZIPException("deflated output doesn't have sync marker bytes");

        final byte[] result = new byte[(int)deflater.total_out - 4];
        System.arraycopy(output, 0, result, 0, result.length);
        return result;
    } catch (GZIPException ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:APNIC-net,项目名称:repositoryd,代码行数:23,代码来源:MemoryCachedModule.java

示例10: encode

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
@Override
public void encode(ChannelBuffer compressed) {
    try {
        byte[] out = new byte[(int) Math.ceil(z.next_in.length * 1.001) + 12];
        z.next_out = out;
        z.next_out_index = 0;
        z.avail_out = out.length;

        int resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException("compression failure: " + resultCode);
        }

        if (z.next_out_index != 0) {
            compressed.writeBytes(out, 0, z.next_out_index);
        }
    } finally {
        // Deference the external references explicitly to tell the VM that
        // the allocated byte arrays are temporary so that the call stack
        // can be utilized.
        // I'm not sure if the modern VMs do this optimization though.
        z.next_in = null;
        z.next_out = null;
    }
}
 
开发者ID:jle,项目名称:andy,代码行数:26,代码来源:SpdyHeaderBlockJZlibCompressor.java

示例11: deflate

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
int deflate(byte[] buf, int off, int nbytes, int flushParam) {
    if (impl == null) {
        throw new IllegalStateException();
    }
    // avoid int overflow, check null buf
    if (off > buf.length || nbytes < 0 || off < 0 || buf.length - off < nbytes) {
        throw new ArrayIndexOutOfBoundsException();
    }

    long sin = impl.total_in;
    long sout = impl.total_out;
    impl.setOutput(buf, off, nbytes);
    int err = impl.deflate(flushParam);
    switch (err) {
        case JZlib.Z_OK:
            break;
        case JZlib.Z_STREAM_END:
            finished = true;
            break;
        default:
            throw new RuntimeException("Error: " + err);
    }

    inRead += impl.total_in - sin;
    return (int) (impl.total_out - sout);
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:27,代码来源:TDeflater.java

示例12: decompressTile

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
private static boolean decompressTile(byte[] dest, byte[] source)
	{
	    zip.next_in = source;
	    zip.avail_in = source.length;
	    zip.next_in_index = 0;
	    zip.next_out = dest;
	    zip.avail_out = dest.length;
	    zip.next_out_index=0;

	    zip.inflateInit();
	    int err = zip.inflate(JZlib.Z_FINISH);
	    if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
	    {
	    	return false;
	    }
//	    decompressed_size = (int) zip.total_out;
	    zip.inflateEnd();
	    return true;
	}
 
开发者ID:andreynovikov,项目名称:androzic-library,代码行数:20,代码来源:OzfDecoder.java

示例13: enableCompression

import com.jcraft.jzlib.JZlib; //导入依赖的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

示例14: deflate

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
/**
 * Compress the input. The result will be put in a new buffer.
 *  
 * @param inBuffer the buffer to be compressed. The contents are transferred
 * into a local byte array and the buffer is flipped and returned intact.
 * @return the buffer with the compressed data
 * @throws IOException if the compression of teh buffer failed for some reason
 * @throws IllegalStateException if the mode is not <code>MODE_DEFLATER</code>
 */
public IoBuffer deflate(IoBuffer inBuffer) throws IOException {
    if (mode == MODE_INFLATER) {
        throw new IllegalStateException("not initialized as DEFLATER");
    }

    byte[] inBytes = new byte[inBuffer.remaining()];
    inBuffer.get(inBytes).flip();

    // according to spec, destination buffer should be 0.1% larger
    // than source length plus 12 bytes. We add a single byte to safeguard
    // against rounds that round down to the smaller value
    int outLen = (int) Math.round(inBytes.length * 1.001) + 1 + 12;
    byte[] outBytes = new byte[outLen];

    synchronized (zStream) {
        zStream.next_in = inBytes;
        zStream.next_in_index = 0;
        zStream.avail_in = inBytes.length;
        zStream.next_out = outBytes;
        zStream.next_out_index = 0;
        zStream.avail_out = outBytes.length;

        int retval = zStream.deflate(JZlib.Z_SYNC_FLUSH);
        if (retval != JZlib.Z_OK) {
            outBytes = null;
            inBytes = null;
            throw new IOException("Compression failed with return value : " + retval);
        }

        IoBuffer outBuf = IoBuffer.wrap(outBytes, 0, zStream.next_out_index);

        return outBuf;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:44,代码来源:Zlib.java

示例15: compress

import com.jcraft.jzlib.JZlib; //导入依赖的package包/类
public int compress(byte[] buf, int start, int len, byte[] output) {
	deflate.next_in = buf;
	deflate.next_in_index = start;
	deflate.avail_in = len - start;

	if ((buf.length + 1024) > deflate_tmpbuf.length) {
		deflate_tmpbuf = new byte[buf.length + 1024];
	}

	deflate.next_out = deflate_tmpbuf;
	deflate.next_out_index = 0;
	deflate.avail_out = output.length;

	if (deflate.deflate(JZlib.Z_PARTIAL_FLUSH) != JZlib.Z_OK) {
		System.err.println("compress: compression failure");
	}

	if (deflate.avail_in > 0) {
		System.err.println("compress: deflated data too large");
	}

	int outputlen = output.length - deflate.avail_out;

	System.arraycopy(deflate_tmpbuf, 0, output, 0, outputlen);

	return outputlen;
}
 
开发者ID:dragonlinux,项目名称:connectbot,代码行数:28,代码来源:Zlib.java


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