List of usage examples for java.nio ByteBuffer putInt
public abstract ByteBuffer putInt(int index, int value);
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer bbuf = ByteBuffer.allocate(10); int capacity = bbuf.capacity(); // 10 System.out.println(capacity); bbuf.putInt(2, 123); System.out.println(Arrays.toString(bbuf.array())); }
From source file:Main.java
public static void putUnsignedInt(ByteBuffer bb, int position, long value) { bb.putInt(position, (int) (value & 0xffffffffL)); }
From source file:Main.java
public static byte[] intToBytes(int x) { ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(0, x); byte[] array = buffer.array(); reverseArray(array);/*from w ww . java 2 s. c om*/ return array; }
From source file:Main.java
public static void putUnsignedInt(final ByteBuffer pByteBuffer, final int pPosition, final long pValue) { pByteBuffer.putInt(pPosition, (short) (pValue & 0xFFFFFFFFL)); }
From source file:org.voltdb.ClientResponseImpl.java
/** * Set the server timestamp marker without deserializing it first * @param arr/*from ww w . jav a 2s. c om*/ * @param flag */ public static void setServerTimestamp(ByteBuffer b, int val) { b.putInt(1, val); }
From source file:org.voltdb.ClientResponseImpl.java
/** * Set the base partition for the client response without deserializing it * @param arr//from www . j a v a 2 s .co m * @param flag */ public static void setBasePartition(ByteBuffer b, int basePartition) { b.putInt(22, basePartition); // 1 + 4 + 8 + 8 + 1 + 1 = 23 }
From source file:Main.java
public final static ByteBuffer toNALFileFormat(final ByteBuffer buffer) { ByteBuffer result = ByteBuffer.allocate(buffer.remaining()); result.put(buffer);//from w ww . ja va 2 s . com result.flip(); int length = 0; int position = -1; int remaining = result.remaining() - 3; for (int i = 0; i < remaining; ++i) { if (result.get(i) == 0x00 && result.get(i + 1) == 0x00 && result.get(i + 2) == 0x00 && result.get(i + 3) == 0x01) { if (0 <= position) { result.putInt(position, length - 3); } position = i; length = 0; } else { ++length; } } result.putInt(position, length); return result; }
From source file:com.l2jfree.security.NewCipher.java
/** * Calculates and embeds a packet's checksum.<BR> * Buffer's position will not be changed. * // w ww . j a v a 2s . c o m * @param buf byte buffer * @param offset offset to a packet's body * @param size packet's body size * @param experimental undocumented experimental features */ public static void appendChecksum(ByteBuffer buf, final int offset, final int size, boolean experimental) { int checksum = 0; int end = offset + size - 4; // ignore reserved bytes int pos; for (pos = offset; pos < end; pos += 4) { int i = buf.getInt(pos); checksum ^= i; } buf.putInt(pos, checksum); if (experimental) { Integer real = _checks.get(buf.get(offset)); if (real != null) // someone knows a better scheme? buf.putInt(pos, real); // let them have it } }
From source file:org.apache.tez.mapreduce.examples.BroadcastLoadGen.java
private DAG createDAG(int numGenTasks, int totalSourceDataSize, int numFetcherTasks) { int bytesPerSource = totalSourceDataSize / numGenTasks; LOG.info("DataPerSourceTask(bytes)=" + bytesPerSource); ByteBuffer payload = ByteBuffer.allocate(4); payload.putInt(0, bytesPerSource); Vertex broadcastVertex = Vertex.create("DataGen", ProcessorDescriptor .create(InputGenProcessor.class.getName()).setUserPayload(UserPayload.create(payload)), numGenTasks);/* www . j a va 2 s. c o m*/ Vertex fetchVertex = Vertex.create("FetchVertex", ProcessorDescriptor.create(InputFetchProcessor.class.getName()), numFetcherTasks); UnorderedKVEdgeConfig edgeConf = UnorderedKVEdgeConfig .newBuilder(NullWritable.class.getName(), IntWritable.class.getName()) .setCompression(false, null, null).build(); DAG dag = DAG.create("BroadcastLoadGen"); dag.addVertex(broadcastVertex).addVertex(fetchVertex) .addEdge(Edge.create(broadcastVertex, fetchVertex, edgeConf.createDefaultBroadcastEdgeProperty())); return dag; }
From source file:com.unister.semweb.drums.file.RepairIndexTest.java
/** * Converts the given <code>value</code> to a byte array representation. The final array has * <code>numberOfBytes</code>. *//*from ww w .j a va2 s. co m*/ private byte[] transform(int value, int numberOfBytes) { ByteBuffer buffer = ByteBuffer.allocate(numberOfBytes); buffer.putInt(numberOfBytes - 4, value); return buffer.array(); }