List of usage examples for java.nio ByteBuffer put
public ByteBuffer put(ByteBuffer src)
From source file:com.buaa.cfs.nfs3.FileHandle.java
private long bytesToLong(byte[] data) { ByteBuffer buffer = ByteBuffer.allocate(8); for (int i = 0; i < 8; i++) { buffer.put(data[i]); }//from w w w . jav a 2 s. co m buffer.flip();// need flip return buffer.getLong(); }
From source file:com.jivesoftware.os.rcvs.api.keys.SymetricalHashableKeyTest.java
License:asdf
public long bytesLong(byte[] bytes) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.put(bytes); buffer.flip(); //need flip return buffer.getLong(); }
From source file:com.alibaba.zonda.logger.server.writer.OutputStreamManager.java
public void writeWithLength(byte[] data, String tag) throws IOException { lock.readLock().lock();// w w w .j ava 2s . c o m try { LogOutputStream os = getOutputStream(tag); ByteBuffer bf = ByteBuffer.allocate(4 + data.length); bf.put(BytesUtil.intToBytes(data.length)); bf.put(data); bf.flip(); IOUtils.write(bf.array(), os.getStream()); os.addBytesWritten(4 + data.length); os.getStream().flush(); } finally { lock.readLock().unlock(); } }
From source file:jnative.io.AIO.java
private ByteBuffer getDirect(ByteBuffer buf) { if (buf instanceof DirectBuffer) return buf; int pos = buf.position(); int lim = buf.limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); ByteBuffer bb = ByteBuffer.allocate(rem); bb.put(buf); bb.flip();/*from w w w . j a v a 2 s .c o m*/ return bb; }
From source file:org.brekka.phalanx.core.services.impl.PasswordBasedCryptoServiceImpl.java
@Override @Transactional(propagation = Propagation.REQUIRED) public PasswordedCryptoData encrypt(Object obj, String password) { CryptoProfile cryptoProfile = cryptoProfileService.retrieveDefault(); byte[] data = toBytes(obj); DigestResult digestResult = phoenixDigest.digest(data, cryptoProfile); byte[] digest = digestResult.getDigest(); ByteBuffer dataBuffer = ByteBuffer.allocate(data.length + digest.length); dataBuffer.put(digest); dataBuffer.put(data);// ww w. j a v a 2 s .c o m data = dataBuffer.array(); byte[] key = toKey(password); DerivedKey derivedKey = phoenixDerived.apply(key, cryptoProfile); SymmetricCryptoSpec symmetricCryptoSpec = phoenixSymmetric.toSymmetricCryptoSpec(derivedKey); CryptoResult<SymmetricCryptoSpec> cryptoResult = phoenixSymmetric.encrypt(data, symmetricCryptoSpec); PasswordedCryptoData encryptedData = new PasswordedCryptoData(); encryptedData.setData(cryptoResult.getCipherText()); encryptedData.setSalt(derivedKey.getSalt()); encryptedData.setProfile(cryptoProfile.getNumber()); cryptoDataDAO.create(encryptedData); return encryptedData; }
From source file:com.offbynull.portmapper.pcp.PeerPcpRequest.java
@Override protected void dumpOpCodeSpecificInformation(ByteBuffer dst) { dst.put(mappingNonce.asReadOnlyBuffer()); dst.put((byte) protocol); for (int i = 0; i < 3; i++) { // reserved block dst.put((byte) 0); }/*w ww .j av a2s. c om*/ dst.putShort((short) internalPort); dst.putShort((short) suggestedExternalPort); dst.put(NetworkUtils.convertToIpv6Array(suggestedExternalIpAddress)); dst.putShort((short) remotePeerPort); for (int i = 0; i < 2; i++) { // reserved block dst.put((byte) 0); } dst.put(NetworkUtils.convertToIpv6Array(remotePeerIpAddress)); }
From source file:com.github.ambry.commons.BlobId.java
@Override public byte[] toBytes() { ByteBuffer idBuf = ByteBuffer.allocate(sizeInBytes()); idBuf.putShort(version);// ww w. j av a 2 s. c o m idBuf.put(partitionId.getBytes()); idBuf.putInt(uuid.getBytes().length); idBuf.put(uuid.getBytes()); return idBuf.array(); }
From source file:com.codeabovelab.dm.common.security.token.SignedTokenServiceBackend.java
private void store(ByteBuffer buffer, byte[] arr) { buffer.put((byte) arr.length); buffer.put(arr); }
From source file:org.jmangos.sniffer.handler.PKTLogHandler.java
@Override public void init() { final String date = String.format("%X", System.currentTimeMillis()); final ByteBuffer buffer = ByteBuffer.allocate(66); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.put("PKT".getBytes()); buffer.put((byte) 1); buffer.put((byte) 3); buffer.put((byte) 12); buffer.putInt(this.build); buffer.put("xxXX".getBytes()); buffer.put(this.keyReader.getKey()); buffer.putInt((int) (System.currentTimeMillis() / 1000L)); buffer.putInt(0);/*ww w . j a v a2s .c om*/ buffer.putInt(0); try { this.fous = new DataOutputStream(new FileOutputStream(new File(this.build + "_" + date + ".pkt"))); this.fous.write(buffer.array()); setInit(true); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:Base64Encoder.java
private boolean out(ByteBuffer bb, int outValue) { if (bb.remaining() > 0) { bb.put((byte) outValue); return true; } else {//from ww w . j a va 2s . c om excessByte = Byte.valueOf((byte) outValue); return false; } }