Search in sources :

Example 56 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project jocean-http by isdom.

the class RxNettys method httpObjectsAsBytes.

public static byte[] httpObjectsAsBytes(final Iterator<HttpObject> itr) throws IOException {
    final CompositeByteBuf composite = Unpooled.compositeBuffer();
    try {
        while (itr.hasNext()) {
            final HttpObject obj = itr.next();
            if (obj instanceof HttpContent) {
                composite.addComponent(((HttpContent) obj).content());
            }
        }
        composite.setIndex(0, composite.capacity());
        @SuppressWarnings("resource") final InputStream is = new ByteBufInputStream(composite);
        final byte[] bytes = new byte[is.available()];
        is.read(bytes);
        return bytes;
    } finally {
        ReferenceCountUtil.release(composite);
    }
}
Also used : CompositeByteBuf(io.netty.buffer.CompositeByteBuf) HttpObject(io.netty.handler.codec.http.HttpObject) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent)

Example 57 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project minecolonies by Minecolonies.

the class SaveScanMessage method fromBytes.

@Override
public void fromBytes(@NotNull final ByteBuf buf) {
    final PacketBuffer buffer = new PacketBuffer(buf);
    try (ByteBufInputStream stream = new ByteBufInputStream(buffer)) {
        final NBTTagCompound wrapperCompound = CompressedStreamTools.readCompressed(stream);
        nbttagcompound = wrapperCompound.getCompoundTag(TAG_SCHEMATIC);
        fileName = wrapperCompound.getString(TAG_MILLIS);
    } catch (final RuntimeException e) {
        Log.getLogger().info("Structure too big to be processed", e);
    } catch (final IOException e) {
        Log.getLogger().info("Problem at retrieving structure on server.", e);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 58 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project Fracture by HellFirePvP.

the class PktSyncData method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    for (int i = 0; i < size; i++) {
        String key = ByteBufUtils.readString(buf);
        byte providerId = buf.readByte();
        AbstractData.AbstractDataProvider<? extends AbstractData> provider = AbstractData.Registry.getProvider(providerId);
        if (provider == null) {
            Fracture.log.warn("[Fracture] Provider for ID " + providerId + " doesn't exist! Skipping...");
            continue;
        }
        NBTTagCompound cmp;
        try {
            cmp = CompressedStreamTools.read(new ByteBufInputStream(buf), NBTSizeTracker.INFINITE);
        } catch (IOException e) {
            Fracture.log.warn("[Fracture] Provider Compound of " + providerId + " threw an IOException! Skipping...");
            Fracture.log.warn("[Fracture] Exception message: " + e.getMessage());
            continue;
        }
        AbstractData dat = provider.provideNewInstance();
        dat.readRawFromPacket(cmp);
        data.put(key, dat);
    }
}
Also used : AbstractData(hellfirepvp.fracture.common.data.AbstractData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException)

Example 59 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project LanternServer by LanternPowered.

the class LanternByteBuffer method readLimitedDataView.

@Nullable
@Override
public DataView readLimitedDataView(int maximumDepth, int maxBytes) {
    final int index = this.buf.readerIndex();
    if (this.buf.readByte() == 0) {
        return null;
    }
    this.buf.readerIndex(index);
    try {
        try (NbtDataContainerInputStream input = new NbtDataContainerInputStream(new LimitInputStream(new ByteBufInputStream(this.buf), maxBytes), false, maximumDepth)) {
            return input.read();
        }
    } catch (IOException e) {
        throw new CodecException(e);
    }
}
Also used : NbtDataContainerInputStream(org.lanternpowered.server.data.persistence.nbt.NbtDataContainerInputStream) CodecException(io.netty.handler.codec.CodecException) LimitInputStream(org.lanternpowered.server.util.io.LimitInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 60 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project drill by apache.

the class ServerAuthenticationHandler method handle.

@Override
public void handle(S connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
    final String remoteAddress = connection.getRemoteAddress().toString();
    // exchange involves server "challenges" and client "responses" (initiated by client)
    if (saslRequestTypeValue == rpcType) {
        final SaslMessage saslResponse;
        try {
            saslResponse = SaslMessage.PARSER.parseFrom(new ByteBufInputStream(pBody));
        } catch (final InvalidProtocolBufferException e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
            return;
        }
        logger.trace("Received SASL message {} from {}", saslResponse.getStatus(), remoteAddress);
        final SaslResponseProcessor processor = RESPONSE_PROCESSORS.get(saslResponse.getStatus());
        if (processor == null) {
            logger.info("Unknown message type from client from {}. Will stop authentication.", remoteAddress);
            handleAuthFailure(connection, sender, new SaslException("Received unexpected message"), saslResponseType);
            return;
        }
        final SaslResponseContext<S, T> context = new SaslResponseContext<>(saslResponse, connection, sender, requestHandler, saslResponseType);
        try {
            processor.process(context);
        } catch (final Exception e) {
            handleAuthFailure(connection, sender, e, saslResponseType);
        }
    } else {
        // drop connection
        throw new RpcException(String.format("Request of type %d is not allowed without authentication. Client on %s must authenticate " + "before making requests. Connection dropped. [Details: %s]", rpcType, remoteAddress, connection.getEncryptionCtxtString()));
    }
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SaslMessage(org.apache.drill.exec.proto.UserBitShared.SaslMessage) ByteString(com.google.protobuf.ByteString) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) SaslException(javax.security.sasl.SaslException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) RpcException(org.apache.drill.exec.rpc.RpcException) IOException(java.io.IOException) SaslException(javax.security.sasl.SaslException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)69 ByteBuf (io.netty.buffer.ByteBuf)22 IOException (java.io.IOException)22 InputStreamReader (java.io.InputStreamReader)18 BadRequestException (co.cask.cdap.common.BadRequestException)16 Reader (java.io.Reader)16 JsonSyntaxException (com.google.gson.JsonSyntaxException)11 InputStream (java.io.InputStream)10 Path (javax.ws.rs.Path)9 ObjectInputStream (java.io.ObjectInputStream)8 NamespaceId (co.cask.cdap.proto.id.NamespaceId)6 POST (javax.ws.rs.POST)6 Test (org.junit.jupiter.api.Test)5 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 ObjectOutputStream (java.io.ObjectOutputStream)3