Answer a {@code byte[]} from {@code body} bytes.
@param body the ByteBuffer
@return String
488654
private static byte[] bufferToArray(final ByteBuffer body) {
    if (body.position() > 0) {
      body.flip();
    }
    final int length = body.limit();
    final byte[] bytes = new byte[length];
    System.arraycopy(body.array(), 0, bytes, 0, length);
    return bytes;
  }
128742
public static byte[] getBytes(String text) {
		byte[] bytes = new byte[] {};
		try {
			bytes = text.getBytes("utf-8");
		} catch (UnsupportedEncodingException e) {
		}
		return bytes;
	}
675580
public static byte[] stringUToByteArr(String s) {
    char c;
    byte[] b = new byte[2 * s.length()];
    for (int i = 0; i < s.length(); i++) {
      c = s.charAt(i);
      b[2 * i + 1] = (byte) c;
      b[2 * i] = (byte) (c >> 8);
    }
    return b;
  }
8142
public static byte[] bytes(String s) {
    try {
      return s.getBytes(ENCODING);
    } catch (UnsupportedEncodingException e) {
      log.error("UnsupportedEncodingException ", e);
      throw new RuntimeException(e);
    }
  }
983135
public <T> Message body(T body, Charset charset) {
        messageWriter.writeBody(body, charset);
        return this;
    }
428922
public static HttpResponse response(String body) {
        return new HttpResponse().withStatusCode(OK_200.code()).withReasonPhrase(OK_200.reasonPhrase()).withBody(body);
    }
1009266
public static String byteArrayToNumString(byte[] b) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			sb.append(byteToNumString(b[i]));
		}
		return new String(sb);
	}
1234342
public static String byteBufferToString (final ByteBuffer buffer) {

        if (buffer == null) return "null";

        final int numberOfBytes = buffer.limit();

        final StringBuilder sb = new StringBuilder();
        buffer.position(0);
        int value;
        for (int i = 1; i <= numberOfBytes; ++i) {
            sb.append("0x");
            value = 255 & buffer.get();
            if (value < 16) sb.append("0");
            sb.append(Integer.toHexString(value));
            if (i % BYTES_PER_LINE == 0)
                sb.append("\n");
            else
                sb.append("   ");
        }

        return sb.toString();
    }
323971
public static final Bytes of(CharSequence cs) {
    if (cs instanceof String) {
      return of((String) cs);
    }

    Objects.requireNonNull(cs);
    if (cs.length() == 0) {
      return EMPTY;
    }

    ByteBuffer bb = StandardCharsets.UTF_8.encode(CharBuffer.wrap(cs));

    if (bb.hasArray()) {
      // this byte buffer has never escaped so can use its byte array directly
      return new Bytes(bb.array(), bb.position() + bb.arrayOffset(), bb.limit());
    } else {
      byte[] data = new byte[bb.remaining()];
      bb.get(data);
      return new Bytes(data);
    }
  }
1350167
public static byte[] asArray(ByteBuffer byteBuffer) {
        ByteBuffer bb = ByteBufferUtil.clone(byteBuffer);
        byte[] bytes = new byte[bb.remaining()];
        bb.get(bytes);
        return bytes;
    }
1075681
public static byte[] toArray(ByteBuffer bytebuffer) {
		if (false == bytebuffer.hasArray()) {
			int oldPosition = bytebuffer.position();
			bytebuffer.position(0);
			int size = bytebuffer.limit();
			byte[] buffers = new byte[size];
			bytebuffer.get(buffers);
			bytebuffer.position(oldPosition);
			return buffers;
		} else {
			return Arrays.copyOfRange(bytebuffer.array(), bytebuffer.position(), bytebuffer.limit());
		}
	}
1184118
public ByteBuffer getByteBuffer() {
		final ByteBuffer bb = ByteBuffer.wrap(buf);
		bb.limit(bufLimit);
		bb.position(bufPosition);
		return bb;
	}
1195408
public byte decodeBuffer(String inputString)[] throws IOException {
        byte    inputBuffer[] = new byte[inputString.length()];
        ByteArrayInputStream inStream;
        ByteArrayOutputStream outStream;

        inputString.getBytes(0, inputString.length(), inputBuffer, 0);
        inStream = new ByteArrayInputStream(inputBuffer);
        outStream = new ByteArrayOutputStream();
        decodeBuffer(inStream, outStream);
        return (outStream.toByteArray());
    }
1043968
public static byte[] getBytes(Object o)
    {
        if (o != null)
        {
            return getBytes(o, o.getClass());
        }

        return null;
    }
60633
public static byte[] readHttpRequestBody(HttpExchange exchange) {
    // Get the length of request body
    int contentLength = Integer.parseInt(exchange.getRequestHeaders().getFirst(CONTENT_LENGTH));

    if (contentLength <= 0) {
      LOG.log(Level.SEVERE, "Failed to read content length http request body: " + contentLength);
      return new byte[0];
    }
    byte[] requestBody = new byte[contentLength];

    InputStream is = exchange.getRequestBody();
    try {
      int off = 0;
      int bRead = 0;
      while (off != (contentLength - 1)
          && (bRead = is.read(requestBody, off, contentLength - off)) != -1) {
        off += bRead;
      }
    } catch (IOException e) {
      LOG.log(Level.SEVERE, "Failed to read http request body: ", e);
      return new byte[0];
    } finally {
      try {
        is.close();
      } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to close InputStream: ", e);
        return new byte[0];
      }
    }

    return requestBody;
  }
893090
public static String byteArrayToString(byte[] b) {
       final int l = b.length/2;
       if (l*2 != b.length) throw new IllegalArgumentException();
       StringBuffer result = new StringBuffer(l);
       int o = 0;
       for (int i = 0; i < l; i++)
       {
           int i1 = b[o++] & 0xff;
           int i2 = b[o++] & 0xff;
           i2 = i2 << 8;
           i1 = i1 | i2;
           result.append((char)i1);
       }
       return (result.toString());
    }
965069
public byte[] readToBytes() {
        try {
            try (InputStream in = body()) {
                return InputStreams.readAll(in);
            }
        } catch (IOException e) {
            throw new RequestsException(e);
        } finally {
            close();
        }
    }