List of usage examples for com.google.common.io ByteArrayDataOutput write
@Override void write(byte b[]);
From source file:com.volumetricpixels.rockyplugin.packet.RockyPacketHandler.java
/** * /* w w w .j a va 2 s. c om*/ * @param packet */ public void sendMessagePlugin(com.volumetricpixels.rockyapi.packet.Packet packet) { ByteArrayDataOutput bos = ByteStreams.newDataOutput(); try { bos.writeShort(packet.getType().getId()); PacketOutputStream out = new PacketOutputStream(); packet.writeData(out); ByteBuffer buffer = out.getRawBuffer(); buffer.flip(); bos.writeShort(buffer.limit()); bos.write(buffer.array()); buffer.clear(); } catch (IOException ex) { return; } Packet250CustomPayload payload = new Packet250CustomPayload("Rocky", bos.toByteArray()); sendOfflinePacket(payload); }
From source file:net.minecraftforge.gradle.patcher.TaskGenBinPatches.java
private void createBinPatches(HashMap<String, byte[]> patches, String root, File base, File target) throws Exception { JarFile cleanJ = new JarFile(base); JarFile dirtyJ = new JarFile(target); for (Map.Entry<String, String> entry : obfMapping.entrySet()) { String obf = entry.getKey(); String srg = entry.getValue(); if (!patchedFiles.contains(obf)) // Not in the list of patch files.. we didn't edit it. {//w w w . j a v a 2 s .co m continue; } JarEntry cleanE = cleanJ.getJarEntry(obf + ".class"); JarEntry dirtyE = dirtyJ.getJarEntry(obf + ".class"); if (dirtyE == null) //Something odd happened.. a base MC class wasn't in the obfed jar? { continue; } byte[] clean = (cleanE != null ? ByteStreams.toByteArray(cleanJ.getInputStream(cleanE)) : new byte[0]); byte[] dirty = ByteStreams.toByteArray(dirtyJ.getInputStream(dirtyE)); byte[] diff = delta.compute(clean, dirty); ByteArrayDataOutput out = ByteStreams.newDataOutput(diff.length + 50); out.writeUTF(obf); // Clean name out.writeUTF(obf.replace('/', '.')); // Source Notch name out.writeUTF(srg.replace('/', '.')); // Source SRG Name out.writeBoolean(cleanE != null); // Exists in Clean if (cleanE != null) { out.writeInt(adlerHash(clean)); // Hash of Clean file } out.writeInt(diff.length); // Patch length out.write(diff); // Patch patches.put(root + srg.replace('/', '.') + ".binpatch", out.toByteArray()); } cleanJ.close(); dirtyJ.close(); }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
private void sendQueueingMessage(String operation, String args, Object... write) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(args);/*from w w w .j a v a 2 s . c o m*/ for (Object w : write) { if (w instanceof String) { out.writeUTF((String) w); } else if (w instanceof Integer) { out.writeInt((Integer) w); } else { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(bos)) { oOut.writeObject(w); out.write(bos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } } } QueueingPluginMessage pm = new QueueingPluginMessage(operation, args, out); for (ServerInfo serverInfo : getProxy().getServers().values()) { if (serverInfo.getPlayers().size() > 0) { pm.send(serverInfo); } } if (pm.getSendTo().size() < getProxy().getServers().size()) { // plugin message wasn't sent to all servers because no players where online, queue it pmQueue.put(pm.getCommand(), pm); } else { // remove previously queued plugin message if we already send a newer one pmQueue.remove(pm.getCommand()); } }
From source file:tk.playerforcehd.networklib.bukkit.connection.DefaultManager.java
/** * @param server The server which recieves the message * @param channel The channel where the message will be send (subchannel) * @param msg The messages will be written to the server * @see DefaultBungeeLib#forward(String, String, Object...) *//*from ww w .j av a2 s. com*/ @Override public void forward(String server, String channel, Object... msg) throws IOException { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("Forward"); stream.writeUTF(server); stream.writeUTF(channel); ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); DataOutputStream dataout = new DataOutputStream(msgbytes); for (Object o : msg) { dataout.writeUTF(o.toString()); } stream.writeShort(msgbytes.toByteArray().length); stream.write(msgbytes.toByteArray()); this.networkManager.sendMessageToProxy(stream); }
From source file:tk.playerforcehd.networklib.bukkit.connection.DefaultManager.java
/** * @param player The player which recieves the message * @param channel The channel where the message will be send (subchannel) * @param msg The message which will be send * @see DefaultBungeeLib#forwardToPlayer(Player, String, Object...) *//*from w w w . j av a2s.c om*/ @Override public void forwardToPlayer(Player player, String channel, Object... msg) throws IOException { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("Forward"); stream.writeUTF(player.getName()); stream.writeUTF(channel); ByteArrayOutputStream msgbytes = new ByteArrayOutputStream(); DataOutputStream dataout = new DataOutputStream(msgbytes); for (Object o : msg) { dataout.writeUTF(o.toString()); } stream.writeShort(msgbytes.toByteArray().length); stream.write(msgbytes.toByteArray()); this.networkManager.sendMessageToProxy(stream); }
From source file:cpw.mods.fml.common.network.EntitySpawnPacket.java
@Override public byte[] generatePacket(Object... data) { EntityRegistration er = (EntityRegistration) data[0]; Entity ent = (Entity) data[1]; NetworkModHandler handler = (NetworkModHandler) data[2]; ByteArrayDataOutput dat = ByteStreams.newDataOutput(); dat.writeInt(handler.getNetworkId()); dat.writeInt(er.getModEntityId());// w ww . ja v a 2s .c o m // entity id dat.writeInt(ent.field_70157_k); // entity pos x,y,z dat.writeInt(MathHelper.func_76128_c(ent.field_70165_t * 32D)); dat.writeInt(MathHelper.func_76128_c(ent.field_70163_u * 32D)); dat.writeInt(MathHelper.func_76128_c(ent.field_70161_v * 32D)); // yaw, pitch dat.writeByte((byte) (ent.field_70177_z * 256.0F / 360.0F)); dat.writeByte((byte) (ent.field_70125_A * 256.0F / 360.0F)); // head yaw if (ent instanceof EntityLiving) { dat.writeByte((byte) (((EntityLiving) ent).field_70759_as * 256.0F / 360.0F)); } else { dat.writeByte(0); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); try { ent.func_70096_w().func_75689_a(dos); } catch (IOException e) { // unpossible } dat.write(bos.toByteArray()); if (ent instanceof IThrowableEntity) { Entity owner = ((IThrowableEntity) ent).getThrower(); dat.writeInt(owner == null ? ent.field_70157_k : owner.field_70157_k); double maxVel = 3.9D; double mX = ent.field_70159_w; double mY = ent.field_70181_x; double mZ = ent.field_70179_y; if (mX < -maxVel) mX = -maxVel; if (mY < -maxVel) mY = -maxVel; if (mZ < -maxVel) mZ = -maxVel; if (mX > maxVel) mX = maxVel; if (mY > maxVel) mY = maxVel; if (mZ > maxVel) mZ = maxVel; dat.writeInt((int) (mX * 8000D)); dat.writeInt((int) (mY * 8000D)); dat.writeInt((int) (mZ * 8000D)); } else { dat.writeInt(0); } if (ent instanceof IEntityAdditionalSpawnData) { ((IEntityAdditionalSpawnData) ent).writeSpawnData(dat); } return dat.toByteArray(); }
From source file:garmintools.adapters.garmin.LandingFacilityDetailGarminAdapter.java
private void encode(LandingFacilityDetail detail, ByteArrayDataOutput output) { BitSet sectionsPresent = new BitSet(16); List<ByteArrayDataOutput> sections = new ArrayList<>(); if (!detail.runways.isEmpty()) { sectionsPresent.set(0);// www .jav a 2s . c o m ByteArrayDataOutput sectionOutput = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); sections.add(sectionOutput); encodeRunwayInfo(detail.runways, sectionOutput); } if (!detail.communicationFrequencies.isEmpty()) { sectionsPresent.set(1); ByteArrayDataOutput sectionOutput = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); sections.add(sectionOutput); encodeCommunicationInfo(detail.communicationFrequencies, sectionOutput); } // Temporary; pass through unknown sections. for (UnknownLandingFacilityDetailSection unknownSection : detail.protoLandingFacilityDetail .getUnknownSectionList()) { sectionsPresent.set(unknownSection.getSectionNumber()); ByteArrayDataOutput sectionOutput = ByteStreams.newDataOutput(); sectionOutput.write(unknownSection.getData().toByteArray()); sections.add(sectionOutput); } output.writeShort(sectionsPresent.length() == 0 ? 0 : (short) sectionsPresent.toLongArray()[0]); // write lengths. for (ByteArrayDataOutput section : sections) { int sectionLength = section.toByteArray().length; output.writeShort(sectionLength); } // write contents. for (ByteArrayDataOutput section : sections) { output.write(section.toByteArray()); } }
From source file:garmintools.adapters.garmin.LandingFacilityDetailGarminAdapter.java
private void encodeRunwayInfo(List<Runway> runways, ByteArrayDataOutput output) { for (Runway runway : runways) { Proto.Runway proto = runway.protoRunway; int data = ((runway.runwayNumberSuffix.getIndex() & 7) << 29) | ((proto.getRunwayNumber() & 0x1f) << 24) | ((proto.getUnknown(0) & 1) << 23) | ((runway.lighting.getIndex() & 7) << 20) | ((runway.surface.getIndex() & 0xf) << 16) | ((proto.getRunwayLengthFeet() & 0xffff)); output.writeInt(data);/*from w w w . j a v a 2 s .co m*/ data = ((proto.getRunwayWidthFeet() & 0x7ff) << 13) | ((proto.hasUnknownAdditionalInfo1() ? 1 : 0) << 12) | ((proto.hasUnknownAdditionalInfo2() ? 1 : 0) << 11) | ((proto.hasUnknownAdditionalInfo3() ? 1 : 0) << 10) | ((proto.getUnknown(1) & 1) << 9) | ((proto.getUnknown(2) & 1) << 8) | ((proto.getUnknown(3) & 0xff)); output.writeShort(data & 0xffff); output.write((data >> 16) & 0xff); if (proto.hasUnknownAdditionalInfo1()) { output.write(proto.getUnknownAdditionalInfo1().toByteArray()); } if (proto.hasUnknownAdditionalInfo2()) { output.write(proto.getUnknownAdditionalInfo2().toByteArray()); } if (proto.hasUnknownAdditionalInfo3()) { output.write(proto.getUnknownAdditionalInfo3().toByteArray()); } } }
From source file:garmintools.adapters.garmin.LandingFacilityDetailGarminAdapter.java
private void encodeCommunicationInfo(List<CommunicationFrequency> freqs, ByteArrayDataOutput output) { for (CommunicationFrequency freq : freqs) { Proto.CommunicationFrequency proto = freq.protoCommunicationFrequency; int additionalDataBitmap = (proto.hasUnknownAdditionalInfo1() ? 1 : 0) | ((proto.hasUnknownAdditionalInfo2() ? 1 : 0) << 1) | ((proto.hasUnknownAdditionalInfo3() ? 1 : 0) << 2) | ((proto.hasUnknownAdditionalInfo4() ? 1 : 0) << 3) | ((proto.hasNarrative() ? 1 : 0) << 4) | ((proto.getUnknownAdditionalInfo5() ? 1 : 0) << 5) | ((proto.getUnknownAdditionalInfo6() ? 1 : 0) << 6) | ((proto.getUnknownAdditionalInfo7() ? 1 : 0) << 7); int data = ((encodeFrequency(proto.getFrequencyGhz()) & 0xfff) | ((proto.getUnknown(0) & 3) << 12) | ((proto.getUnknown(1) & 1) << 14) | ((proto.getUnknown(2) & 1) << 15) | ((freq.frequencyType.getIndex()) & 0x3f) << 16) | ((proto.getUnknown(3) & 1) << 22) | (((additionalDataBitmap > 0) ? 1 : 0) << 23) | ((proto.getUnknown(4) & 7) << 24) | ((proto.getUnknown(5) & 7) << 27) | ((proto.getUnknown(6) & 1) << 30) | ((proto.getUnknown(7) & 1) << 31); output.writeInt(data);//from w w w . ja v a2 s . c om if (additionalDataBitmap > 0) { output.write(additionalDataBitmap & 0xff); if (proto.hasUnknownAdditionalInfo1()) { output.write(proto.getUnknownAdditionalInfo1().toByteArray()); } if (proto.hasUnknownAdditionalInfo2()) { output.write(proto.getUnknownAdditionalInfo2().toByteArray()); } if (proto.hasUnknownAdditionalInfo3()) { output.write(proto.getUnknownAdditionalInfo3().toByteArray()); } if (proto.hasUnknownAdditionalInfo4()) { output.write(proto.getUnknownAdditionalInfo4().toByteArray()); } if (proto.hasNarrative()) { BitListOutputStream bitListOutputStream = new BitListOutputStream(); for (int i = 0; i < NUM_NARRATIVE_LEADING_BITS; ++i) { bitListOutputStream.writeBits(ImmutableList.of(false)); } VariableLengthAsciiEncoding encoding = new VariableLengthAsciiEncoding(bitListOutputStream); encoding.encodeExtended(proto.getNarrative()); byte b[] = bitListOutputStream.toByteArray(); output.write(b.length & 0xff); output.write(b); } } } }
From source file:de.minigameslib.mclib.impl.MclibPlugin.java
@Override public void broadcastServers(CommunicationEndpointId id, DataSection... data) { if (data != null) { for (final DataSection section : data) { // TODO only works if both servers have online players // TODO if target servers do not have online players the messages should be queued by bungeecord. // TODO ensure that we are really within bungeecord environments, else this will be sent to clients (not good) final ByteArrayDataOutput out2 = ByteStreams.newDataOutput(); final ByteArrayDataOutput out = ByteStreams.newDataOutput(); out2.writeUTF("Forward"); //$NON-NLS-1$ out2.writeUTF("ALL"); //$NON-NLS-1$ out2.writeUTF(MCLIB_SERVER_TO_SERVER_CHANNEL); out.writeByte(0);/*from w w w . java 2 s .c om*/ new NetMessage(id, section).toBytes(out); byte[] bytes = out.toByteArray(); if (this.getLogger().isLoggable(Level.FINEST)) { this.getLogger().finest("Sending NetMessage to all servers\n" + Arrays.toString(bytes)); //$NON-NLS-1$ } out2.writeShort(bytes.length); out2.write(bytes); final ObjectServiceInterface osi = ObjectServiceInterface.instance(); final Optional<? extends Player> player = Bukkit.getOnlinePlayers().stream() .filter(p -> !osi.isHuman(p)).findFirst(); if (player.isPresent()) { // bungee cord ensures this is not send to the client. player.get().sendPluginMessage(this, BUNGEECORD_CHANNEL, bytes); } else { this.bungeeQueue.add(p -> p.sendPluginMessage(this, BUNGEECORD_CHANNEL, bytes)); } } } }