List of usage examples for java.nio ByteBuffer put
public ByteBuffer put(ByteBuffer src)
From source file:net.fenyo.mail4hotspot.service.HttpProxy.java
public void sendData(final byte data[]) throws IOException { // log.debug("sendData on id " + local_port); last_use = System.currentTimeMillis(); // log.debug("sendData(): " + data.length + " bytes"); if (closed)/*from w ww .j a v a 2 s .c o m*/ return; try { final ByteBuffer bb = ByteBuffer.allocate(to_socket_array.length + data.length); bb.put(to_socket_array); bb.put(data); bb.flip(); final int nbytes = socket_channel.write(bb); to_socket_array = ArrayUtils.subarray(bb.array(), nbytes, bb.array().length); } catch (final IOException ex) { log.warn(ex); ex.printStackTrace(); socket_channel.close(); closed = true; throw ex; } }
From source file:net.beaconpe.jraklib.protocol.Packet.java
protected byte[] get(int len) { if (len < 0) { offset = buffer.length - 1;//from w w w. j a v a2s. c o m return new byte[] {}; } else { ByteBuffer bb = ByteBuffer.allocate(len); while (len > 0) { bb.put(buffer[offset]); len = len - 1; if (len != 0) { offset = offset + 1; } } return bb.array(); } }
From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java
/** * Extracts the BitFingerprint length from the first two bytes * /*w ww.j av a 2 s. c o m*/ * @param bitFingerprint * the bytes * @return the length */ private short bitFingerprintToLength(byte[] bitFingerprint) { Preconditions.checkArgument(bitFingerprint.length >= 3); ByteBuffer bb = ByteBuffer.allocate(2); bb.order(ByteOrder.LITTLE_ENDIAN); bb.put(bitFingerprint[0]); bb.put(bitFingerprint[1]); short length = bb.getShort(0); return length; }
From source file:com.openteach.diamond.network.waverider.command.Command.java
/** * ByteBuffer/* ww w .j a v a 2 s.c o m*/ * @return */ public ByteBuffer marshall() { int length = getSize(); ByteBuffer buffer = ByteBuffer.allocate(length); buffer.putLong(type); buffer.putInt(length); buffer.put(payLoad); buffer.flip(); payLoad.clear(); return buffer; }
From source file:net.openhft.chronicle.wire.benchmarks.Data.java
public void copyTextTo(ByteBuffer textBuffer) { for (int i = 0; i < text.length(); i++) textBuffer.put((byte) text.charAt(i)); }
From source file:com.twitter.distributedlog.DLSN.java
/** * Serialize the DLSN into bytes with given <code>version</code>. * * @param version/*from w w w .ja va 2 s. c om*/ * version to serialize the DLSN * @return the serialized bytes */ public byte[] serializeBytes(byte version) { Preconditions.checkArgument(version <= CUR_VERSION && version >= VERSION0); byte[] data = new byte[CUR_VERSION == version ? VERSION1_LEN : VERSION0_LEN]; ByteBuffer bb = ByteBuffer.wrap(data); bb.put(version); bb.putLong(logSegmentSequenceNo); bb.putLong(entryId); bb.putLong(slotId); return data; }
From source file:com.mycompany.monroelabsm.Seed.java
public byte[] getSeed() { byte[] seed = new byte[32]; ByteBuffer bb = ByteBuffer.wrap(seed); bb.put(serial); bb.put(operator);//from w ww. j a va 2 s. co m bb.put(heading); bb.put(gpsx); bb.put(gpsy); bb.put(crypto); bb.put(fiat); bb.put(denomination); bb.put(time); return bb.array(); }
From source file:net.sf.jinsim.UDPChannel.java
@Override protected synchronized int receive(ByteBuffer buffer) throws IOException { if (cacheBuffer.position() > 0 && cacheBuffer.hasRemaining()) { buffer.put(cacheBuffer); return buffer.position(); } else {// www.j a va2s.c o m byte[] data = new byte[buffer.limit()]; cacheBuffer.clear(); SocketAddress address = datagramChannel.receive(cacheBuffer); int size = cacheBuffer.position(); if (address != null) { cacheBuffer.flip(); int remaining = cacheBuffer.remaining(); if (remaining > data.length) { remaining = data.length; } cacheBuffer.get(data, 0, remaining); buffer.put(data, 0, remaining); return data.length; } return size; } /* SocketAddress address = datagramChannel.receive(buffer); if (address != null) { System.out.println("has data: " + buffer.position()); return buffer.position(); } return 0; */ /* DatagramSocket socket = datagramChannel.socket(); receive(DatagramPacket p) */ }
From source file:edu.tsinghua.lumaqq.qq.packets.out._05.RequestAgentPacket.java
@Override protected void putBody(ByteBuffer buf) { buf.putLong(0x0100000000000000L);/*from w w w. j a v a 2 s.c o m*/ buf.putInt(0); buf.putChar((char) user.getFileAgentToken().length); buf.put(user.getFileAgentToken()); buf.put((byte) 0x04); buf.put((byte) 0x4C); buf.putInt(clusterId); buf.putInt(imageLength); buf.put(md5); buf.put(md5(fileName.getBytes())); buf.putChar((char) 0); }
From source file:com.unister.semweb.drums.file.RepairIndexTest.java
/** Converts the given array of {@link TestStorable} to a consecutive {@link ByteBuffer}. */ private ByteBuffer convert(TestStorable[] toConvert) { ByteBuffer converter = ByteBuffer.allocate(toConvert.length * globalParameters.getElementSize()); for (TestStorable oneTestStorable : toConvert) { converter.put(oneTestStorable.toByteBuffer()); }/*from ww w.j ava 2 s . c o m*/ converter.flip(); return converter; }