List of usage examples for com.google.common.io ByteArrayDataOutput writeShort
@Override void writeShort(int v);
From source file:io.github.aritzhack.aritzh.bds.BDSShort.java
@Override public byte[] getBytes() { ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeByte(this.getType().toByte()); output.writeUTF(this.name); output.writeShort(this.data); return output.toByteArray(); }
From source file:garmintools.adapters.garmin.MetadataGarminAdapter.java
private void writeDate(ByteArrayDataOutput output, Proto.Date date) { output.write(date.getMonth());//from w w w . j a v a2 s. c o m output.write(date.getDay()); output.writeShort(date.getYear()); }
From source file:com.android.tools.perflib.heap.SnapshotBuilder.java
public Snapshot build() { HprofStringBuilder strings = new HprofStringBuilder(0); List<HprofRecord> records = new ArrayList<HprofRecord>(); List<HprofDumpRecord> dump = new ArrayList<HprofDumpRecord>(); byte objType = HprofType.TYPE_OBJECT; // Roots go in the default heap. Add those first. for (Integer id : mRoots) { dump.add(new HprofRootUnknown(id)); }/*from w ww .j a va2 s. c om*/ // Everything else goes in "testHeap" with id 13. dump.add(new HprofHeapDumpInfo(13, strings.get("testHeap"))); // The SoftReference class records.add(new HprofLoadClass(0, 0, SOFT_REFERENCE_ID, 0, strings.get("java.lang.ref.Reference"))); dump.add(new HprofClassDump(SOFT_REFERENCE_ID, 0, 0, 0, 0, 0, 0, 0, 0, new HprofConstant[0], new HprofStaticField[0], new HprofInstanceField[] { new HprofInstanceField(strings.get("referent"), objType) })); // The SoftAndHardReference class records.add(new HprofLoadClass(0, 1, SOFT_AND_HARD_REFERENCE_ID, 0, strings.get("SoftAndHardReference"))); dump.add(new HprofClassDump(SOFT_AND_HARD_REFERENCE_ID, 0, 0, 0, 0, 0, 0, 0, 0, new HprofConstant[0], new HprofStaticField[0], new HprofInstanceField[] { new HprofInstanceField(strings.get("referent"), objType), new HprofInstanceField(strings.get("hardReference"), objType) })); // Regular nodes and their classes for (int i = 1; i <= mNumNodes; i++) { HprofInstanceField[] fields = new HprofInstanceField[mReferences[i].size()]; ByteArrayDataOutput values = ByteStreams.newDataOutput(); for (int j = 0; j < fields.length; j++) { fields[j] = new HprofInstanceField(strings.get("field" + j), objType); values.writeShort(mReferences[i].get(j)); } // Use same name classes on different loaders to extend test coverage records.add(new HprofLoadClass(0, 0, 100 + i, 0, strings.get("Class" + (i / 2)))); dump.add(new HprofClassDump(100 + i, 0, 0, i % 2, 0, 0, 0, 0, i, new HprofConstant[0], new HprofStaticField[0], fields)); dump.add(new HprofInstanceDump(i, 0, 100 + i, values.toByteArray())); } // Soft reference nodes. for (int i = mNumNodes + 1; i <= mNumNodes + mNumSoftNodes; ++i) { assertEquals(1, mReferences[i].size()); ByteArrayDataOutput values = ByteStreams.newDataOutput(); values.writeShort(mReferences[i].get(0)); dump.add(new HprofInstanceDump(i, 0, SOFT_REFERENCE_ID, values.toByteArray())); } // Soft and hard reference nodes. for (int i = mNumNodes + mNumSoftNodes + 1; i <= mMaxTotalNodes; ++i) { assertEquals(2, mReferences[i].size()); ByteArrayDataOutput values = ByteStreams.newDataOutput(); values.writeShort(mReferences[i].get(0)); values.writeShort(mReferences[i].get(1)); dump.add(new HprofInstanceDump(i, 0, SOFT_AND_HARD_REFERENCE_ID, values.toByteArray())); } records.add(new HprofHeapDump(0, dump.toArray(new HprofDumpRecord[0]))); // TODO: Should perflib handle the case where strings are referred to // before they are defined? List<HprofRecord> actualRecords = new ArrayList<HprofRecord>(); actualRecords.addAll(strings.getStringRecords()); actualRecords.addAll(records); Snapshot snapshot = null; try { Hprof hprof = new Hprof("JAVA PROFILE 1.0.3", 2, new Date(), actualRecords); ByteArrayOutputStream os = new ByteArrayOutputStream(); hprof.write(os); InMemoryBuffer buffer = new InMemoryBuffer(os.toByteArray()); snapshot = Snapshot.createSnapshot(buffer); } catch (IOException e) { fail("IOException when writing to byte output stream: " + e); } // TODO: Should the parser be setting isSoftReference, not the builder? for (Heap heap : snapshot.getHeaps()) { ClassObj softClass = heap.getClass(SOFT_REFERENCE_ID); if (softClass != null) { softClass.setIsSoftReference(); } ClassObj softAndHardClass = heap.getClass(SOFT_AND_HARD_REFERENCE_ID); if (softAndHardClass != null) { softAndHardClass.setIsSoftReference(); } } return snapshot; }
From source file:pw.simplyintricate.bitcoin.models.datastructures.NetworkAddress.java
public byte[] toByteArray() { ByteArrayDataOutput writer = ByteStreams.newDataOutput(); //writer.writeInt(EndianUtils.swapInteger(time)); writer.writeLong(EndianUtils.swapLong(services.longValue())); // write the two ipv4 to ipv6 pads for (int i = 0; i < 10; i++) { writer.writeByte(0);// w ww . ja v a2s . com } writer.writeByte(0xFF); writer.writeByte(0xFF); writer.write(ipAddress); writer.writeShort(port); return writer.toByteArray(); }
From source file:com.volumetricpixels.rockyplugin.packet.RockyPacketHandler.java
/** * //w ww . j av a2s .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:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java
/** * Send a custom plugin message to said server. This is one of the most useful channels ever. * <b>Remember, the sending and receiving server(s) need to have a player online.</b> * * @param server the name of the server to send to, * ALL to send to every server (except the one sending the plugin message), * or ONLINE to send to every server that's online (except the one sending the plugin message). * * @param channelName Subchannel for plugin usage. * @param data data to send./* w w w . j a v a 2 s.c o m*/ * @throws IllegalArgumentException if there is no players online. */ public void forward(String server, String channelName, byte[] data) { Player player = getFirstPlayer(); ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeUTF("Forward"); output.writeUTF(server); output.writeUTF(channelName); output.writeShort(data.length); output.write(data); player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); }
From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java
/** * Send a custom plugin message to specific player. * * @param playerName the name of the player to send to. * @param channelName Subchannel for plugin usage. * @param data data to send./* w w w .j ava 2 s . c o m*/ * @throws IllegalArgumentException if there is no players online. */ public void forwardToPlayer(String playerName, String channelName, byte[] data) { Player player = getFirstPlayer(); ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeUTF("ForwardToPlayer"); output.writeUTF(playerName); output.writeUTF(channelName); output.writeShort(data.length); output.write(data); player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); }
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...) *//*w w w .j a v a2 s .c o m*/ @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 .jav a 2 s .c o m @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: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 ww . j a v a2 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()); } } }