本文整理汇总了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));
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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));
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}