Java Convert via ByteBuffer stringsFromBinary(final byte[] binary)

Here you can find the source of stringsFromBinary(final byte[] binary)

Description

Utility to convert bytes to a String

License

Apache License

Parameter

Parameter Description
binary a byte array to convert to a String

Return

a String representation of the byte array

Declaration

public static String[] stringsFromBinary(final byte[] binary) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class Main {
    public static final Charset GEOWAVE_CHAR_SET = Charset.forName("ISO-8859-1");

    /**/*from   w w w  .  ja  va2 s .com*/
     * Utility to convert bytes to a String
     * 
     * @param binary
     *            a byte array to convert to a String
     * @return a String representation of the byte array
     */
    public static String[] stringsFromBinary(final byte[] binary) {
        final ByteBuffer buf = ByteBuffer.wrap(binary);
        final int count = buf.getInt();
        final String[] result = new String[count];
        for (int i = 0; i < count; i++) {
            final int size = buf.getInt();
            final byte[] strBytes = new byte[size];
            buf.get(strBytes);
            result[i] = new String(strBytes, GEOWAVE_CHAR_SET);
        }
        return result;
    }
}

Related

  1. longToIPv4(Long ip)
  2. longToLE(long lVal)
  3. longToShorts2(long value)
  4. shortToByteArray(short inShort)
  5. shortToBytes(short s)
  6. stringsToBinary(final String strings[])
  7. stringToBytes(final String inString)
  8. stringToBytes(String str)
  9. StringToData(String conv, boolean isRe, int number)