Java Utililty Methods Convert via ByteBuffer

List of utility methods to do Convert via ByteBuffer

Description

The list of methods to do Convert via ByteBuffer are organized into topic(s).

Method

byte[]stringsToBinary(final String strings[])
Utility to convert a String to bytes
int len = 4;
final List<byte[]> strsBytes = new ArrayList<byte[]>();
for (final String str : strings) {
    final byte[] strByte = str.getBytes(GEOWAVE_CHAR_SET);
    strsBytes.add(strByte);
    len += (strByte.length + 4);
final ByteBuffer buf = ByteBuffer.allocate(len);
...
byte[]stringToBytes(final String inString)
Converts a String to UTF-8 bytes.
final CharsetEncoder enc = Charset.forName("UTF-8").newEncoder();
enc.onMalformedInput(CodingErrorAction.REPORT);
enc.onUnmappableCharacter(CodingErrorAction.REPORT);
final CharBuffer cb = CharBuffer.wrap(inString);
ByteBuffer bb;
try {
    bb = enc.encode(cb);
} catch (final CharacterCodingException e) {
...
byte[]stringToBytes(String str)
string To Bytes
StringBuffer sb = new StringBuffer(str);
char c = sb.charAt(0);
ByteBuffer buffer = ByteBuffer.allocate(sb.length() * 2);
int index = 0;
while (index < sb.length()) {
    buffer.putChar(sb.charAt(index++));
return buffer.array();
...
VectorStringToData(String conv, boolean isRe, int number)
String To Data
String alpha = "abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
int counter = 0;
Vector<Object[]> va = new Vector<Object[]>();
String[] lines = conv.split("\n");
Object[] oa;
String[] sa;
for (int i = 0; i < lines.length; i++) {
    if (lines[i].indexOf("\t") > -1) {
...
intstringToIpAddress(String s)
string To Ip Address
try {
    return ByteBuffer.wrap(InetAddress.getByName(s).getAddress()).getInt();
} catch (UnknownHostException e) {
    return -1;
longstringToLong(String offsetString)
string To Long
if (offsetString.charAt(0) == '0') {
    if (offsetString.length() > 1 && (offsetString.charAt(1) == 'x' || offsetString.charAt(1) == 'X')) {
        String ss = offsetString.substring(2);
        try {
            return Long.parseLong(ss, 16);
        } catch (NumberFormatException nfe) {
            byte[] bytes = hex2Bytes(ss);
            ByteBuffer bb = ByteBuffer.allocate(8).wrap(bytes).order(ByteOrder.BIG_ENDIAN);
...
longstringToLongUnknownLength(String str, int startIndex)
string To Long Unknown Length
for (int i = startIndex; i < str.length(); i++) {
    char c = str.charAt(i);
    switch (c) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
...
int[]to32BitsLongArray(byte[] data, boolean bigEndian)
to Bits Long Array
ByteBuffer byteBuffer = ByteBuffer.wrap(data);
if (bigEndian) {
    byteBuffer.order(ByteOrder.BIG_ENDIAN);
} else {
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
LongBuffer longBuf = byteBuffer.asLongBuffer();
long[] array = new long[longBuf.remaining()];
...
ByteBuffer[]toArray(final byte[] byteArray, final int sizeLimit)
Splits the specified byte array into an array of ByteBuffer s, each with the specified maximum size.
final int numBufs = (int) Math.ceil((double) byteArray.length / (double) sizeLimit);
final ByteBuffer[] bufs = new ByteBuffer[numBufs];
int byteIndex = 0;
for (int i = 0; i < numBufs; i++) {
    final int numBytes;
    final int remaining = byteArray.length - byteIndex;
    if (remaining < sizeLimit) {
        numBytes = remaining;
...
byte[]toArray(int value)
to Array
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.BIG_ENDIAN);
buffer.putInt(value);
buffer.flip();
return buffer.array();