public class Utils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Utils.HttpStatusCode
HTTP Response Status code (with text explanation)
|
| 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 |
getHttpStatusCodeText(int sc)
Gets the numerical HTTP status code concatenated with the
text representing that status code, for example
"403 Forbidden". |
static String |
stripHtml(String str)
Strips a string from HTML markup.
|
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 is 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 str)
<br>,<p>, <h1>,
<h2> and <h3> are replaced with 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.
str - public static String getHttpStatusCodeText(int sc)
"403 Forbidden".
If the status code is unknown then the text will be
"<Unknown status code>".
sc - numerical HTTP status codeCopyright © 2019 Addicticks. All rights reserved.