public class Utils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
fileSizeAsStr(long size)
Formats a byte size (for example the size of a file) into an easy-to-read
string.
|
static String |
stripHtml(String inp)
Strips a string from HTML and replaces
<br>,{@code |
public static String fileSizeAsStr(long size)
-h option which exist on
many Unix/Linux commands. Readability is favored over precision.
Note that the method uses the abbreviations "KB", "MB" and "GB" to denote 1024 bytes, 10242 bytes and 10243 bytes. Strictly speaking this incorrect but this is what most operating systems do as well.
Rules are as follows:
If the size is <1 KB : Will be shown as-is. Example returned string:
"361 bytes"
If the size is >= 1 KB and < 1 MB : Will be shown as KB value with
no decimals. Example returned string: "76 KB"
If the size is >= 1 MB and < 1 GB : Will be shown as MB value with
1 decimal. Example returned string: "323.4 MB"
If the size is >= 1 GB : Will be shown as GB value with 2 decimal.
Example returned string: "1.42 GB"
Except for input values above 1 TB the returned string will never be more than 9 bytes in length.
size - byte sizepublic static String stripHtml(String inp)
<br>,<p>,
<h1>, <h2> and <h3> with new line. This produces
a string which is readable as plain text.
Note: The method is simple and crude. It will not work on malformed HTML
or if there are un-escaped < or > outside of the HTML
tags. However, for all but the most complex use cases, the method will
probably work just fine.
inp - Copyright © 2015 Addicticks. All rights reserved.