Here you can find the source of fromBytes(byte[] buf, int off, int len)
Parameter | Description |
---|---|
buf | an array of bytes |
off | the initial offset |
len | the length |
@SuppressWarnings("deprecation") public static String fromBytes(byte[] buf, int off, int len)
//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()); } }