Java ByteBuffer from String asByteBuffer(String data)

Here you can find the source of asByteBuffer(String data)

Description

as Byte Buffer

License

MIT License

Declaration

public static ByteBuffer asByteBuffer(String data) 

Method Source Code


//package com.java2s;
/*/*ww  w.  jav  a 2  s  .  co m*/
 * WireSpider
 *
 * Copyright (c) 2015 kazyx
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class Main {
    public static ByteBuffer asByteBuffer(String data) {
        try {
            return ByteBuffer.wrap(data.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new UnsupportedOperationException(e);
        }
    }
}

Related

  1. asByteBuffer(String s)
  2. stringToByteBuffer(String data)
  3. stringToByteBuffer(String string)
  4. stringToNullTerminatedByteBuffer(String s)