List of usage examples for java.util Formatter close
public void close()
From source file:cc.recommenders.utils.Fingerprints.java
private static String toHexString(final byte[] hash) { ensureIsNotNull(hash);//ww w. ja v a 2 s.c o m // this is said to be very slow... - we may look at this if hashing // actually takes too long. final Formatter formatter = new Formatter(); for (final byte b : hash) { formatter.format("%02x", b); } String out = formatter.toString(); formatter.close(); return out; }
From source file:Main.java
public static String toUUIDFormat(byte[] bytes) { byte[] switched = new byte[] { bytes[3], bytes[2], bytes[1], bytes[0], bytes[5], bytes[4], bytes[7], bytes[6], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15] }; StringBuilder sb = new StringBuilder(bytes.length * 2); Formatter formatter = new Formatter(sb); for (byte b : switched) { formatter.format("%02x", b); }/*from www .j a v a2s . co m*/ sb.insert(8, "-"); sb.insert(13, "-"); sb.insert(18, "-"); sb.insert(23, "-"); String temp = sb.toString().toUpperCase(); formatter.close(); return temp; }
From source file:Main.java
public static String byteArrayToHexString(byte[] paramArrayOfByte) { StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length); Formatter localFormatter = new Formatter(localStringBuilder); int i = paramArrayOfByte.length; for (int j = 0; j < i; j++) { byte b = paramArrayOfByte[j]; Object[] arrayOfObject = new Object[1]; arrayOfObject[0] = Byte.valueOf(b); localFormatter.format("%02x", arrayOfObject); }//from w ww.j a v a 2 s . c om localFormatter.close(); return localStringBuilder.toString(); }
From source file:pt.webdetails.cdc.hazelcast.CfgTestApp.java
public static String toHexString(byte[] bytes) { Formatter formatter = new Formatter(); try {/*from w w w . j a va 2 s .co m*/ for (byte b : bytes) { formatter.format("%02x", b); } return formatter.toString(); } finally { formatter.close(); } }
From source file:com.codealot.textstore.FileStore.java
private static String byteToHex(final byte[] hash) { final Formatter formatter = new Formatter(); for (final byte b : hash) { formatter.format("%02X", b); }// w w w .j ava2 s. c o m final String result = formatter.toString(); formatter.close(); return result; }
From source file:com.codedx.burp.security.InvalidCertificateDialogStrategy.java
public static String toHexString(byte[] bytes, String sep) { Formatter f = new Formatter(); for (int i = 0; i < bytes.length; i++) { f.format("%02x", bytes[i]); if (i < bytes.length - 1) { f.format(sep);//from w w w . j av a 2 s .co m } } String result = f.toString(); f.close(); return result; }
From source file:de.uzk.hki.da.pkg.MetsConsistencyChecker.java
/** * Byte array2 hex.//from ww w . j a v a 2 s.c o m * * @param hash the hash * @return the string */ private static String byteArray2Hex(byte[] hash) { Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); } String result = formatter.toString(); formatter.close(); return result; }
From source file:com.cloud.utils.NumbersUtil.java
public static String toReadableSize(long bytes) { if (bytes < KB && bytes >= 0) { return Long.toString(bytes) + " bytes"; }//from w ww.j a va 2 s .co m StringBuilder builder = new StringBuilder(); Formatter format = new Formatter(builder, Locale.getDefault()); if (bytes < MB) { format.format("%.2f KB", (float) bytes / (float) KB); } else if (bytes < GB) { format.format("%.2f MB", (float) bytes / (float) MB); } else if (bytes < TB) { format.format("%.2f GB", (float) bytes / (float) GB); } else { format.format("%.4f TB", (float) bytes / (float) TB); } format.close(); return builder.toString(); }
From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java
private static void appendDir(final Appendable report, final File file, final int indent) throws IOException { for (int i = 0; i < indent; i++) report.append(" - "); final Formatter formatter = new Formatter(report); final Calendar calendar = new GregorianCalendar(UTC); calendar.setTimeInMillis(file.lastModified()); formatter.format(Locale.US, "%tF %tT %8d %s\n", calendar, calendar, file.length(), file.getName()); formatter.close(); final File[] files = file.listFiles(); if (files != null) for (final File f : files) appendDir(report, f, indent + 1); }
From source file:org.openecomp.sdc.common.config.EcompErrorLogUtil.java
private static Either<String, Boolean> setDescriptionParams(EcompErrorEnum ecompErrorEnum, String... descriptionParams) { String description = ecompErrorEnum.getEcompErrorCode().getDescription(); // Counting number of params in description int countMatches = StringUtils.countMatches(description, AbsEcompErrorManager.PARAM_STR); // Catching cases when there are more params passed than there are in // the description (formatter will ignore extra params and won't throw // exception) if (countMatches != descriptionParams.length) { return Either.right(false); }/* w w w.j av a2s .c o m*/ // Setting params of the description if any StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); try { formatter.format(description, (Object[]) descriptionParams).toString(); return Either.left(formatter.toString()); } catch (IllegalFormatException e) { // Number of passed params doesn't match number of params in config // file return Either.right(false); } finally { formatter.close(); } }