List of usage examples for java.nio ByteBuffer wrap
public static ByteBuffer wrap(byte[] array)
From source file:com.metawiring.load.generators.RandomBytesGenerator.java
@Override public ByteBuffer get() { byte[] buffer = new byte[length]; twister.nextBytes(buffer);/*from w w w.j av a 2 s . c o m*/ return ByteBuffer.wrap(buffer); }
From source file:com.FalcoLabs.Fido.api.datastore.serializers.BinarySerializer.java
public ByteBuffer toByteBuffer(T obj) { byte[] bytes = SerializationUtils.serialize((Serializable) obj); return ByteBuffer.wrap(bytes); }
From source file:Main.java
/** * Parse UUID from bytes. The {@code uuidBytes} can represent a 16-bit, 32-bit or 128-bit UUID, * but the returned UUID is always in 128-bit format. * Note UUID is little endian in Bluetooth. * * @param uuidBytes Byte representation of uuid. * @return {@link ParcelUuid} parsed from bytes. * @throws IllegalArgumentException If the {@code uuidBytes} cannot be parsed. *///from w w w .ja v a2 s . co m public static ParcelUuid parseUuidFrom(byte[] uuidBytes) { if (uuidBytes == null) { throw new IllegalArgumentException("uuidBytes cannot be null"); } int length = uuidBytes.length; if (length != UUID_BYTES_16_BIT && length != UUID_BYTES_32_BIT && length != UUID_BYTES_128_BIT) { throw new IllegalArgumentException("uuidBytes length invalid - " + length); } // Construct a 128 bit UUID. if (length == UUID_BYTES_128_BIT) { ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN); long msb = buf.getLong(8); long lsb = buf.getLong(0); return new ParcelUuid(new UUID(msb, lsb)); } // For 16 bit and 32 bit UUID we need to convert them to 128 bit value. // 128_bit_value = uuid * 2^96 + BASE_UUID long shortUuid; if (length == UUID_BYTES_16_BIT) { shortUuid = uuidBytes[0] & 0xFF; shortUuid += (uuidBytes[1] & 0xFF) << 8; } else { shortUuid = uuidBytes[0] & 0xFF; shortUuid += (uuidBytes[1] & 0xFF) << 8; shortUuid += (uuidBytes[2] & 0xFF) << 16; shortUuid += (uuidBytes[3] & 0xFF) << 24; } long msb = BASE_UUID.getUuid().getMostSignificantBits() + (shortUuid << 32); long lsb = BASE_UUID.getUuid().getLeastSignificantBits(); return new ParcelUuid(new UUID(msb, lsb)); }
From source file:org.elasticsoftware.elasticactors.base.serialization.JacksonMessageSerializer.java
@Override public ByteBuffer serialize(T object) throws IOException { return ByteBuffer.wrap(objectMapper.writeValueAsBytes(object)); }
From source file:com.inmobi.messaging.util.AuditUtil.java
public static ByteBuffer removeHeader(byte[] data) { if (isValidHeaders(data)) { return ByteBuffer.wrap(Arrays.copyOfRange(data, HEADER_LENGTH, data.length)); } else {//from w w w . j a va 2s.c om return ByteBuffer.wrap(data); } }
From source file:org.springframework.cloud.sleuth.stream.Host.java
public int getIpv4() { InetAddress inetAddress = null; try {/* w ww . ja v a 2 s .com*/ inetAddress = InetAddress.getByName(this.address); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } return ByteBuffer.wrap(inetAddress.getAddress()).getInt(); }
From source file:Main.java
/** * non-premultiplied alpha version of GLUtils.texImage2D(). Note: this method is Slow and should only be used when really necessary! * * @param gl// www. j a va 2s. c o m * @param bitmap * @see GLUtils.texImage2D() */ public static void texImage2DNonPremultipliedAlpha(final GL10 gl, final Bitmap bitmap) { final int[] pixels = extractPixels(bitmap); final byte[] pixelComponents = new byte[pixels.length * 4]; int byteIndex = 0, p; for (int i = 0; i < pixels.length; i++) { p = pixels[i]; // Convert to byte representation RGBA required by gl.glTexImage2D. pixelComponents[byteIndex++] = (byte) ((p >> 16) & 0xFF); // red pixelComponents[byteIndex++] = (byte) ((p >> 8) & 0xFF); // pixelComponents[byteIndex++] = (byte) ((p) & 0xFF); // blue pixelComponents[byteIndex++] = (byte) (p >> 24); // alpha } gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(), 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ByteBuffer.wrap(pixelComponents)); }
From source file:ezbake.frack.submitter.util.UnzipUtilTest.java
@Test public void testUnzip() throws IOException { File unzipped = null;//from ww w .java 2s.co m try { InputStream is = getClass().getResourceAsStream("/example.tar.gz"); byte[] tarGzBytes = IOUtils.toByteArray(is); is.close(); unzipped = UnzipUtil.unzip(new File(System.getProperty("user.dir")), ByteBuffer.wrap(tarGzBytes)); assertTrue("Unzipped folder exists", unzipped.exists()); assertTrue("Unzipped folder is a folder", unzipped.isDirectory()); Optional<String> jarPath = UnzipUtil.getJarPath(unzipped); assertTrue("Jar path exists", jarPath.isPresent()); File jarFile = new File(jarPath.get()); assertEquals("Jar path has correct name", "example.jar", jarFile.getName()); assertEquals("Jar has correct parent", "bin", jarFile.getParentFile().getName()); Optional<String> confPath = UnzipUtil.getConfDirectory(unzipped); assertTrue("Conf path exists", confPath.isPresent()); File confDir = new File(confPath.get()); Optional<String> sslPath = UnzipUtil.getSSLPath(confDir); assertTrue("SSL path exists", sslPath.isPresent()); File keyPath = UnzipUtil.findSubDir(confDir, "keys"); assertTrue("Keys path exists", keyPath.exists()); } finally { if (unzipped != null && unzipped.exists()) { FileUtils.deleteDirectory(unzipped); } } }
From source file:com.liveramp.cascading_ext.Bytes.java
public static ByteBuffer bytesWriteableToByteBuffer(BytesWritable writable) { return ByteBuffer.wrap(getBytes(writable)); }
From source file:com.networknt.light.util.HashUtil.java
public static String generateUUID() { UUID id = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(id.getMostSignificantBits()); bb.putLong(id.getLeastSignificantBits()); Base64 base64 = new Base64(); return base64.encodeBase64URLSafeString(bb.array()); }