public void testNewDataOutput_BAOS() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayDataOutput out = ByteStreams.newDataOutput(baos); out.writeInt(0x12345678); assertEquals(4, baos.size()); assertEquals(new byte[] {0x12, 0x34, 0x56, 0x78}, baos.toByteArray()); }
public byte[] serializeEvent(DataPointEvent dataPointEvent) { //Todo: Create some adaptive value here, keep stats on if the buffer increases and slowely increase it ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(64); dataOutput.writeUTF(dataPointEvent.getMetricName()); dataOutput.writeInt(dataPointEvent.getTtl()); dataOutput.writeLong(dataPointEvent.getDataPoint().getTimestamp()); dataOutput.writeUTF(dataPointEvent.getDataPoint().getDataStoreDataType()); try { dataPointEvent.getDataPoint().writeValueToBuffer(dataOutput); } catch (IOException e) { logger.error("Error serializing DataPoint", e); } dataOutput.writeInt(dataPointEvent.getTags().size()); for (Map.Entry<String, String> entry : dataPointEvent.getTags().entrySet()) { dataOutput.writeUTF(entry.getKey()); dataOutput.writeUTF(entry.getValue()); } return dataOutput.toByteArray(); }
private void serializeCollection(Collection<?> collection, ByteArrayDataOutput output) { output.writeInt(collection.size()); for (Object o : collection) { output.writeUTF(o.toString()); } }
private void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) { output.writeInt(collection.keySet().size()); for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) { output.writeUTF(entry.getKey()); if (includeNames) { serializeCollection(entry.getValue(), output); } else { output.writeInt(entry.getValue().size()); } } }
ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.write(someBytes); out.writeInt(someInt); // ... return out.toByteArray();
@Override public void writeTo(ByteArrayDataOutput output) { output.writeInt(type.ordinal()); //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target output.writeUTF(playerName); //proxy identifier to check if it's a acceptable proxy output.writeLong(proxyId.getMostSignificantBits()); output.writeLong(proxyId.getLeastSignificantBits()); }
public void testNewDataOutput_BAOS() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayDataOutput out = ByteStreams.newDataOutput(baos); out.writeInt(0x12345678); assertEquals(4, baos.size()); assertEquals(new byte[] {0x12, 0x34, 0x56, 0x78}, baos.toByteArray()); }
private byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash); encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
@Override public void writeTo(ByteArrayDataOutput out) { out.writeBoolean(allowed); out.writeInt(skin.getRowId()); out.writeUTF(skin.getEncodedValue()); out.writeUTF(skin.getSignature()); out.writeUTF(receiverUUID.toString()); }
public static PGId valueOf(final int h1, final long h2, final long h3) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeInt(h1); out.writeLong(h2); out.writeLong(h3); byte[] raw = out.toByteArray(); return new PGId(raw); }
public static byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash); encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
public static byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash); encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
public static byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash); encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
public static byte[] encodeSignResponse(RawSignResponse rawSignResponse) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(rawSignResponse.getUserPresence()); encoded.writeInt((int) rawSignResponse.getCounter()); encoded.write(rawSignResponse.getSignature()); return encoded.toByteArray(); }