/** * Returns an input stream for the specified character sequence, using UTF-8 encoding. * * @param cs the character sequence to wrap * * @return an input stream for reading the specified character sequence */ public static InputStream getStringInputStream( CharSequence cs ) { return new ByteArrayInputStream( toBytes( cs ) ); }
public static String getSHA1String( String s ) { MessageDigest md; try { md = MessageDigest.getInstance( "SHA1" ); } catch( NoSuchAlgorithmException e ) { throw new RuntimeException( e ); } byte[] bytes = md.digest( StreamUtil.toBytes( s ) ); StringBuilder result = new StringBuilder(); Formatter fm = new Formatter( result ); for( int i = 0; i < bytes.length; i++ ) { fm.format( "%02X", bytes[i] ); } return result.toString(); }