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);
}
}
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);
}
}
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);
}
}
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);
}
}
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()));
}
}
Aggregations