public static byte [ ] toBytes ( String str ) { if ( str == null ) { return new byte [ 0 ] ; } byte [ ] val = null ; try { val = str . getBytes ( CHARSET ) ; } catch ( UnsupportedEncodingException e ) { // NOPMD - ignore empty catch // Can never occur since CHARSET is correct and final } return val ; }
Encodes the String str into a sequence of bytes using the character set specified in CHARSET storing the result into a new byte array .