當前位置: 首頁>>代碼示例>>Java>>正文


Java Inflater.inflate方法代碼示例

本文整理匯總了Java中java.util.zip.Inflater.inflate方法的典型用法代碼示例。如果您正苦於以下問題:Java Inflater.inflate方法的具體用法?Java Inflater.inflate怎麽用?Java Inflater.inflate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.zip.Inflater的用法示例。


在下文中一共展示了Inflater.inflate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readChunkUnzip

import java.util.zip.Inflater; //導入方法依賴的package包/類
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:23,代碼來源:PNGDecoder.java

示例2: decompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
public static byte[] decompress(byte[] value) throws DataFormatException
{

    ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);

    Inflater decompressor = new Inflater();

    try
    {
        decompressor.setInput(value);

        final byte[] buf = new byte[1024];
        while (!decompressor.finished())
        {
            int count = decompressor.inflate(buf);
            bos.write(buf, 0, count);
        }
    } finally
    {
        decompressor.end();
    }

    return bos.toByteArray();
}
 
開發者ID:WeDevelopTeam,項目名稱:HeroVideo-master,代碼行數:25,代碼來源:BiliDanmukuCompressionTools.java

示例3: decompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
/**
   * Testing method for decompression of ewf file hex bytes
   * @param ewfHexStr any zlib compressed hex
   * @return decompressed string
   */
  protected static String decompress(String ewfHexStr) {
Inflater inflater = new Inflater();
byte[] input = DatatypeConverter.parseHexBinary(ewfHexStr);
inflater.setInput(input, 0, input.length);
String outputString = "empty";

byte[] result = new byte[input.length];
int resultLength;
try {
	resultLength = inflater.inflate(result);
	outputString = new String(result, 0, resultLength, "UTF-8");
} catch (DataFormatException | UnsupportedEncodingException e) {
	e.printStackTrace();
}
inflater.end();

return outputString;
  }
 
開發者ID:ciphertechsolutions,項目名稱:IO,代碼行數:24,代碼來源:CompressionTask.java

示例4: getZipString

import java.util.zip.Inflater; //導入方法依賴的package包/類
public String getZipString() {
	int length = getBInt() - 4;
	int zlength = getLInt();

	if (remaining() > length) {
		Inflater decompressor = new Inflater();
		decompressor.setInput(buffer, offset, length);
		offset += length;

		try {
			ByteArrayOutputStream bos = new ByteArrayOutputStream(zlength);
			byte[] buf = new byte[1024];
			int count;
			while ((!decompressor.finished()) && ((count = decompressor.inflate(buf)) > 0)) {
				bos.write(buf, 0, count);
			}
			decompressor.end();
			bos.close();

			return new String(bos.toByteArray(), UTF8_CHARSET);
		} catch (DataFormatException | IOException ignored) {
		}
	}

	return null;
}
 
開發者ID:Tarik02,項目名稱:cr-private-server,代碼行數:27,代碼來源:DataStream.java

示例5: verifyLogoutOneLogoutRequestNotAttempted

import java.util.zip.Inflater; //導入方法依賴的package包/類
@Test
public void verifyLogoutOneLogoutRequestNotAttempted() throws Exception {
    final LogoutRequest logoutRequest = new DefaultLogoutRequest(TICKET_ID,
            new SimpleWebApplicationServiceImpl(TEST_URL),
            new URL(TEST_URL));
    final Event event = getLogoutEvent(Arrays.asList(logoutRequest));

    assertEquals(FrontChannelLogoutAction.REDIRECT_APP_EVENT, event.getId());
    final List<LogoutRequest> list = WebUtils.getLogoutRequests(this.requestContext);
    assertEquals(1, list.size());
    final String url = (String) event.getAttributes().get(FrontChannelLogoutAction.DEFAULT_FLOW_ATTRIBUTE_LOGOUT_URL);
    assertTrue(url.startsWith(TEST_URL + "?" + FrontChannelLogoutAction.DEFAULT_LOGOUT_PARAMETER + "="));
    final byte[] samlMessage = CompressionUtils.decodeBase64ToByteArray(
            URLDecoder.decode(StringUtils.substringAfter(url, "?" + FrontChannelLogoutAction.DEFAULT_LOGOUT_PARAMETER + "="), "UTF-8"));
    final Inflater decompresser = new Inflater();
    decompresser.setInput(samlMessage);
    final byte[] result = new byte[1000];
    decompresser.inflate(result);
    decompresser.end();
    final String message = new String(result);
    assertTrue(message.startsWith("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\""));
    assertTrue(message.contains("<samlp:SessionIndex>" + TICKET_ID + "</samlp:SessionIndex>"));
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:24,代碼來源:FrontChannelLogoutActionTests.java

示例6: verifyUserSig

import java.util.zip.Inflater; //導入方法依賴的package包/類
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
	try {
		Security.addProvider(new BouncyCastleProvider());
		
		//DeBaseUrl64 urlSig to json
		Base64 decoder = new Base64();

		byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
		
		//Decompression
		Inflater decompression =  new Inflater();
		decompression.setInput(compressBytes, 0, compressBytes.length);
		byte [] decompressBytes = new byte [1024];
		int decompressLength = decompression.inflate(decompressBytes);
		decompression.end();
		
		String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
		
		//Get TLS.Sig from json
		JSONObject jsonObject= JSON.parseObject(jsonString);
		String sigTLS = jsonObject.getString("TLS.sig");
		
		//debase64 TLS.Sig to get serailString
		byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
		
		String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
		String sigTime = jsonObject.getString("TLS.time");
		String sigExpire = jsonObject.getString("TLS.expire_after");
		
		if (!imConfig.getSdkAppId().equals(strSdkAppid))
		{
			return false;
		}

		if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
			return false;
		}
		
		//Get Serial String from json
		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:" + sigTime + "\n" + 
			"TLS.expire_after:" + sigExpire + "\n";
	
        Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
        PEMParser  parser = new PEMParser(reader);
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object obj = parser.readObject();
        parser.close();
        PublicKey pubKeyStruct  = converter.getPublicKey((SubjectPublicKeyInfo) obj);

		Signature signature = Signature.getInstance("SHA256withECDSA","BC");
		signature.initVerify(pubKeyStruct);
		signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
		return signature.verify(signatureBytes);
	}catch (Exception e) {
		throw new QCloudException(e);
	}
}
 
開發者ID:51wakeup,項目名稱:wakeup-qcloud-sdk,代碼行數:64,代碼來源:DefaultQCloudClient.java

示例7: decodeURLBase64DeflateString

import java.util.zip.Inflater; //導入方法依賴的package包/類
private String decodeURLBase64DeflateString(final String input)
        throws UnsupportedEncodingException, DataFormatException {
    String urlDecoded = URLDecoder.decode(input, "UTF-8");
    byte[] base64Decoded = Base64.decodeBase64(urlDecoded);

    Inflater decompresser = new Inflater(true);
    decompresser.setInput(base64Decoded);
    StringBuilder result = new StringBuilder();

    while (!decompresser.finished()) {
        byte[] outputFraction = new byte[base64Decoded.length];
        int resultLength = decompresser.inflate(outputFraction);
        result.append(new String(outputFraction, 0, resultLength, "UTF-8"));
    }

    return result.toString();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:RedirectEncoderTest.java

示例8: uncompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
public static byte[] uncompress(final byte[] input) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Inflater decompressor = new Inflater();
    try {
        decompressor.setInput(input);
        final byte[] buf = new byte[2048];
        while (!decompressor.finished()) {
            int count = 0;
            try {
                count = decompressor.inflate(buf);
            } catch (DataFormatException e) {
                e.printStackTrace();
            }
            bos.write(buf, 0, count);
        }
    } finally {
        decompressor.end();
    }
    return bos.toByteArray();
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:21,代碼來源:LogUtils.java

示例9: decompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
/** Decompress the byte array previously returned by
 *  compress */
public static byte[] decompress(byte[] value, int offset, int length) throws DataFormatException {
  // Create an expandable byte array to hold the decompressed data
  ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

  Inflater decompressor = new Inflater();

  try {
    decompressor.setInput(value, offset, length);

    // Decompress the data
    final byte[] buf = new byte[1024];
    while (!decompressor.finished()) {
      int count = decompressor.inflate(buf);
      bos.write(buf, 0, count);
    }
  } finally {  
    decompressor.end();
  }
  
  return bos.toByteArray();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:CompressionTools.java

示例10: b

import java.util.zip.Inflater; //導入方法依賴的package包/類
public static byte[] b(byte[] bArr) throws UnsupportedEncodingException, DataFormatException {
    int i = 0;
    if (bArr == null || bArr.length == 0) {
        return null;
    }
    Inflater inflater = new Inflater();
    inflater.setInput(bArr, 0, bArr.length);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byte[] bArr2 = new byte[1024];
    while (!inflater.needsInput()) {
        int inflate = inflater.inflate(bArr2);
        byteArrayOutputStream.write(bArr2, i, inflate);
        i += inflate;
    }
    inflater.end();
    return byteArrayOutputStream.toByteArray();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:bs.java

示例11: readChunkUnzip

import java.util.zip.Inflater; //導入方法依賴的package包/類
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
    assert(buffer != this.buffer);
    try {
        do {
            int read = inflater.inflate(buffer, offset, length);
            if(read <= 0) {
                if(inflater.finished()) {
                    throw new EOFException();
                }
                if(inflater.needsInput()) {
                    refillInflater(inflater);
                } else {
                    throw new IOException("Can't inflate " + length + " bytes");
                }
            } else {
                offset += read;
                length -= read;
            }
        } while(length > 0);
    } catch (DataFormatException ex) {
        throw (IOException)(new IOException("inflate error").initCause(ex));
    }
}
 
開發者ID:DaanVanYperen,項目名稱:odb-artax,代碼行數:24,代碼來源:PNGDecoder.java

示例12: decompressForZlib

import java.util.zip.Inflater; //導入方法依賴的package包/類
/**
 * zlib decompress 2 byte
 *
 * @param bytesToDecompress byte[]
 * @return byte[]
 */
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
    byte[] returnValues = null;

    Inflater inflater = new Inflater();

    int numberOfBytesToDecompress = bytesToDecompress.length;

    inflater.setInput(bytesToDecompress, 0, numberOfBytesToDecompress);

    int numberOfBytesDecompressedSoFar = 0;
    List<Byte> bytesDecompressedSoFar = new ArrayList<>();

    try {
        while (!inflater.needsInput()) {
            byte[] bytesDecompressedBuffer = new byte[numberOfBytesToDecompress];

            int numberOfBytesDecompressedThisTime = inflater.inflate(bytesDecompressedBuffer);

            numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;

            for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
                bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
            }
        }

        returnValues = new byte[bytesDecompressedSoFar.size()];
        for (int b = 0; b < returnValues.length; b++) {
            returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
        }

    } catch (DataFormatException dfe) {
        dfe.printStackTrace();
    }

    inflater.end();
    return returnValues;
}
 
開發者ID:xiaobailong24,項目名稱:MVVMArms,代碼行數:44,代碼來源:ZipHelper.java

示例13: inflate

import java.util.zip.Inflater; //導入方法依賴的package包/類
/**
 * Utility method to decompress a compressed byte array, using the given {@link Inflater}.
 * @param source The compressed array.
 * @param off The offset in {@code source}.
 * @param len The number of bytes in {@code source}.
 * @param infl The inflater to use for decompression.
 * @return The decompressed byte array.
 * @throws IOException If input array contains invalid data.
 */
public static byte[] inflate(byte[] source, int off, int len, Inflater infl) throws IOException {
	infl.setInput(source, off, len);
	byte[] buf = new byte[1024];
	try (DirectByteArrayOutputStream bos = new DirectByteArrayOutputStream(buf.length)) {
		int n;
		while ((n = infl.inflate(buf)) > 0)
			bos.write(buf, 0, n);
		return Arrays.copyOf(bos.toByteArray(), bos.size());
	} catch (DataFormatException e) {
		throw new IOException("Cannot inflate data: "+e.getMessage(), e);
	}
}
 
開發者ID:matthieu-labas,項目名稱:JRF,代碼行數:22,代碼來源:Utils.java

示例14: decompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
static byte[] decompress(byte[] data) throws IOException, DataFormatException {
	Inflater inflater = new Inflater(true);
	inflater.setInput(data);
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
	byte[] buffer = new byte[1024];
	while (!inflater.finished()) {
		int count = inflater.inflate(buffer);
		outputStream.write(buffer, 0, count);
	}
	outputStream.close();
	byte[] output = outputStream.toByteArray();
	Log.d("Compressor", "Original: " + data.length);
	Log.d("Compressor", "Decompressed: " + output.length);
	return output;
}
 
開發者ID:SapuSeven,項目名稱:NotiCap,代碼行數:16,代碼來源:Compressor.java

示例15: uncompress

import java.util.zip.Inflater; //導入方法依賴的package包/類
/**
 * Decompress realFrameSize bytes to decompressedFrameSize bytes and return as ByteBuffer
 *
 * @param byteBuffer
 * @param decompressedFrameSize
 * @param realFrameSize
 * @return
 * @throws org.jaudiotagger.tag.InvalidFrameException
 */
protected static ByteBuffer uncompress(String identifier, String filename, ByteBuffer byteBuffer, int decompressedFrameSize, int realFrameSize) throws InvalidFrameException {
    logger.config(filename + ":About to decompress " + realFrameSize + " bytes, expect result to be:" + decompressedFrameSize + " bytes");
    // Decompress the bytes into this buffer, size initialized from header field
    byte[] result = new byte[decompressedFrameSize];
    byte[] input = new byte[realFrameSize];

    //Store position ( just after frame header and any extra bits)
    //Read frame data into array, and then put buffer back to where it was
    int position = byteBuffer.position();
    byteBuffer.get(input, 0, realFrameSize);
    byteBuffer.position(position);

    Inflater decompresser = new Inflater();
    decompresser.setInput(input);
    try {
        int inflatedTo = decompresser.inflate(result);
        logger.config(filename + ":Decompressed to " + inflatedTo + " bytes");
    } catch (DataFormatException dfe) {
        logger.log(Level.CONFIG, "Unable to decompress this frame:" + identifier, dfe);

        //Update position of main buffer, so no attempt is made to reread these bytes
        byteBuffer.position(byteBuffer.position() + realFrameSize);
        throw new InvalidFrameException(ErrorMessage.ID3_UNABLE_TO_DECOMPRESS_FRAME.getMsg(identifier, filename, dfe.getMessage()));
    }
    decompresser.end();
    return ByteBuffer.wrap(result);
}
 
開發者ID:openaudible,項目名稱:openaudible,代碼行數:37,代碼來源:ID3Compression.java


注:本文中的java.util.zip.Inflater.inflate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。