use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project ambry by linkedin.
the class GCMCryptoService method decrypt.
@Override
public ByteBuf decrypt(ByteBuf toDecrypt, SecretKeySpec key) throws GeneralSecurityException {
ByteBuf decryptedContent = null;
ByteBuf temp = null;
try {
Cipher decrypter = Cipher.getInstance(GCM_CRYPTO_INSTANCE, "BC");
byte[] iv = deserializeIV(new ByteBufInputStream(toDecrypt));
decrypter.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
int outputSize = decrypter.getOutputSize(toDecrypt.readableBytes());
decryptedContent = PooledByteBufAllocator.DEFAULT.ioBuffer(outputSize);
ByteBuffer toDecryptBuffer;
if (toDecrypt.nioBufferCount() != 1) {
temp = PooledByteBufAllocator.DEFAULT.ioBuffer(toDecrypt.readableBytes());
temp.writeBytes(toDecrypt);
toDecryptBuffer = temp.nioBuffer();
} else {
toDecryptBuffer = toDecrypt.nioBuffer();
}
ByteBuffer decryptedContentBuffer = decryptedContent.nioBuffer(0, outputSize);
int n = decrypter.doFinal(toDecryptBuffer, decryptedContentBuffer);
decryptedContent.writerIndex(decryptedContent.writerIndex() + n);
toDecrypt.skipBytes(toDecrypt.readableBytes());
return decryptedContent;
} catch (Exception e) {
if (toDecrypt != null) {
toDecrypt.release();
}
throw new GeneralSecurityException("Exception thrown while decrypting data", e);
} finally {
if (temp != null) {
temp.release();
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project MysticTools by binary404.
the class Utils method readCompoundNBTFromBuffer.
public static CompoundTag readCompoundNBTFromBuffer(FriendlyByteBuf bb) {
int i = bb.readerIndex();
byte b0 = bb.readByte();
if (b0 == 0) {
return null;
}
bb.readerIndex(i);
try {
return NbtIo.read((DataInput) new ByteBufInputStream(bb), new NbtAccounter(2097152L));
} catch (IOException iOException) {
return null;
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project resteasy by resteasy.
the class NettyHttpRequest method setContentBuffer.
public void setContentBuffer(ByteBuf content) {
this.content = content;
this.inputStream = new ByteBufInputStream(content);
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project resteasy by resteasy.
the class VertxRequestHandler method handle.
@Override
public void handle(HttpServerRequest request) {
request.bodyHandler(buff -> {
Context ctx = vertx.getOrCreateContext();
ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request, servletMappingPrefix);
HttpServerResponse response = request.response();
VertxHttpResponse vertxResponse = new VertxHttpResponse(response, dispatcher.getProviderFactory(), request.method());
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx, request, uriInfo, dispatcher.getDispatcher(), vertxResponse, false);
if (buff.length() > 0) {
ByteBufInputStream in = new ByteBufInputStream(buff.getByteBuf());
vertxRequest.setInputStream(in);
}
try {
dispatcher.service(ctx, request, response, vertxRequest, vertxResponse, true);
} catch (Failure e1) {
vertxResponse.setStatus(e1.getErrorCode());
} catch (Exception ex) {
vertxResponse.setStatus(500);
LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), ex);
}
if (!vertxRequest.getAsyncContext().isSuspended()) {
try {
vertxResponse.finish();
} catch (IOException e) {
LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), e);
}
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project eblocker by eblocker.
the class CompressProcessorTest method testBrotliRecompressionGZIP.
@Test
public void testBrotliRecompressionGZIP() throws IOException {
Mockito.when(featureService.getCompressionMode()).thenReturn(CompressionMode.ALWAYS);
Transaction transaction = makeTransaction(UNCOMPRESSED_CONTENT, ContentEncoding.BROTLI, "abc");
transaction.getRequest().headers().set("Accept-Encoding", "x-bzip, gzip, deflate");
processor.process(transaction);
InputStream in = new GZIPInputStream(new ByteBufInputStream(transaction.getResponse().content()));
byte[] uncompressedResponse = ByteStreams.toByteArray(in);
Assert.assertArrayEquals(UNCOMPRESSED, uncompressedResponse);
}
Aggregations