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


Java JZlib.Z_OK属性代码示例

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


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

示例1: compress

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,代码行数:22,代码来源:ZlibCompressor.java

示例2: uncompress

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,代码行数:22,代码来源:ZlibCompressor.java

示例3: process

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,代码行数:22,代码来源:ZLibCodecompressor.java

示例4: compress

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,代码行数:24,代码来源:ZLibCompression.java

示例5: encode

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,代码行数:24,代码来源:SpdyHeaderBlockJZlibEncoder.java

示例6: zip

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,代码行数:22,代码来源:MemoryCachedModule.java

示例7: encode

@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,代码行数:25,代码来源:SpdyHeaderBlockJZlibCompressor.java

示例8: deflate

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,代码行数:26,代码来源:TDeflater.java

示例9: decompressTile

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,代码行数:19,代码来源:OzfDecoder.java

示例10: deflate

/**
 * 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,代码行数:43,代码来源:Zlib.java

示例11: compress

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,代码行数:27,代码来源:Zlib.java

示例12: compress

@Override
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:jianlinwei,项目名称:sshtunnel,代码行数:28,代码来源:Zlib.java

示例13: SpdyHeaderBlockJZlibEncoder

SpdyHeaderBlockJZlibEncoder(
        SpdyVersion version, int compressionLevel, int windowBits, int memLevel) {
    super(version);
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    if (windowBits < 9 || windowBits > 15) {
        throw new IllegalArgumentException(
                "windowBits: " + windowBits + " (expected: 9-15)");
    }
    if (memLevel < 1 || memLevel > 9) {
        throw new IllegalArgumentException(
                "memLevel: " + memLevel + " (expected: 1-9)");
    }

    int resultCode = z.deflateInit(
            compressionLevel, windowBits, memLevel, JZlib.W_ZLIB);
    if (resultCode != JZlib.Z_OK) {
        throw new CompressionException(
                "failed to initialize an SPDY header block deflater: " + resultCode);
    } else {
        resultCode = z.deflateSetDictionary(SPDY_DICT, SPDY_DICT.length);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException(
                    "failed to set the SPDY dictionary: " + resultCode);
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:29,代码来源:SpdyHeaderBlockJZlibEncoder.java

示例14: JZlibDecoder

/**
 * Creates a new instance with the specified wrapper.
 *
 * @throws DecompressionException if failed to initialize zlib
 */
public JZlibDecoder(ZlibWrapper wrapper) {
    if (wrapper == null) {
        throw new NullPointerException("wrapper");
    }

    int resultCode = z.init(ZlibUtil.convertWrapperType(wrapper));
    if (resultCode != JZlib.Z_OK) {
        ZlibUtil.fail(z, "initialization failure", resultCode);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:15,代码来源:JZlibDecoder.java

示例15: JZlibEncoder

/**
 * Creates a new zlib encoder with the specified {@code compressionLevel},
 * the specified {@code windowBits}, the specified {@code memLevel}, and
 * the specified wrapper.
 *
 * @param compressionLevel
 *        {@code 1} yields the fastest compression and {@code 9} yields the
 *        best compression.  {@code 0} means no compression.  The default
 *        compression level is {@code 6}.
 * @param windowBits
 *        The base two logarithm of the size of the history buffer.  The
 *        value should be in the range {@code 9} to {@code 15} inclusive.
 *        Larger values result in better compression at the expense of
 *        memory usage.  The default value is {@code 15}.
 * @param memLevel
 *        How much memory should be allocated for the internal compression
 *        state.  {@code 1} uses minimum memory and {@code 9} uses maximum
 *        memory.  Larger values result in better and faster compression
 *        at the expense of memory usage.  The default value is {@code 8}
 *
 * @throws CompressionException if failed to initialize zlib
 */
public JZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {

    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel +
                " (expected: 0-9)");
    }
    if (windowBits < 9 || windowBits > 15) {
        throw new IllegalArgumentException(
                "windowBits: " + windowBits + " (expected: 9-15)");
    }
    if (memLevel < 1 || memLevel > 9) {
        throw new IllegalArgumentException(
                "memLevel: " + memLevel + " (expected: 1-9)");
    }
    if (wrapper == null) {
        throw new NullPointerException("wrapper");
    }
    if (wrapper == ZlibWrapper.ZLIB_OR_NONE) {
        throw new IllegalArgumentException(
                "wrapper '" + ZlibWrapper.ZLIB_OR_NONE + "' is not " +
                "allowed for compression.");
    }

    int resultCode = z.init(
            compressionLevel, windowBits, memLevel,
            ZlibUtil.convertWrapperType(wrapper));
    if (resultCode != JZlib.Z_OK) {
        ZlibUtil.fail(z, "initialization failure", resultCode);
    }

    wrapperOverhead = ZlibUtil.wrapperOverhead(wrapper);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:55,代码来源:JZlibEncoder.java


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