Creates a UTF8_CHARSET string from a byte array.

@param bytes  the byte array.
@param offset the index of the first byte to decode
@param length the number of bytes to decode
@return the string created from the byte array.
771326
public static String bytesToString(byte[] bytes, int offset, int length) {
        return new String(bytes, offset, length, UTF8_CHARSET);
    }
210620
private long fourByteToLong(byte[] bytes, int offset) {
        return (byteToLong(bytes[offset + 0])
                + (byteToLong(bytes[offset + 1]) << 8)
                + (byteToLong(bytes[offset + 2]) << 16)
                + (byteToLong(bytes[offset + 3]) << 24));
    }
1299548
def read_utf8_string(self, length):
        
        s = struct.unpack("%s%ds" % (self.endian, length), self.read(length))[0]

        return s.decode('utf-8')
627170
public static String bytes2String(byte[] bytes) {
    try {
      final int len = bytes.length;
      char[] charArray = UTF8.getCharArray(len);
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] < UTF8.MIN_ASCII_CODE) {
          // non-ASCII codepoints' higher bytes
          // are of the form (10xxxxxx), hence the bytes
          // represent a non-ASCII string
          // do expensive conversion
          return new String(bytes, utf8charsetName);
        }
        // copy to temporary array
        charArray[i] = (char) bytes[i];
      }
      // only ASCII bytes, do fast conversion
      // using bytes as actual characters
      return new String(charArray, 0, len);
    } catch (UnsupportedEncodingException e) {
      assert false : "UTF8 encoding is not supported ";
    }
    return null;
  }
396032
public static String getString(ByteBuffer buf, int offset, int length, Charset encoding) {
        buf = buf.duplicate();
        buf.position(buf.position() + offset);
        if (buf.hasArray()) {
            return new String(buf.array(), buf.arrayOffset() + buf.position(), length, encoding);
        } else {
            byte[] bytes = new byte[length];
            buf.get(bytes);
            return new String(bytes, encoding);
        }
    }
97313
public static ByteBuffer fromUtf8String(CharSequence utfString) {
        if (utfString == null || utfString.length() == 0) {
            return Buffers.EMPTY_BYTE_BUFFER;
        } else {
            return ByteBuffer.wrap(utfString.toString().getBytes(StandardCharsets.UTF_8));
        }
    }
728488
public static final String toHex(byte[] buf, int offset, int length)
    {
        return toHex(Arrays.copyOfRange(buf, offset, offset+length));
    }
19538
public static long bytesToLong(byte[] bytes, int offset) {
        long result = 0x0;
        for (int i = offset; i < offset + 8; ++i) {
            result = result << 8;
            result |= (bytes[i] & 0x00000000000000FFl);
        }
        return result;
    }
435384
public static UTF8String fromAddress(Object base, long offset, int numBytes) {
    return new UTF8String(base, offset, numBytes);
  }
952737
public static String decode(byte[] in, char[] out, int offset, int utfSize) throws UTFDataFormatException {
        int count = 0, s = 0, a;
        while (count < utfSize) {
            if ((out[s] = (char) in[offset + count++]) < '\u0080') {
                s++;
            } else if (((a = out[s]) & 0xe0) == 0xc0) {
                if (count >= utfSize) {
                    throw new UTFDataFormatException("bad second byte at " + count);
                }
                int b = in[offset + count++];
                if ((b & 0xC0) != 0x80) {
                    throw new UTFDataFormatException("bad second byte at " + (count - 1));
                }
                out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
            } else if ((a & 0xf0) == 0xe0) {
                if (count + 1 >= utfSize) {
                    throw new UTFDataFormatException("bad third byte at " + (count + 1));
                }
                int b = in[offset + count++];
                int c = in[offset + count++];
                if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
                    throw new UTFDataFormatException("bad second or third byte at " + (count - 2));
                }
                out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
            } else {
                throw new UTFDataFormatException("bad byte at " + (count - 1));
            }
        }
        return new String(out, 0, s);
    }
949602
public static void decodeTo(byte[] data, int offset, int length, MultiMap map, String charset)
    {
        if (data == null || length == 0)
            return;

        if (charset==null)
            charset=StringUtil.__ISO_8859_1;
        
        synchronized(map)
        {
            try
            {
                int    ix = offset;
                int    end = offset+length;
                int    ox = offset;
                String key = null;
                String value = null;
                while (ix < end)
                {
                    byte c = data[ix++];
                    switch ((char) c)
                    {
                      case '&':
                          value = new String(data, offset, ox, charset);
                          if (key != null)
                          {
                              map.add(key,value);
                              key = null;
                          }
                          ox = offset;
                          break;
                      case '=':
                          if (key!=null)
                              break;
                          key = new String(data, offset, ox, charset);
                          ox = offset;
                          break;
                      case '+':
                          data[ox++] = (byte)' ';
                          break;
                      case '%':
                          int i0 = (14<<4)+1;
                          byte b0 = (byte)i0;
                          data[ox++] = (byte)
                              ((TypeUtil.convertHexDigit(data[ix++]) << 4)+
                               TypeUtil.convertHexDigit(data[ix++]));
                          break;
                      default:
                          data[ox++] = c;
                    }
                }
                if (key != null)
                {
                    value = new String(data, offset, ox, charset);
                    map.add(key,value);
                }
            }
            catch(UnsupportedEncodingException e)
            {
                log.warn(LogSupport.EXCEPTION,e);
            }
        }
    }
217289
public static String toHexString(byte[] b, int offset, int length) {
        StringBuilder buf = new StringBuilder();
        for (int i = offset; i < offset + length; i++) {
            int bi = 0xff & b[i];
            int c = '0' + (bi / 16) % 16;
            if (c > '9') {
                c = 'A' + (c - '0' - 10);
            }
            buf.append((char) c);
            c = '0' + bi % 16;
            if (c > '9') {
                c = 'a' + (c - '0' - 10);
            }
            buf.append((char) c);
        }
        return buf.toString();
    }
1312884
public static UTF8String fromBytes(byte[] bytes, int offset, int numBytes) {
    if (bytes != null) {
      return new UTF8String(bytes, BYTE_ARRAY_OFFSET + offset, numBytes);
    } else {
      return null;
    }
  }
201393
private static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int v = bytes[i] & 0xFF;
            hexChars[i * 2] = hexArray[v >>> 4];
            hexChars[i * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
767721
private static String toAsciiString(byte[] bytes) {
        for(int i = 0; i < bytes.length; i++) {
            if(bytes[i] < 0) return null;
        }
        char[] chars = new char[bytes.length];
        for(int i = 0; i < bytes.length; i++) {
            chars[i] = (char)bytes[i];
        }
        return new String(chars);
    }
657694
public static String data(byte[] data, int offset, int length) {
        try {
            return stream(new ByteArrayInputStream(data, offset, length), length);
        } catch (IOException e) {
            throw new AssertionError(e);
        }
    }
489924
public static final Bytes of(byte[] data, int offset, int length) {
    Objects.requireNonNull(data);
    if (length == 0) {
      return EMPTY;
    }
    byte[] copy = new byte[length];
    System.arraycopy(data, offset, copy, 0, length);
    return new Bytes(copy);
  }