FormatUtil
Utility methods used by formatters. For example, to format a file size or format time.
Methods
formatSize
Description:
Method | Return values | Description |
---|---|---|
formatSize(long bytes) |
String |
Format the document size for human readers. |
bytes: The size of the file content. |
Example:
package com.openkm;
import java.io.File;
import com.openkm.util.FormatUtil;
public class Test {
public static void main(String[] args) {
try {
File file = new File("/home/openkm/test.png");
System.out.println(FormatUtil.formatSize(file.length()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
parseSize
Description:
Method | Return values | Description |
---|---|---|
parseSize(String text) |
long |
Parse human-readable sizes. |
text: The size to parse. |
Example:
package com.openkm;
import com.openkm.util.FormatUtil;
public class Test {
public static void main(String[] args) {
try {
System.out.println(FormatUtil.parseSize("1024.7"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
formatDate
Description:
Method | Return values | Description |
---|---|---|
formatDate(Calendar cal) |
String |
Format calendar date. |
cal: The date to format. |
Example:
package com.openkm;
import java.util.Calendar;
import com.openkm.util.FormatUtil;
public class Test {
public static void main(String[] args) {
try {
System.out.println(FormatUtil.formatDate(Calendar.getInstance()));
} catch (Exception e) {
e.printStackTrace();
}
}
}