List of usage examples for java.nio ByteBuffer wrap
public static ByteBuffer wrap(byte[] array)
From source file:Main.java
public static ByteBuffer rightSize(ByteBuffer in) { if (in == null) { return null; }/*from w ww . j ava2s. com*/ if (wrapsFullArray(in)) { return in; } return ByteBuffer.wrap(byteBufferToByteArray(in)); }
From source file:com.images3.data.impl.ShortUUID.java
private static byte[] toByteArray(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); }
From source file:Main.java
public static float readFloat32(byte[] value, int start, int end) { byte[] bytes = Arrays.copyOfRange(value, start, end); float result = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat(); return result; }
From source file:Main.java
public static double readFloat64(byte[] value, int start, int end) { byte[] bytes = Arrays.copyOfRange(value, start, end); double result = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getDouble(); return result; }
From source file:com.hengyi.japp.tools.UuidUtils.java
public static String decodeBase64Uuid(String compressedUuid) { byte[] byUuid = Base64.decodeBase64(compressedUuid); ByteBuffer bb = ByteBuffer.wrap(byUuid); UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }
From source file:com.pinterest.deployservice.common.CommonUtils.java
/** * TODO figure out how to use guava to achive this * * @return base64 encoded shorten UUID, e.g. 11YozyYYTvKmuUXpRDvoJA *//* w ww. j a v a 2 s .com*/ public static String getBase64UUID() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); String base64 = BaseEncoding.base64Url().omitPadding().encode(buffer.array()); if (base64.charAt(0) == '_') { return 'x' + base64.substring(1); } if (base64.charAt(0) == '-') { return 'X' + base64.substring(1); } return base64; }
From source file:Main.java
public static final ByteBuffer wrap(final ByteBuffer bb) { return (ByteBuffer) ByteBuffer.wrap(bb.array()).limit(bb.limit()).position(bb.position()); }
From source file:Main.java
public static ByteBuffer getServiceDataFromEnv(String serviceName, Map<String, String> env) { String meta = env.get(getPrefixServiceName(serviceName)); if (null == meta) { return null; }/*from w ww .j a va2 s . c o m*/ byte[] metaData = Base64.decodeBase64(meta); return ByteBuffer.wrap(metaData); }
From source file:Main.java
public static ByteBuffer getDataBuffer() { String lineSeparator = System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); sb.append("test"); sb.append(lineSeparator);//www. ja v a 2s . c o m sb.append("test"); sb.append(lineSeparator); String str = sb.toString(); Charset cs = Charset.forName("UTF-8"); ByteBuffer bb = ByteBuffer.wrap(str.getBytes(cs)); return bb; }
From source file:com.cloudera.branchreduce.impl.thrift.Writables.java
public static ByteBuffer toByteBuffer(Writable writable) { return ByteBuffer.wrap(WritableUtils.toByteArray(writable)); }