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


Java Deflater.finish方法代码示例

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


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

示例1: getDeflated

import java.util.zip.Deflater; //导入方法依赖的package包/类
protected byte[] getDeflated(String s) {
    byte[] content = s.getBytes();

    ByteArrayOutputStream output = new ByteArrayOutputStream(content.length);
    Deflater deflater = new Deflater();
    deflater.setInput(content);
    deflater.finish();

    byte[] buffer = new byte[1024];
    while (!deflater.finished()) {
        int count = deflater.deflate(buffer);
        output.write(buffer, 0, count);
    }

    return output.toByteArray();
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:17,代码来源:RestClientTestBase.java

示例2: compressForZlib

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * zlib compress 2 byte
 *
 * @param bytesToCompress
 * @return
 */
public static byte[] compressForZlib(byte[] bytesToCompress) {
    Deflater deflater = new Deflater();
    deflater.setInput(bytesToCompress);
    deflater.finish();

    byte[] bytesCompressed = new byte[Short.MAX_VALUE];

    int numberOfBytesAfterCompression = deflater.deflate(bytesCompressed);

    byte[] returnValues = new byte[numberOfBytesAfterCompression];

    System.arraycopy
            (
                    bytesCompressed,
                    0,
                    returnValues,
                    0,
                    numberOfBytesAfterCompression
            );

    return returnValues;
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:29,代码来源:ZipHelper.java

示例3: deflater

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * 压缩.
 * 
 * @param inputByte
 *            需要解压缩的byte[]数组
 * @return 压缩后的数据
 * @throws IOException
 */
public static byte[] deflater(final byte[] inputByte) throws IOException {
	int compressedDataLength = 0;
	Deflater compresser = new Deflater();
	compresser.setInput(inputByte);
	compresser.finish();
	ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
	byte[] result = new byte[1024];
	try {
		while (!compresser.finished()) {
			compressedDataLength = compresser.deflate(result);
			o.write(result, 0, compressedDataLength);
		}
	} finally {
		o.close();
	}
	compresser.end();
	return o.toByteArray();
}
 
开发者ID:wangfei0904306,项目名称:unionpay,代码行数:27,代码来源:SDKUtil.java

示例4: deflater

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * 压缩.
 *
 * @param inputByte 需要解压缩的byte[]数组
 * @return 压缩后的数据
 * @throws IOException
 */
public static byte[] deflater(final byte[] inputByte) throws IOException {
    int compressedDataLength = 0;
    Deflater compresser = new Deflater();
    compresser.setInput(inputByte);
    compresser.finish();
    ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
    byte[] result = new byte[1024];
    try {
        while (!compresser.finished()) {
            compressedDataLength = compresser.deflate(result);
            o.write(result, 0, compressedDataLength);
        }
    } finally {
        o.close();
    }
    compresser.end();
    return o.toByteArray();
}
 
开发者ID:howe,项目名称:nutz-pay,代码行数:26,代码来源:SDKUtil.java

示例5: compress

import java.util.zip.Deflater; //导入方法依赖的package包/类
static byte[] compress(byte[] bytesIn) {
    Deflater deflater = new Deflater();
    deflater.setInput(bytesIn);
    ByteArrayOutputStream stream = new ByteArrayOutputStream(bytesIn.length);
    byte[] buffer = new byte[1024];

    deflater.finish();
    while (!deflater.finished()) {
        int count = deflater.deflate(buffer);
        stream.write(buffer, 0, count);
    }

    try {
        stream.close();
    } catch (IOException ex) {
        return bytesIn;
    }

    byte[] bytesOut = stream.toByteArray();
    deflater.end();

    return bytesOut;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ZipPlugin.java

示例6: zlibCompress

import java.util.zip.Deflater; //导入方法依赖的package包/类
public DataStream zlibCompress() {
	Deflater compressor = new Deflater();
	compressor.setInput(this.get());

	this.reset();
	this.put(Hex.toByteArray("0178040000")); // size?!

	byte[] buf = new byte[1024];
	int length = 0;

	compressor.finish();
	while (!compressor.finished()) {
		int count = compressor.deflate(buf);
		this.put(buf, 0, count);
		length += count;
	}
	compressor.end();

	return this;
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:21,代码来源:DataStream.java

示例7: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
    Deflater deflater = new Deflater(level);
    deflater.reset();
    deflater.setInput(data);
    deflater.finish();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
    byte[] buf = new byte[1024];
    try {
        while (!deflater.finished()) {
            int i = deflater.deflate(buf);
            bos.write(buf, 0, i);
        }
    } finally {
        deflater.end();
    }
    return bos.toByteArray();
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:18,代码来源:Zlib.java

示例8: compress

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {

    ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

    Deflater compressor = new Deflater();

    try {
      compressor.setLevel(compressionLevel); // 将当前压缩级别设置为指定值。
      compressor.setInput(value, offset, length);
      compressor.finish(); // 调用时,指示压缩应当以输入缓冲区的当前内容结尾。

      // Compress the data
      final byte[] buf = new byte[1024];
      while (!compressor.finished()) {
        // 如果已到达压缩数据输出流的结尾,则返回 true。
        int count = compressor.deflate(buf);
        // 使用压缩数据填充指定缓冲区。
        bos.write(buf, 0, count);
      }
    } finally {
      compressor.end(); // 关闭解压缩器并放弃所有未处理的输入。
    }

    return bos.toByteArray();
  }
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:26,代码来源:BiliDanmukuCompressionTools.java

示例9: dumpFlate

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * Write the entire content into the given file using Flate compression (see
 * RFC1951) then return the number of bytes written.
 */
public long dumpFlate(RandomAccessFile os) throws IOException {
	Deflater zip = new Deflater(Deflater.BEST_COMPRESSION);
	byte[] output = new byte[8192];
	Iterator<byte[]> it = list.iterator(); // when null, that means we have
											// told the Deflater that no
											// more input would be coming
	long ans = 0; // the number of bytes written out so far
	while (true) {
		if (it != null && zip.needsInput() && it.hasNext()) {
			byte[] in = it.next();
			if (in == list.getLast()) {
				zip.setInput(in, 0, n);
				it = null;
				zip.finish();
			} else {
				zip.setInput(in, 0, SIZE);
			}
		}
		if (it == null && zip.finished())
			break;
		int count = zip.deflate(output);
		if (count > 0) {
			ans = ans + count;
			if (ans < 0)
				throw new IOException("Data too large to be written to the output file.");
			os.write(output, 0, count);
		}
	}
	return ans;
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:35,代码来源:ByteBuffer.java

示例10: binaryEncode

import java.util.zip.Deflater; //导入方法依赖的package包/类
private String binaryEncode(String tag) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Deflater deflater = new Deflater();
    deflater.setInput(tag.getBytes());
    deflater.finish();
    byte[] buffer = new byte[1024];
    while (!deflater.finished()) {
        int count = deflater.deflate(buffer);
        outputStream.write(buffer, 0, count);
    }
    outputStream.close();
    byte compressed[] = outputStream.toByteArray();
    return bytesToHex(compressed);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:15,代码来源:RegistrationManager.java

示例11: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
    Deflater deflater = getDef(level);
    if (deflater == null) throw new IllegalArgumentException("No deflate for level " + level + " !");
    deflater.reset();
    deflater.setInput(data);
    deflater.finish();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
    while (!deflater.finished()) {
        int i = deflater.deflate(buf.get());
        bos.write(buf.get(), 0, i);
    }
    //Deflater::end is called the time when the process exits.
    return bos.toByteArray();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:Zlib.java

示例12: call

import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public DataChunk call() throws Exception {
    Deflater deflater = new Deflater(compressionLevel);
    deflater.setInput(input);
    deflater.finish();
    byte[] output = new byte[input.length + 4];
    int compressedSize = deflater.deflate(output);
    //Unlikely, but possible.
    if (compressedSize >= input.length) {
        System.arraycopy(input, 0, output, 0, input.length);
        System.arraycopy(ByteUtils.intToBytes(deflater.getAdler()), 0, output, input.length, 4);
        return new DataChunk(input.length, output, false);
    }
    return new DataChunk(input.length, Arrays.copyOf(output, compressedSize), true);
}
 
开发者ID:ciphertechsolutions,项目名称:IO,代码行数:16,代码来源:CompressionTask.java

示例13: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
protected static byte[] deflate(byte[] toCompress) {
       Deflater deflater = new Deflater();
       deflater.setInput(toCompress);
       deflater.finish();
       byte[] output = new byte[toCompress.length];
       int compressedSize = deflater.deflate(output);
       //TODO: Determine if we need to append the adler-32 hash.
       return Arrays.copyOf(output, compressedSize);
}
 
开发者ID:ciphertechsolutions,项目名称:IO,代码行数:10,代码来源:AbstractHeaderSection.java

示例14: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * Deflate the given string via a {@link java.util.zip.Deflater}.
 *
 * @param data the data
 * @return base64 encoded string
 */
public static String deflate(final String data) {
    final Deflater deflater = new Deflater();
    deflater.setInput(data.getBytes(StandardCharsets.UTF_8));
    deflater.finish();
    final byte[] buffer = new byte[data.length()];
    final int resultSize = deflater.deflate(buffer);
    final byte[] output = new byte[resultSize];
    System.arraycopy(buffer, 0, output, 0, resultSize);
    return EncodingUtils.encodeBase64(output);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:CompressionUtils.java

示例15: createFrontChannelLogoutMessage

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * Create a logout message for front channel logout.
 *
 * @param logoutRequest the logout request.
 * @return a front SAML logout message.
 */
public String createFrontChannelLogoutMessage(final LogoutRequest logoutRequest) {
    final String logoutMessage = this.logoutMessageBuilder.create(logoutRequest);
    final Deflater deflater = new Deflater();
    deflater.setInput(logoutMessage.getBytes(ASCII));
    deflater.finish();
    final byte[] buffer = new byte[logoutMessage.length()];
    final int resultSize = deflater.deflate(buffer);
    final byte[] output = new byte[resultSize];
    System.arraycopy(buffer, 0, output, 0, resultSize);
    return Base64.encodeBase64String(output);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:18,代码来源:LogoutManagerImpl.java


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