Java ByteBuffer from String toByteBuffer(final String s)

Here you can find the source of toByteBuffer(final String s)

Description

Converts a string into bytes in the UTF-8 character set.

License

Open Source License

Parameter

Parameter Description
s String to convert.

Return

Byte buffer containing byte representation of string.

Declaration

public static ByteBuffer toByteBuffer(final String s) 

Method Source Code

//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));
    }
}

Related

  1. asByteBuffer(String data)
  2. asByteBuffer(String s)
  3. stringToByteBuffer(String data)
  4. stringToByteBuffer(String string)
  5. stringToNullTerminatedByteBuffer(String s)
  6. toByteBuffer(String hexStr)
  7. toByteBuffer(String s)
  8. toByteBuffer(String value)
  9. toByteBuffer(String value)