001    package com.nimbusds.jose.util;
002    
003    
004    import java.io.UnsupportedEncodingException;
005    
006    import com.nimbusds.jose.JOSEException;
007    
008    
009    /**
010     * String utilities.
011     *
012     * @author Vladimir Dzhuvinov
013     * @version $version$ (2013-05-06)
014     */
015    public class StringUtils {
016    
017    
018            /**
019             * Converts the specified string to a byte array.
020             *
021             * @param s The input string to convert. Must be UTF-8 encoded and not
022             *          {@code null}.
023             *
024             * @return The resulting byte array.
025             *
026             * @throws JOSEException If UTF-8 encoding is not supported.
027             */
028            public static byte[] toByteArray(final String s)
029                    throws JOSEException {
030    
031                    try {
032                            return s.getBytes("UTF-8");
033    
034                    } catch (UnsupportedEncodingException e) {
035    
036                            throw new JOSEException(e.getMessage(), e);
037                    }
038            }
039    
040    
041            /**
042             * Prevents public instantiation.
043             */
044            private StringUtils() {
045    
046            }
047    }