List of usage examples for java.nio ByteBuffer array
public final byte[] array()
From source file:com.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java
private byte[] getCleanedBytes(char[] password) { final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password); final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars)); final byte[] byteArray = new byte[byteBuffer.remaining()]; byteBuffer.get(byteArray);//ww w .j a va 2s . com Arrays.fill(byteBuffer.array(), (byte) 0); return byteArray; }
From source file:com.joyent.manta.http.entity.DigestedEntity.java
@Override public void writeTo(final OutputStream out) throws IOException { digest.reset(); // reset the digest state in case we're in a retry // If our wrapped entity is backed by a buffer of some form // we can read easily read the whole buffer into our message digest. if (wrapped instanceof MemoryBackedEntity) { final MemoryBackedEntity entity = (MemoryBackedEntity) wrapped; final ByteBuffer backingBuffer = entity.getBackingBuffer(); if (backingBuffer.hasArray()) { final byte[] bytes = backingBuffer.array(); final int offset = backingBuffer.arrayOffset(); final int position = backingBuffer.position(); final int limit = backingBuffer.limit(); digest.update(bytes, offset + position, limit - position); backingBuffer.position(limit); wrapped.writeTo(out);/*from w w w .java 2 s .c o m*/ } } else { try (DigestOutputStream dout = new DigestOutputStream(digest); TeeOutputStream teeOut = new TeeOutputStream(out, dout)) { wrapped.writeTo(teeOut); teeOut.flush(); } } }
From source file:com.sm.store.utils.FileStore.java
private byte[] readChannel(long offset2len, FileChannel channel) throws IOException { long offset = getOffset(offset2len); int len = getLen(offset2len); ByteBuffer data = ByteBuffer.allocate(len); channel.read(data, offset);// w w w. jav a2s .c o m return data.array(); }
From source file:com.shuffle.p2p.Bytestring.java
public Bytestring prepend(Bytestring pre) { ByteBuffer target = ByteBuffer.wrap(new byte[bytes.length + pre.bytes.length]); target.put(pre.bytes);/*from w w w . ja v a2 s .com*/ target.put(bytes); return new Bytestring(target.array()); }
From source file:com.metamx.collections.spatial.search.RectangularBound.java
@Override public byte[] getCacheKey() { ByteBuffer minCoordsBuffer = ByteBuffer.allocate(minCoords.length * Floats.BYTES); minCoordsBuffer.asFloatBuffer().put(minCoords); final byte[] minCoordsCacheKey = minCoordsBuffer.array(); ByteBuffer maxCoordsBuffer = ByteBuffer.allocate(maxCoords.length * Floats.BYTES); maxCoordsBuffer.asFloatBuffer().put(maxCoords); final byte[] maxCoordsCacheKey = maxCoordsBuffer.array(); final ByteBuffer cacheKey = ByteBuffer.allocate(1 + minCoordsCacheKey.length + maxCoordsCacheKey.length) .put(minCoordsCacheKey).put(maxCoordsCacheKey).put(CACHE_TYPE_ID); return cacheKey.array(); }
From source file:cn.ac.ncic.mastiff.io.coding.MVDecoder.java
public void ensureDecompress() throws IOException { if (compressAlgo != null && page == null) { org.apache.hadoop.io.compress.Decompressor decompressor = this.compressAlgo.getDecompressor(); InputStream is = this.compressAlgo.createDecompressionStream(inBuf, decompressor, 0); ByteBuffer buf = ByteBuffer.allocate(decompressedSize); IOUtils.readFully(is, buf.array(), 3 * Bytes.SIZEOF_INT, buf.capacity() - 3 * Bytes.SIZEOF_INT); is.close();/*from w w w . j a v a 2s. co m*/ this.compressAlgo.returnDecompressor(decompressor); page = buf.array(); } }
From source file:net.phoenix.thrift.hello.ThreadPoolTest.java
@Test public void testByteBuffer() throws TException, IOException, InterruptedException { LOG.info("Client starting...."); String name = "Hello "; // TTransport transport = new TNonblockingSocket("localhost", 9804); TTransport transport = new TSocket("localhost", 9804); transport.open();/*from w ww. j a va 2 s . c om*/ // TTransport transport = new TTransport(socket); TProtocol protocol = new TBinaryProtocol(transport); HelloService.Client client = new HelloService.Client(protocol); try { // System.out.println("start request. "); Hello.HelloRequest.Builder request = Hello.HelloRequest.newBuilder(); request.setName(name); Hello.User.Builder user = Hello.User.newBuilder(); user.setName("hello"); user.setPassword("hello"); request.setUser(user.build()); ByteBuffer requestBuffer = ByteBuffer.wrap(request.build().toByteArray()); ByteBuffer buffer = client.hello(requestBuffer); Hello.HelloResponse response = Hello.HelloResponse .parseFrom(ArrayUtils.subarray(buffer.array(), buffer.position(), buffer.limit())); String message = response.getMessage(); assertEquals(message, "Hello " + name); // System.out.println(message); } finally { transport.close(); } }
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);//from w ww . j a v a 2 s.c om dataBuffer.put(data); 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.hazelcast.simulator.probes.xml.HistogramConverter.java
@Override public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext marshallingContext) { Histogram histogram = (Histogram) object; int size = histogram.getNeededByteBufferCapacity(); ByteBuffer byteBuffer = ByteBuffer.allocate(size); int bytesWritten = histogram.encodeIntoCompressedByteBuffer(byteBuffer); byteBuffer.rewind();/*from w w w . j a v a 2 s . c om*/ byteBuffer.limit(bytesWritten); String encodedHistogram = encodeBase64String(byteBuffer.array()); writer.setValue(encodedHistogram); }
From source file:com.delphix.session.service.ServiceUUID.java
@Override public byte[] getBytes() { ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); return buffer.array(); }