List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
/** * InputStream convert to string//from w ww. j a va2 s . c o m * * @param in * @return * @throws IOException */ public static String inputStream2String(InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); }
From source file:Main.java
/** * Slurps a InputStream into a String.// ww w .j ava 2s . c o m * @param in * @throws IOException */ public static String inputStreamToString(final InputStream in) throws IOException { StringBuffer out = new StringBuffer(); byte[] b = new byte[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); }
From source file:Main.java
public static String getContent(InputStreamReader reader) throws IOException { StringBuffer content = new StringBuffer(); int next = -1; while ((next = reader.read()) >= 0) { content.append((char) next); }/*from w ww. ja v a2 s . c o m*/ return content.toString(); }
From source file:Main.java
public static String getRandomString(int length) { String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(62); sb.append(str.charAt(number));//from w w w .ja v a 2s . c o m } return sb.toString(); }
From source file:com.glaf.core.security.DigestUtil.java
public static void digestFile(String filename, String algorithm) { byte[] b = new byte[65536]; int read = 0; FileInputStream fis = null;/*from w w w . j a v a 2s . c o m*/ FileOutputStream fos = null; OutputStream encodedStream = null; try { MessageDigest md = MessageDigest.getInstance(algorithm); fis = new FileInputStream(filename); while (fis.available() > 0) { read = fis.read(b); md.update(b, 0, read); } byte[] digest = md.digest(); StringBuffer fileNameBuffer = new StringBuffer(256).append(filename).append('.').append(algorithm); fos = new FileOutputStream(fileNameBuffer.toString()); encodedStream = MimeUtility.encode(fos, "base64"); encodedStream.write(digest); fos.flush(); } catch (Exception ex) { throw new RuntimeException("Error computing Digest: " + ex); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(fos); IOUtils.closeQuietly(encodedStream); } }
From source file:Main.java
public static String getMD5(String input) { String result = null;/*from ww w.java2s . c o m*/ try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input.getBytes()); byte[] digest = md.digest(); StringBuffer sb = new StringBuffer(); for (byte b : digest) { sb.append(String.format("%02x", b & 0xff)); } result = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); } finally { return result; } }
From source file:Main.java
/** * Slurps a Reader into a String./*from w w w . j a va2 s . c o m*/ * @param in * @throws IOException */ public static String readerToString(final Reader in) throws IOException { StringBuffer out = new StringBuffer(); char[] b = new char[4096]; for (int n; (n = in.read(b)) != -1;) { out.append(new String(b, 0, n)); } return out.toString(); }
From source file:com.centurylink.mdw.util.CryptUtil.java
private static String pad(String input, int len) { // return StringUtils.rightPad(input, MAX_LENGTH); StringBuffer padded = new StringBuffer(input); for (int i = 0; i < len - input.length(); i++) { padded.append(" "); }/*from w w w. ja va 2s .com*/ return padded.toString(); }
From source file:com.sharpshim.yarc.util.HtmlUtil.java
private static String clearString(String str) { StringBuffer sb = new StringBuffer(); for (final Character c : str.toCharArray()) { if (c != null && c != '\uFEFF') { sb.append(c);/*w ww .j a va 2 s . c o m*/ } } return sb.toString(); }
From source file:Main.java
private static String bufferToHex(byte bytes[], int m, int n) { StringBuffer stringbuffer = new StringBuffer(2 * n); int k = m + n; for (int l = m; l < k; l++) { appendHexPair(bytes[l], stringbuffer); }/*from w w w . jav a2s. c om*/ return stringbuffer.toString(); }