Android Byte Array to String Convert fromBytes(byte[] buf, int off, int len)

Here you can find the source of fromBytes(byte[] buf, int off, int len)

Description

Return a new String with chars corresponding to buf from off to off + len.

License

Open Source License

Parameter

Parameter Description
buf an array of bytes
off the initial offset
len the length

Return

a new String corresponding to the bytes in buf

Declaration

@SuppressWarnings("deprecation")
public static String fromBytes(byte[] buf, int off, int len) 

Method Source Code

//package com.java2s;

import java.nio.ByteBuffer;

public class Main {
    /**/* w  w w  .ja v  a 2  s  .c  om*/
     * Return a new String with chars corresponding to buf from off to
     * off + len.
     *
     * @param buf an array of bytes
     * @param off the initial offset
     * @param len the length
     * @return a new String corresponding to the bytes in buf
     */
    @SuppressWarnings("deprecation")
    public static String fromBytes(byte[] buf, int off, int len) {
        // Yes, I known the method is deprecated, but it is the fastest
        // way of converting between between byte[] and String
        return new String(buf, 0, off, len);
    }

    /**
     * Return a new String with chars corresponding to buf.
     *
     * @param buf an array of bytes
     * @return a new String corresponding to the bytes in buf
     */
    public static String fromBytes(byte[] buf) {
        return fromBytes(buf, 0, buf.length);
    }

    /**
     * Return a new String with chars corresponding to buf.
     *
     * @param buf a ByteBuffer of bytes
     * @return a new String corresponding to the bytes in buf
     */
    public static String fromBytes(ByteBuffer buf) {
        return fromBytes(buf.array(), buf.arrayOffset() + buf.position(),
                buf.arrayOffset() + buf.limit());
    }
}

Related

  1. toString(byte[] array)
  2. toString(byte[] array, String separator, int frequency)
  3. toString(byte[] b)
  4. toString(byte[] theByteArray)
  5. fromBytes(byte[] buf)
  6. bytes2String(byte[] value)
  7. byte2String(byte[] is)
  8. loadConvert(byte[] s, int offset, boolean lengthFlag)
  9. getStringForByte(byte[] bs)