Here you can find the source of toBytesDirect(final String singleOctets)
Parameter | Description |
---|---|
IllegalArgumentException | if the input string contains any multi-octet character |
public static byte[] toBytesDirect(final String singleOctets)
//package com.java2s; //License from project: Apache License public class Main { /**/* ww w . j a v a 2 s . com*/ * Returns a byte array representing the given string, * truncating each character into a byte directly. * * @throws IllegalArgumentException if the input string contains any multi-octet character */ public static byte[] toBytesDirect(final String singleOctets) { final char[] src = singleOctets.toCharArray(); final byte[] dest = new byte[src.length]; for (int i = 0; i < dest.length; i++) { final char c = src[i]; if (c > Byte.MAX_VALUE) throw new IllegalArgumentException( "Invalid character found at position " + i + " for " + singleOctets); dest[i] = (byte) c; } return dest; } }