Package com.saperion.ngc.util
Class RawTextTools
java.lang.Object
com.saperion.ngc.util.RawTextTools
A utility that provides several methods to analyze and convert raw text data.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
convertTextToPdf
(byte[] original, String font, float fontSize) Converts the provided plain text data to PDF.static byte[]
convertTextToPdf
(byte[] original, String font, float fontSize, String defaultCharset) Converts the provided plain text data to PDF.static String
getMediaType
(byte[] bytes, String filename) Detects the media type of the provided data.static String
getUnicodeString
(byte[] original) Returns a unicode encoded string corresponding to the provided data.static String
getUnicodeString
(byte[] original, String defaultCharset) Returns a unicode encoded string corresponding to the provided data.static boolean
isPlainTextFile
(byte[] bytes, String filename) Detects if the data contains plain text.
-
Method Details
-
isPlainTextFile
Detects if the data contains plain text.- Parameters:
bytes
- data to analyzefilename
- name of the file the data is contained in- Returns:
- true if data contains plain text
- Throws:
IOException
- IO exception when trying to detect media type
-
getMediaType
Detects the media type of the provided data.- Parameters:
bytes
- original datafilename
- name of the file the data was contained in- Returns:
- media type (like 'text/plain' for plain text)
- Throws:
IOException
- IO exception when reading original data
-
convertTextToPdf
public static byte[] convertTextToPdf(byte[] original, String font, float fontSize) throws com.lowagie.text.DocumentException, IOException Converts the provided plain text data to PDF.- Parameters:
original
- plain text datafont
- font to use (like C:/Windows/Fonts/arial.ttf). This must be a true-type font! If null or empty, a default helvetica font will be used. Note that unicode characters will not work then.fontSize
- size of the font- Returns:
- PDF document as array of bytes
- Throws:
com.lowagie.text.DocumentException
- Exception when creating the PDF documentIOException
- IO exception when reading the original data
-
convertTextToPdf
public static byte[] convertTextToPdf(byte[] original, String font, float fontSize, String defaultCharset) throws com.lowagie.text.DocumentException, IOException Converts the provided plain text data to PDF.- Parameters:
original
- plain text datafont
- font to use (like C:/Windows/Fonts/arial.ttf). This must be a true-type font! If null or empty, a default helvetica font will be used. Note that unicode characters will not work then.fontSize
- size of the fontdefaultCharset
- charset to use when auto-detection of charset failed- Returns:
- PDF document as array of bytes
- Throws:
com.lowagie.text.DocumentException
- Exception when creating the PDF documentIOException
- IO exception when reading the original data
-
getUnicodeString
Returns a unicode encoded string corresponding to the provided data. The encoding of the original data is auto-detected. If an unsupported encoding is detected, ISO-8859-1 is used as a fallback.- Parameters:
original
- original data- Returns:
- unicode string corresponding to original data
- Throws:
IOException
- IO exception when reading the original data
-
getUnicodeString
Returns a unicode encoded string corresponding to the provided data. The encoding of the original data is auto-detected. If an unsupported encoding is detected, the provided fallback is used.- Parameters:
original
- original datadefaultCharset
- charset to use when auto-detection of charset failed- Returns:
- unicode string corresponding to original data
- Throws:
IOException
- IO exception when reading the original data
-