FormatUtil

Utility methods used by formatters. For example, to format a file size or format time. 

Methods

formatSize

Description:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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:

MethodReturn valuesDescription

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();
		}
	}
}