use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project ArsMagica2 by Mithion.
the class AMPacketProcessorServer method onServerPacketData.
@SubscribeEvent
public void onServerPacketData(ServerCustomPacketEvent event) {
ByteBufInputStream bbis = new ByteBufInputStream(event.packet.payload());
byte packetID = -1;
try {
if (event.packet.getTarget() != Side.SERVER) {
return;
}
// constant details all packets share: ID, player, and remaining data
packetID = bbis.readByte();
NetHandlerPlayServer srv = (NetHandlerPlayServer) event.packet.handler();
EntityPlayerMP player = srv.playerEntity;
byte[] remaining = new byte[bbis.available()];
bbis.readFully(remaining);
switch(packetID) {
case AMPacketIDs.SPELL_SHAPE_GROUP_CHANGE:
handleCastingModeChange(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.MAGIC_LEVEL_UP:
handleMagicLevelUp(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SYNC_BETA_PARTICLES:
handleSyncBetaParticles(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.POSSIBLE_CLIENT_EXPROP_DESYNC:
handlePossibleClientExpropDesync(remaining);
break;
case AMPacketIDs.REQUEST_BETA_PARTICLES:
handleRequestBetaParticles(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SPELL_CUSTOMIZE:
handleSpellCustomize(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SPELLBOOK_CHANGE_ACTIVE_SLOT:
handleSpellBookChangeActiveSlot(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SYNC_SPELL_KNOWLEDGE:
handleSyncSpellKnowledge(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.DECO_BLOCK_UPDATE:
handleDecoBlockUpdate(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.INSCRIPTION_TABLE_UPDATE:
handleInscriptionTableUpdate(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.TK_DISTANCE_SYNC:
ExtendedProperties.For((EntityPlayerMP) player).TK_Distance = new AMDataReader(remaining).getFloat();
break;
case AMPacketIDs.SAVE_KEYSTONE_COMBO:
handleSaveKeystoneCombo(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SET_KEYSTONE_COMBO:
handleSetKeystoneCombo(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SET_MAG_WORK_REC:
handleSetMagiciansWorkbenchRecipe(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.RUNE_BAG_GUI_OPEN:
handleRuneBagGUIOpen(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.M_BENCH_LOCK_RECIPE:
handleMBenchLockRecipe(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.IMBUE_ARMOR:
handleImbueArmor(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.REQUEST_PWR_PATHS:
handlePowerPathSync(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.SYNC_EXTENDED_PROPS:
handleExpropOperation(remaining, (EntityPlayerMP) player);
break;
case AMPacketIDs.AFFINITY_ACTIVATE:
handleAffinityActivate(remaining, player);
break;
}
} catch (Throwable t) {
LogHelper.error("Server Packet Failed to Handle!");
LogHelper.error("Packet Type: " + packetID);
t.printStackTrace();
} finally {
try {
if (bbis != null)
bbis.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project netty by netty.
the class ObjectDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, in);
if (frame == null) {
return null;
}
ObjectInputStream ois = new CompactObjectInputStream(new ByteBufInputStream(frame, true), classResolver);
try {
return ois.readObject();
} finally {
ois.close();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project netty by netty.
the class SslContext method getCertificatesFromBuffers.
private static X509Certificate[] getCertificatesFromBuffers(ByteBuf[] certs) throws CertificateException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] x509Certs = new X509Certificate[certs.length];
try {
for (int i = 0; i < certs.length; i++) {
InputStream is = new ByteBufInputStream(certs[i], false);
try {
x509Certs[i] = (X509Certificate) cf.generateCertificate(is);
} finally {
try {
is.close();
} catch (IOException e) {
// This is not expected to happen, but re-throw in case it does.
throw new RuntimeException(e);
}
}
}
} finally {
for (ByteBuf buf : certs) {
buf.release();
}
}
return x509Certs;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project netty by netty.
the class DiskFileUploadTest method testSetContentFromInputStream.
@Test
public void testSetContentFromInputStream() throws Exception {
String json = "{\"hello\":\"world\",\"foo\":\"bar\"}";
DiskFileUpload f1 = new DiskFileUpload("file3", "file3", "application/json", null, null, 0);
try {
byte[] bytes = json.getBytes(CharsetUtil.UTF_8);
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
InputStream is = new ByteBufInputStream(buf);
try {
f1.setContent(is);
assertEquals(json, f1.getString());
assertArrayEquals(bytes, f1.get());
File file = f1.getFile();
assertEquals((long) bytes.length, file.length());
assertArrayEquals(bytes, doReadFile(file, bytes.length));
} finally {
buf.release();
is.close();
}
} finally {
f1.delete();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project netty by netty.
the class AbstractMemoryHttpDataTest method testSetContentFromStream.
/**
* Provide content into HTTP data with input stream.
*
* @throws Exception In case of any exception.
*/
@Test
public void testSetContentFromStream() throws Exception {
// definedSize=0
TestHttpData test = new TestHttpData("test", UTF_8, 0);
String contentStr = "foo_test";
ByteBuf buf = Unpooled.wrappedBuffer(contentStr.getBytes(UTF_8));
buf.markReaderIndex();
ByteBufInputStream is = new ByteBufInputStream(buf);
try {
test.setContent(is);
assertFalse(buf.isReadable());
assertEquals(test.getString(UTF_8), contentStr);
buf.resetReaderIndex();
assertTrue(ByteBufUtil.equals(buf, test.getByteBuf()));
} finally {
is.close();
}
Random random = new SecureRandom();
for (int i = 0; i < 20; i++) {
// Generate input data bytes.
int size = random.nextInt(Short.MAX_VALUE);
byte[] bytes = new byte[size];
random.nextBytes(bytes);
// Generate parsed HTTP data block.
TestHttpData data = new TestHttpData("name", UTF_8, 0);
data.setContent(new ByteArrayInputStream(bytes));
// Validate stored data.
ByteBuf buffer = data.getByteBuf();
assertEquals(0, buffer.readerIndex());
assertEquals(bytes.length, buffer.writerIndex());
assertArrayEquals(bytes, Arrays.copyOf(buffer.array(), bytes.length));
assertArrayEquals(bytes, data.get());
}
}
Aggregations