List of usage examples for com.google.common.io ByteArrayDataOutput writeInt
@Override void writeInt(int v);
From source file:org.locationtech.geogig.storage.postgresql.PGId.java
public static PGId valueOf(final int h1, final long h2, final long h3) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeInt(h1); out.writeLong(h2);/*from w w w . ja va 2 s . c o m*/ out.writeLong(h3); byte[] raw = out.toByteArray(); return new PGId(raw); }
From source file:com.yubico.u2f.data.messages.key.CodecTestUtils.java
public static byte[] encodeAuthenticateResponse(RawAuthenticateResponse rawAuthenticateResponse) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(rawAuthenticateResponse.getUserPresence()); encoded.writeInt((int) rawAuthenticateResponse.getCounter()); encoded.write(rawAuthenticateResponse.getSignature()); return encoded.toByteArray(); }
From source file:co.cask.cdap.internal.app.runtime.batch.dataset.AbstractBatchReadableInputFormat.java
/** * Sets dataset and splits information into the given {@link Configuration}. * * @param hConf configuration to modify * @param datasetName name of the dataset * @param datasetArguments arguments for the dataset * @param splits list of splits on the dataset * @throws IOException//from ww w .j av a2 s. c o m */ public static void setDatasetSplits(Configuration hConf, String datasetName, Map<String, String> datasetArguments, List<Split> splits) throws IOException { hConf.set(DATASET_NAME, datasetName); hConf.set(DATASET_ARGS, GSON.toJson(datasetArguments, DATASET_ARGS_TYPE)); // Encode the list of splits with size followed by that many of DataSetInputSplit objects. ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); dataOutput.writeInt(splits.size()); for (Split split : splits) { new DataSetInputSplit(split).write(dataOutput); } hConf.set(SPLITS, Bytes.toStringBinary(dataOutput.toByteArray())); }
From source file:u2f.data.messages.key.RawAuthenticateResponse.java
public static byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash);/*from ww w . j av a 2 s . co m*/ encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
From source file:com.volumetricpixels.rockyplugin.chunk.ChunkCacheHandler.java
/** * //ww w .j a va2 s . co m * @param buffer * @throws IOException */ public static byte[] handleCompression(String playerName, byte[] buffer) throws IOException { Set<Long> playerCache = cache.getPlayerCache(playerName); // Each chunk sended is handled by: // - BlockType: Whole byte per block // - BlockMetaData: Half byte per block // - BlockLight: Half byte per block // - SkyLight: Half byte per block (Only of handleLight is TRUE) // - AddArray: Half byte per block (Only if extraMask has the bit, // support for FORGE) // - BiomeArray: Whole byte per XZ coordinate (Only if isContinous is // TRUE) int chunkLen = buffer.length / ChunkCache.CHUNK_PARTITION_SIZE; if ((chunkLen & 0x7FF) != 0) { chunkLen++; } ByteArrayDataOutput out = ByteStreams.newDataOutput(); byte[] chunkData = new byte[ChunkCache.CHUNK_PARTITION_SIZE]; // Write the magic number out.writeInt(ChunkCache.CHUNK_MAGIC_NUMBER); // Write the number of section inside the packet out.writeShort(chunkLen); // For each CHUNK_PARTITION_SIZE block, check the hash of it. for (int i = 0; i < chunkLen; i++) { int index = i * ChunkCache.CHUNK_PARTITION_SIZE; int length = ChunkCache.CHUNK_PARTITION_SIZE; if (index + ChunkCache.CHUNK_PARTITION_SIZE > buffer.length) { length = buffer.length - index; } // Calculate the hash of the current block System.arraycopy(buffer, index, chunkData, 0x0000, length); long hash = ChunkCache.calculateHash(chunkData); // Write the hash into the packet out.writeLong(hash); // Add the hash into the player cache boolean isPresent = playerCache.add(hash); // Writes the length of the section out.writeShort(isPresent ? length : 0); // Check for the chunk with the player cache if (isPresent) { // Writes the data of the section out.write(chunkData); statCacheMiss.incrementAndGet(); } else { statCacheHit.incrementAndGet(); } statTotal.incrementAndGet(); } return out.toByteArray(); }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static byte[] encodeElement(String name, Object value) throws AnalyticsException { ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); buffer.writeInt(nameBytes.length); buffer.write(nameBytes);// ww w.j a v a2 s .co m if (value instanceof String) { buffer.write(DATA_TYPE_STRING); String strVal = (String) value; byte[] strBytes = strVal.getBytes(StandardCharsets.UTF_8); buffer.writeInt(strBytes.length); buffer.write(strBytes); } else if (value instanceof Long) { buffer.write(DATA_TYPE_LONG); buffer.writeLong((Long) value); } else if (value instanceof Double) { buffer.write(DATA_TYPE_DOUBLE); buffer.writeDouble((Double) value); } else if (value instanceof Boolean) { buffer.write(DATA_TYPE_BOOLEAN); boolean boolVal = (Boolean) value; if (boolVal) { buffer.write(BOOLEAN_TRUE); } else { buffer.write(BOOLEAN_FALSE); } } else if (value instanceof Integer) { buffer.write(DATA_TYPE_INTEGER); buffer.writeInt((Integer) value); } else if (value instanceof Float) { buffer.write(DATA_TYPE_FLOAT); buffer.writeFloat((Float) value); } else if (value instanceof byte[]) { buffer.write(DATA_TYPE_BINARY); byte[] binData = (byte[]) value; buffer.writeInt(binData.length); buffer.write(binData); } else if (value == null) { buffer.write(DATA_TYPE_NULL); } else { buffer.write(DATA_TYPE_OBJECT); byte[] binData = serializeObject(value); buffer.writeInt(binData.length); buffer.write(binData); } return buffer.toByteArray(); }
From source file:org.wso2.carbon.analytics.datasource.core.util.GenericUtils.java
public static byte[] encodeElement(String name, Object value) throws AnalyticsException { ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); buffer.writeInt(nameBytes.length); buffer.write(nameBytes);/*from ww w .j a va2 s.c o m*/ if (value instanceof String) { buffer.write(DATA_TYPE_STRING); String strVal = (String) value; byte[] strBytes = strVal.getBytes(StandardCharsets.UTF_8); buffer.writeInt(strBytes.length); buffer.write(strBytes); } else if (value instanceof Long) { buffer.write(DATA_TYPE_LONG); buffer.writeLong((Long) value); } else if (value instanceof Double) { buffer.write(DATA_TYPE_DOUBLE); buffer.writeDouble((Double) value); } else if (value instanceof Boolean) { buffer.write(DATA_TYPE_BOOLEAN); boolean boolVal = (Boolean) value; if (boolVal) { buffer.write(BOOLEAN_TRUE); } else { buffer.write(BOOLEAN_FALSE); } } else if (value instanceof Integer) { buffer.write(DATA_TYPE_INTEGER); buffer.writeInt((Integer) value); } else if (value instanceof Float) { buffer.write(DATA_TYPE_FLOAT); buffer.writeFloat((Float) value); } else if (value instanceof byte[]) { buffer.write(DATA_TYPE_BINARY); byte[] binData = (byte[]) value; buffer.writeInt(binData.length); buffer.write(binData); } else if (value == null) { buffer.write(DATA_TYPE_NULL); } else { buffer.write(DATA_TYPE_OBJECT); byte[] binData = GenericUtils.serializeObject(value); buffer.writeInt(binData.length); buffer.write(binData); } return buffer.toByteArray(); }
From source file:de.mineformers.robots.network.packet.PacketBuddyBotSit.java
@Override public void write(ByteArrayDataOutput out) { out.writeInt(id); }
From source file:de.paleocrafter.pmfw.network.data.DataForgeDirection.java
@Override public void writeToPacket(ByteArrayDataOutput out) { out.writeInt(internal.ordinal()); }
From source file:de.mineformers.robots.network.packet.PacketTileSync.java
@Override public void write(ByteArrayDataOutput out) { out.writeInt(x); out.writeInt(y); out.writeInt(z); }