Convert the given string to a byte buffer. The resulting buffer can be
converted back to the same string through {@link #bytesToString(ByteBuffer)}.
438735
public static ByteBuffer stringToBytes(String s) {
    return Unpooled.wrappedBuffer(s.getBytes(StandardCharsets.UTF_8)).nioBuffer();
  }
787348
static public String decodeString(final ByteBuffer bb) {
        final int strlength = bb.getInt();
        final int position = bb.position();
        String decoded = new String(bb.array(), bb.arrayOffset() + position, strlength, Charsets.UTF_8);
        bb.position(position + strlength);
        return decoded;
    }
380254
public static ByteBuffer encode(String text, Charset charset) {
		return encode(text.getBytes(charset));
	}
1285377
private static String inputStreamToString(InputStream stream)
			throws IOException {
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		String resultString = null;
		while ((length = stream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		resultString = result.toString("UTF-8");
		return resultString;
	}
59451
public static byte[] bufferToArray(ByteBuffer buffer) {
    if (buffer.hasArray() && buffer.arrayOffset() == 0 &&
        buffer.array().length == buffer.remaining()) {
      return buffer.array();
    } else {
      byte[] bytes = new byte[buffer.remaining()];
      buffer.get(bytes);
      return bytes;
    }
  }
952654
@Override
	public String saveToString() {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		saveTo(baos);
		return new String(baos.toByteArray());
	}
1128613
protected ByteBuffer getByteBuffer(int bufferLength) {
        if(_buffer == null) {
            _buffer = ByteBuffer.wrap(new byte[bufferLength]);
            _log.info("ByteBuffer allocated for buffering");
        }
        
        return _buffer;
    }
1249556
public static ByteBuffer bytes(String s)
    {
        return ByteBuffer.wrap(s.getBytes(StandardCharsets.UTF_8));
    }
372188
public static String string(byte[] bytes) {
    if (bytes == null) {
      return null;
    }
    try {
      return new String(bytes, ENCODING);
    } catch (UnsupportedEncodingException e) {
      log.error("UnsupportedEncodingException ", e);
      throw new RuntimeException(e);
    }
  }
396032
public static String getString(ByteBuffer buf, int offset, int length, Charset encoding) {
        buf = buf.duplicate();
        buf.position(buf.position() + offset);
        if (buf.hasArray()) {
            return new String(buf.array(), buf.arrayOffset() + buf.position(), length, encoding);
        } else {
            byte[] bytes = new byte[length];
            buf.get(bytes);
            return new String(bytes, encoding);
        }
    }
26523
public static ByteBuffer toByteBuffer(String s) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(s.length());
        buffer.put(s.getBytes(UTF_8));
        buffer.flip();
        return buffer;
    }
958943
private static byte[] stringToBytes(String text) {
        byte[] data;
        try {
            data = text.getBytes(Charset.forName(StandardCharsets.UTF_8.name()));
        } catch (UnsupportedCharsetException ex) {
            data = text.getBytes(Charset.defaultCharset());
        }
        return data;
    }
424824
public static ByteBuffer decode(String input) throws IOException {
		return decode(input.getBytes(StandardCharsets.US_ASCII));
	}
568654
public static String string(ByteBuffer buffer, Charset charset) throws CharacterCodingException
	    {
	        return charset.newDecoder().decode(buffer.duplicate()).toString();
	    }
645437
private static byte[] stringToByteArray(String str) {
		byte[] result = new byte[str.length() + 1];
		for (int i = 0; i < str.length(); i++) {
			result[i] = (byte) str.charAt(i);
		}
		result[str.length()] = 0;
		return result;
	}
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());
    }
1090178
@Override
	public void writeString(String str) throws IOException {
		byte[] bytes = Utf8.getBytesFor(str);
		writeBytes(bytes, 0, bytes.length);
	}