+ /**
+ * Unconvert the given data from Base64 format back into a {@link String}.
+ *
+ * @param data
+ * the data to unconvert
+ * @param offset
+ * the offset at which to start taking the data (do not take the
+ * data before it into account)
+ * @param count
+ * the number of bytes to take into account (do not process after
+ * this number of bytes has been processed)
+ * @param zip
+ * TRUE to also uncompress the data from a GZIP format; take care
+ * about this flag, as it could easily cause errors in the
+ * returned content or an {@link IOException}
+ *
+ * @return the {@link String} represented by the given Base64 {@link String}
+ * , optionally compressed with GZIP
+ *
+ * @throws IOException
+ * in case of I/O errors
+ */
+ public static String unbase64s(byte[] data, int offset, int count,
+ boolean zip) throws IOException {
+ return new String(unbase64(data, offset, count, zip), "UTF-8");
+ }
+
+ /**
+ * Return a display {@link String} for the given value, which can be
+ * suffixed with "k" or "M" depending upon the number, if it is big enough.
+ * <p>
+ * <p>
+ * Examples:
+ * <ul>
+ * <li><tt>8 765</tt> becomes "8k"</li>
+ * <li><tt>998 765</tt> becomes "998k"</li>
+ * <li><tt>12 987 364</tt> becomes "12M"</li>
+ * <li><tt>5 534 333 221</tt> becomes "5G"</li>
+ * </ul>
+ *
+ * @param value
+ * the value to convert
+ *
+ * @return the display value
+ */
+ public static String formatNumber(long value) {
+ return formatNumber(value, 0);
+ }
+
+ /**
+ * Return a display {@link String} for the given value, which can be
+ * suffixed with "k" or "M" depending upon the number, if it is big enough.
+ * <p>
+ * Examples (assuming decimalPositions = 1):
+ * <ul>
+ * <li><tt>8 765</tt> becomes "8.7k"</li>
+ * <li><tt>998 765</tt> becomes "998.7k"</li>
+ * <li><tt>12 987 364</tt> becomes "12.9M"</li>
+ * <li><tt>5 534 333 221</tt> becomes "5.5G"</li>
+ * </ul>
+ *
+ * @param value
+ * the value to convert
+ * @param decimalPositions
+ * the number of decimal positions to keep
+ *
+ * @return the display value
+ */
+ public static String formatNumber(long value, int decimalPositions) {
+ long userValue = value;
+ String suffix = "";
+ long mult = 1;
+
+ if (value >= 1000000000l) {
+ mult = 1000000000l;
+ userValue = value / 1000000000l;
+ suffix = " G";
+ } else if (value >= 1000000l) {
+ mult = 1000000l;
+ userValue = value / 1000000l;
+ suffix = " M";
+ } else if (value >= 1000l) {
+ mult = 1000l;
+ userValue = value / 1000l;
+ suffix = " k";
+ }
+
+ String deci = "";
+ if (decimalPositions > 0) {
+ deci = Long.toString(value % mult);
+ int size = Long.toString(mult).length() - 1;
+ while (deci.length() < size) {
+ deci = "0" + deci;
+ }
+
+ deci = deci.substring(0, Math.min(decimalPositions, deci.length()));
+ while (deci.length() < decimalPositions) {
+ deci += "0";
+ }
+
+ deci = "." + deci;