Search in sources :

Example 6 with ByteBufInputStream

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();
        }
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) MessageFormatException(com.github.ambry.messageformat.MessageFormatException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 7 with ByteBufInputStream

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;
    }
}
Also used : NbtAccounter(net.minecraft.nbt.NbtAccounter) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException)

Example 8 with ByteBufInputStream

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);
}
Also used : ByteBufInputStream(io.netty.buffer.ByteBufInputStream)

Example 9 with ByteBufInputStream

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);
            }
        }
    });
}
Also used : Context(io.vertx.core.Context) ResteasyUriInfo(org.jboss.resteasy.specimpl.ResteasyUriInfo) HttpServerResponse(io.vertx.core.http.HttpServerResponse) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) Failure(org.jboss.resteasy.spi.Failure) IOException(java.io.IOException)

Example 10 with ByteBufInputStream

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);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Transaction(org.eblocker.server.icap.transaction.Transaction) IcapTransaction(org.eblocker.server.icap.ch.mimo.icap.IcapTransaction) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) Test(org.junit.Test)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)247 IOException (java.io.IOException)94 ByteBuf (io.netty.buffer.ByteBuf)83 InputStreamReader (java.io.InputStreamReader)51 InputStream (java.io.InputStream)45 Reader (java.io.Reader)44 JsonSyntaxException (com.google.gson.JsonSyntaxException)31 BadRequestException (io.cdap.cdap.common.BadRequestException)26 Path (javax.ws.rs.Path)24 POST (javax.ws.rs.POST)19 Map (java.util.Map)17 BadRequestException (co.cask.cdap.common.BadRequestException)16 HashMap (java.util.HashMap)15 DataInputStream (java.io.DataInputStream)13 ObjectInputStream (java.io.ObjectInputStream)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)10 BufferedImage (java.awt.image.BufferedImage)10 List (java.util.List)10