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


Java Deflater.deflate方法代码示例

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


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

示例1: 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:yangxp108,项目名称:MVPArms_Fragment-fragment,代码行数:29,代码来源:ZipHelper.java

示例2: zipCompression

import java.util.zip.Deflater; //导入方法依赖的package包/类
private String zipCompression(String data) throws UnsupportedEncodingException, IOException {
	Deflater zipDeflater = new Deflater();
	ByteArrayOutputStream stream = new ByteArrayOutputStream();
	try {
		zipDeflater.setInput(getBytes(data));
		zipDeflater.finish();
		byte[] buffer = new byte[1024];
		int count = 0;
		while (!zipDeflater.finished()) {
			count = zipDeflater.deflate(buffer);
			stream.write(buffer, 0, count);
		}
		return new String(Base64.getEncoder().encode(stream.toByteArray()), LOCAL_ENCODING);
	} finally {
		stream.close();
		zipDeflater.end();
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:19,代码来源:CompressionTransformer.java

示例3: compressBytes

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static DeflaterInflaterData compressBytes(byte[] input) {
  Deflater compresser = new Deflater();
  compresser.setInput(input);
  compresser.finish();
  byte[] buffer = new byte[100];
  byte[] result = new byte[0];
  int compressedDataLength = 0;
  int totalCompressedDataLength = 0;
  do {
    byte[] newResult = new byte[result.length + buffer.length];
    System.arraycopy(result, 0, newResult, 0, result.length);

    compressedDataLength = compresser.deflate(buffer);
    totalCompressedDataLength += compressedDataLength;
    // System.out.println(compressedDataLength);
    // System.out.println("uc: b "+buffer.length);
    // System.out.println("uc: r "+result.length);
    // System.out.println("uc: nr "+newResult.length);
    // System.out.println();
    System.arraycopy(buffer, 0, newResult, result.length, buffer.length);
    result = newResult;
  } while (compressedDataLength != 0);
  return new DeflaterInflaterData(totalCompressedDataLength, result);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:CliUtil.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:Javen205,项目名称:IJPay,代码行数:27,代码来源:SDKUtil.java

示例5: 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

示例6: storeData

import java.util.zip.Deflater; //导入方法依赖的package包/类
private void storeData(ByteBuffer data) {
    try {
        final byte[] input = data.array();
        FileOutputStream fos = new FileOutputStream(file);

        final Deflater deflater = new Deflater(Deflater.BEST_SPEED, true);
        deflater.setInput(input, data.arrayOffset(), data.remaining());
        deflater.finish();

        byte[] buf = new byte[1024];
        while (!deflater.finished()) {
            int byteCount = deflater.deflate(buf);
            fos.write(buf, 0, byteCount);
        }
        deflater.end();

        fos.close();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:22,代码来源:Slice.java

示例7: compress

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static String compress(String stringToCompress) throws UnsupportedEncodingException
{
    byte[] compressedData = new byte[1024];
    byte[] stringAsBytes = stringToCompress.getBytes("UTF-8");

    Deflater compressor = new Deflater();
    compressor.setInput(stringAsBytes);
    compressor.finish();
    int compressedDataLength = compressor.deflate(compressedData);

    byte[] bytes = Arrays.copyOf(compressedData, compressedDataLength);
    return Base64.encodeBase64String(bytes);
}
 
开发者ID:tmobile,项目名称:keybiner,代码行数:14,代码来源:Compression.java

示例8: compress

import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public byte[] compress(byte[] data) throws IOException {
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	Deflater compressor = new Deflater(1);
	
	try {
		compressor.setInput(data);
		compressor.finish();
		final byte[] buf = new byte[2048];
		while (!compressor.finished()) {
			int count = compressor.deflate(buf);
			bos.write(buf, 0, count);
		}
	} finally {
		compressor.end();
	}
	
	return bos.toByteArray();
}
 
开发者ID:yu120,项目名称:compress,代码行数:20,代码来源:DeflaterCompress.java

示例9: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static DeflateResult deflate(ByteBuffer input) {
    byte[] inputBuf;
    int inputOffset;
    int inputLength = input.remaining();
    if (input.hasArray()) {
        inputBuf = input.array();
        inputOffset = input.arrayOffset() + input.position();
        input.position(input.limit());
    } else {
        inputBuf = new byte[inputLength];
        inputOffset = 0;
        input.get(inputBuf);
    }
    CRC32 crc32 = new CRC32();
    crc32.update(inputBuf, inputOffset, inputLength);
    long crc32Value = crc32.getValue();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Deflater deflater = new Deflater(9, true);
    deflater.setInput(inputBuf, inputOffset, inputLength);
    deflater.finish();
    byte[] buf = new byte[65536];
    while (!deflater.finished()) {
        int chunkSize = deflater.deflate(buf);
        out.write(buf, 0, chunkSize);
    }
    return new DeflateResult(inputLength, crc32Value, out.toByteArray());
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:28,代码来源:ZipUtils.java

示例10: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
 * Deflate the given string via a {@link java.util.zip.Deflater}.
 * The result will be base64 encoded with {@link #UTF8_ENCODING}.
 *
 * @param data the data
 * @return base64 encoded string
 */
public static String deflate(final String data) {
    try {
        final Deflater deflater = new Deflater();
        deflater.setInput(data.getBytes(UTF8_ENCODING));
        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 encodeBase64(output);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException("Cannot find encoding:" + UTF8_ENCODING, e);
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:22,代码来源:CompressionUtils.java

示例11: compress

import java.util.zip.Deflater; //导入方法依赖的package包/类
/** Compresses the specified byte range using the
 *  specified compressionLevel (constants are defined in
 *  java.util.zip.Deflater). */
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {

  /* Create an expandable byte array to hold the compressed data.
   * You cannot use an array that's the same size as the orginal because
   * there is no guarantee that the compressed data will be smaller than
   * the uncompressed data. */
  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()) {
      int count = compressor.deflate(buf);
      bos.write(buf, 0, count);
    }
  } finally {
    compressor.end();
  }

  return bos.toByteArray();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:CompressionTools.java

示例12: getUserSig

import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public String getUserSig(String identifier, long expire)throws QCloudException {
	try {
		 	Security.addProvider(new BouncyCastleProvider());
	        Reader reader = new CharArrayReader(imConfig.getPrivateKey().toCharArray());
	        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
	        PEMParser parser = new PEMParser(reader);
	        Object obj = parser.readObject();
	        parser.close();
	    	PrivateKey privKeyStruct = converter.getPrivateKey((PrivateKeyInfo) obj);
			
			String jsonString = "{" 
			+ "\"TLS.account_type\":\"" + 0 +"\","
			+"\"TLS.identifier\":\"" + identifier +"\","
			+"\"TLS.appid_at_3rd\":\"" + 0 +"\","
		    +"\"TLS.sdk_appid\":\"" + imConfig.getSdkAppId() +"\","
			+"\"TLS.expire_after\":\"" + expire +"\","
	        +"\"TLS.version\": \"201512300000\""
			+"}";
			
			String time = String.valueOf(System.currentTimeMillis()/1000);
			String SerialString = 
				"TLS.appid_at_3rd:" + 0 + "\n" +
				"TLS.account_type:" + 0 + "\n" +
				"TLS.identifier:" + identifier + "\n" + 
				"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" + 
				"TLS.time:" + time + "\n" +
				"TLS.expire_after:" + expire +"\n";
			
			//Create Signature by SerialString
			Signature signature = Signature.getInstance("SHA256withECDSA", "BC");
			signature.initSign(privKeyStruct);
			signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
			byte[] signatureBytes = signature.sign();
			
			String sigTLS = Base64.encodeBase64String(signatureBytes);
			
			//Add TlsSig to jsonString
		    JSONObject jsonObject= JSON.parseObject(jsonString);
		    jsonObject.put("TLS.sig", (Object)sigTLS);
		    jsonObject.put("TLS.time", (Object)time);
		    jsonString = jsonObject.toString();
		    
		    //compression
		    Deflater compresser = new Deflater();
		    compresser.setInput(jsonString.getBytes(Charset.forName("UTF-8")));

		    compresser.finish();
		    byte [] compressBytes = new byte [512];
		    int compressBytesLength = compresser.deflate(compressBytes);
		    compresser.end();
		    return new String(Base64Url.base64EncodeUrl(Arrays.copyOfRange(compressBytes,0,compressBytesLength)));
	}catch (Exception e) {
		throw new  QCloudException(e);
	}
}
 
开发者ID:51wakeup,项目名称:wakeup-qcloud-sdk,代码行数:57,代码来源:DefaultQCloudClient.java

示例13: deflateAndBase64

import java.util.zip.Deflater; //导入方法依赖的package包/类
private String deflateAndBase64(final String data) {
    try {
        final Deflater deflater = new Deflater();
        deflater.setInput(data.getBytes(HttpConstants.UTF8_ENCODING));
        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 DatatypeConverter.printBase64Binary(output);
    } catch (final UnsupportedEncodingException e) {
        throw new RuntimeException("Cannot find encoding:" + HttpConstants.UTF8_ENCODING, e);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:15,代码来源:CasClientTests.java

示例14: 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

示例15: 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


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