Java Byte Array Convert To bytesToStringUTFCustom(byte[] bytes)

Here you can find the source of bytesToStringUTFCustom(byte[] bytes)

Description

Use during externalization methods....FAST as it avoids charset encoding From http://www.javacodegeeks.com/2010/11/java-best-practices-char-to-byte-and.html

License

Apache License

Parameter

Parameter Description
str a parameter

Declaration

public static String bytesToStringUTFCustom(byte[] bytes) 

Method Source Code

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

public class Main {
    /**//from  www .j  a  v a  2s . c  o  m
     * Use during externalization methods....FAST as it avoids charset encoding
     * From http://www.javacodegeeks.com/2010/11/java-best-practices-char-to-byte-and.html
     * @param str
     * @return
     */
    public static String bytesToStringUTFCustom(byte[] bytes) {
        char[] buffer = new char[bytes.length >> 1];
        for (int i = 0; i < buffer.length; i++) {
            int bpos = i << 1;
            char c = (char) (((bytes[bpos] & 0x00FF) << 8) + (bytes[bpos + 1] & 0x00FF));
            buffer[i] = c;
        }
        return new String(buffer);
    }
}

Related

  1. bytesToSectors(long bytes)
  2. bytesToSignedInt(byte bb1, byte bb2)
  3. bytesToStore(int bits)
  4. bytesToStringAscii(byte[] bytes)
  5. bytesToStringMac(byte[] mac)
  6. bytesToSVar64(final byte[] buffer, final int offset)
  7. bytesToTagBE(byte[] bytes, int off)
  8. bytesToText(byte[] bytes)
  9. BytesToUInt16(byte[] pb)