本文整理汇总了Java中java.util.zip.Inflater.setInput方法的典型用法代码示例。如果您正苦于以下问题:Java Inflater.setInput方法的具体用法?Java Inflater.setInput怎么用?Java Inflater.setInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Inflater
的用法示例。
在下文中一共展示了Inflater.setInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLogoutOneLogoutRequestNotAttempted
import java.util.zip.Inflater; //导入方法依赖的package包/类
@Test
public void testLogoutOneLogoutRequestNotAttempted() throws Exception {
final String FAKE_URL = "http://url";
LogoutRequest logoutRequest = new LogoutRequest(TICKET_ID, new SimpleWebApplicationServiceImpl(FAKE_URL));
WebUtils.putLogoutRequests(this.requestContext, Arrays.asList(logoutRequest));
this.requestContext.getFlowScope().put(FrontChannelLogoutAction.LOGOUT_INDEX, 0);
final Event event = this.frontChannelLogoutAction.doExecute(this.requestContext);
assertEquals(FrontChannelLogoutAction.REDIRECT_APP_EVENT, event.getId());
List<LogoutRequest> list = WebUtils.getLogoutRequests(this.requestContext);
assertEquals(1, list.size());
final String url = (String) event.getAttributes().get("logoutUrl");
assertTrue(url.startsWith(FAKE_URL + "?SAMLRequest="));
final byte[] samlMessage = Base64.decodeBase64(URLDecoder.decode(StringUtils.substringAfter(url, "?SAMLRequest="), "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.indexOf("<samlp:SessionIndex>" + TICKET_ID + "</samlp:SessionIndex>") >= 0);
}
示例2: onMessage
import java.util.zip.Inflater; //导入方法依赖的package包/类
@Override
public void onMessage(ByteBuffer message) {
try {
//Thanks to ShadowLordAlpha for code and debugging.
//Get the compressed message and inflate it
StringBuilder builder = new StringBuilder();
Inflater decompresser = new Inflater();
byte[] bytes = message.array();
decompresser.setInput(bytes, 0, bytes.length);
byte[] result = new byte[128];
while (!decompresser.finished()) {
int resultLength = decompresser.inflate(result);
builder.append(new String(result, 0, resultLength, "UTF-8"));
}
decompresser.end();
// send the inflated message to the TextMessage method
onMessage(builder.toString());
} catch (DataFormatException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例3: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
@Override
public byte[] uncompress(byte[] data) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater decompressor = new Inflater();
try {
decompressor.setInput(data);
final byte[] buf = new byte[2048];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} catch (DataFormatException e) {
e.printStackTrace();
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例4: inflater
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* 解压缩.
*
* @param inputByte byte[]数组类型的数据
* @return 解压缩后的数据
* @throws IOException
*/
public static byte[] inflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Inflater compresser = new Inflater(false);
compresser.setInput(inputByte, 0, inputByte.length);
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.inflate(result);
if (compressedDataLength == 0) {
break;
}
o.write(result, 0, compressedDataLength);
}
} catch (Exception ex) {
System.err.println("Data format error!\n");
ex.printStackTrace();
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例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: 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();
}
示例7: inflate
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* Inflate the given byte array by {@link #INFLATED_ARRAY_LENGTH}.
*
* @param bytes the bytes
* @return the array as a string with {@code UTF-8} encoding
*/
public static String inflate(final byte[] bytes) {
final Inflater inflater = new Inflater(true);
final byte[] xmlMessageBytes = new byte[INFLATED_ARRAY_LENGTH];
final byte[] extendedBytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, extendedBytes, 0, bytes.length);
extendedBytes[bytes.length] = 0;
inflater.setInput(extendedBytes);
try {
final int resultLength = inflater.inflate(xmlMessageBytes);
inflater.end();
if (!inflater.finished()) {
throw new RuntimeException("buffer not large enough.");
}
inflater.end();
return new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8);
} catch (final DataFormatException e) {
return null;
}
}
示例8: 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();
}
示例9: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static byte[] uncompress(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();
}
示例10: decompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
static byte[] decompress(byte[] bytesIn, int offset) throws Exception {
Inflater inflater = new Inflater();
inflater.setInput(bytesIn, offset, bytesIn.length - offset);
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytesIn.length - offset);
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
stream.write(buffer, 0, count);
}
stream.close();
byte[] bytesOut = stream.toByteArray();
inflater.end();
return bytesOut;
}
示例11: deflate
import java.util.zip.Inflater; //导入方法依赖的package包/类
/** Descomprime un certificado contenido en la tarjeta CERES.
* @param compressedCertificate Certificado comprimido en ZIP a partir del 9 octeto.
* @return Certificado codificado.
* @throws IOException Cuando se produce un error en la descompresión del certificado. */
private static byte[] deflate(final byte[] compressedCertificate) throws IOException {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final Inflater decompressor = new Inflater();
decompressor.setInput(compressedCertificate, 8, compressedCertificate.length - 8);
final byte[] buf = new byte[1024];
try {
// Descomprimimos los datos
while (!decompressor.finished()) {
final int count = decompressor.inflate(buf);
if (count == 0) {
throw new DataFormatException();
}
buffer.write(buf, 0, count);
}
// Obtenemos los datos descomprimidos
return buffer.toByteArray();
}
catch (final DataFormatException ex) {
throw new IOException("Error al descomprimir el certificado: " + ex, ex); //$NON-NLS-1$
}
}
示例12: 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();
}
示例13: decompressToString
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static String decompressToString(String base64String) throws UnsupportedEncodingException, DataFormatException
{
byte[] compressedData = Base64.decodeBase64(base64String);
Inflater deCompressor = new Inflater();
deCompressor.setInput(compressedData, 0, compressedData.length);
byte[] output = new byte[1024];
int decompressedDataLength = deCompressor.inflate(output);
deCompressor.end();
return new String(output, 0, decompressedDataLength, "UTF-8");
}
示例14: refillInflater
import java.util.zip.Inflater; //导入方法依赖的package包/类
private void refillInflater(Inflater inflater) throws IOException {
while(chunkRemaining == 0) {
closeChunk();
openChunk(IDAT);
}
int read = readChunk(buffer, 0, buffer.length);
inflater.setInput(buffer, 0, read);
}
示例15: 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);
}
}