Java Byte Array to String bytesToString(byte[] bytes, int startIndex)

Here you can find the source of bytesToString(byte[] bytes, int startIndex)

Description

Given a byte array, restore a String out of it.

License

Open Source License

Parameter

Parameter Description
bytes the byte array
startIndex the starting index where the string is stored, the first cell stores the length

Declaration

public static String bytesToString(byte[] bytes, int startIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  w  w w .j a v  a2  s  .c om*/
     * Given a byte array, restore a String out of it. the first cell stores the length of the String
     * 
     * @param bytes
     *            the byte array
     * @param startIndex
     *            the starting index where the string is stored, the first cell stores the length
     * @ret the string out of the byte array.
     */
    public static String bytesToString(byte[] bytes, int startIndex) {
        int len = (int) (bytes[startIndex++]) & 0xff;
        return new String(bytes, startIndex, len);
    }
}

Related

  1. bytesToString(byte[] bytes)
  2. bytesToString(byte[] bytes)
  3. bytesToString(byte[] bytes)
  4. bytesToString(byte[] bytes)
  5. bytesToString(byte[] bytes, int offs, int len)
  6. bytesToString(byte[] bytes, String encoding)
  7. bytesToString(byte[] data)
  8. bytesToString(byte[] data, int start, int end)
  9. bytesToString(byte[] hasher)