List of utility methods to do Convert via ByteBuffer
ByteBuffer | toBuffer(boolean[] src, int offset) to Buffer int n = src.length - offset; ensureSize(n); buffer.position(0); for (boolean value : src) buffer.put(value ? (byte) 1 : 0); return buffer; |
ByteBuffer | toBuffer(byte[] arr) to Buffer ByteBuffer buffer = ByteBuffer.allocate(arr.length);
buffer.put(arr);
buffer.flip();
return buffer.duplicate();
|
ByteBuffer | toBuffer(byte[] arr) to Buffer ByteBuffer buff = createByteBuffer(arr.length);
buff.put(arr);
buff.compact();
return buff;
|
ByteBuffer | toBuffer(int[] array) to Buffer ByteBuffer result = ByteBuffer.allocate(array.length); for (int i = 0; i < array.length; ++i) { result.put((byte) (array[i] & 0xff)); result.flip(); return result; |
ByteBuffer | toBuffer(Serializable obj) Convert a serializable object to buffer. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.flush(); ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray()); oos.close(); baos.close(); return buffer; ... |
ByteBuffer | toBuffer(String spacedHex) Convert the spaced hex form of a String into a ByteBuffer. return ByteBuffer.wrap(toByteArray(spacedHex));
|
byte[] | toByte(char data) to Byte return ByteBuffer.allocate(2).putChar(0, data).array();
|
byte[] | toByte(final char[] charArray) Converts a character array to a byte array final byte[] byteArray = new byte[charArray.length << 1]; int bpos = 0; for (final char element : charArray) { if ((byte) ((element & 0xFF00) >> 8) != 0) { byteArray[bpos] = (byte) ((element & 0xFF00) >> 8); bpos++; byteArray[bpos] = (byte) (element & 0x00FF); ... |
byte[] | toByte(int input, int count) HelperMethod to Convert int to byte[] return ByteBuffer.allocate(count).putInt(input).array();
|
byte[] | toByteArray(BitSet bits) Convert BitSet to byte array byte[] result = new byte[(bits.length() + 7) / 8]; for (int i = 0; i < bits.length(); ++i) { if (bits.get(i)) { result[i / 8] |= 1 << (i % 8); return result; |