Here you can find the source of fromBytes(byte[] buf)
Parameter | Description |
---|---|
buf | an array of bytes |
public static String fromBytes(byte[] buf)
//package com.java2s; import java.nio.ByteBuffer; public class Main { /**/*from w w w . j a va2s .c o m*/ * 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()); } }