Here you can find the source of toByteBuffer(final String s)
Parameter | Description |
---|---|
s | String to convert. |
public static ByteBuffer toByteBuffer(final String s)
//package com.java2s; /* See LICENSE for licensing and NOTICE for copyright. */ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { /** Default character set for bytes is UTF-8. */ public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); /**//from w ww .ja v a 2s . c o m * Converts a string into bytes in the UTF-8 character set. * * @param s String to convert. * * @return Byte buffer containing byte representation of string. */ public static ByteBuffer toByteBuffer(final String s) { return DEFAULT_CHARSET.encode(CharBuffer.wrap(s)); } }