Package com.saperion.ngc.util
Class RawTextTools
- java.lang.Object
-
- com.saperion.ngc.util.RawTextTools
-
public final class RawTextTools extends java.lang.Object
A utility that provides several methods to analyze and convert raw text data.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
convertTextToPdf(byte[] original, java.lang.String font, float fontSize)
Converts the provided plain text data to PDF.static byte[]
convertTextToPdf(byte[] original, java.lang.String font, float fontSize, java.lang.String defaultCharset)
Converts the provided plain text data to PDF.static java.lang.String
getMediaType(byte[] bytes, java.lang.String filename)
Detects the media type of the provided data.static java.lang.String
getUnicodeString(byte[] original)
Returns a unicode encoded string corresponding to the provided data.static java.lang.String
getUnicodeString(byte[] original, java.lang.String defaultCharset)
Returns a unicode encoded string corresponding to the provided data.static boolean
isPlainTextFile(byte[] bytes, java.lang.String filename)
Detects if the data contains plain text.
-
-
-
Method Detail
-
isPlainTextFile
public static boolean isPlainTextFile(byte[] bytes, java.lang.String filename) throws java.io.IOException
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:
java.io.IOException
- IO exception when trying to detect media type
-
getMediaType
public static java.lang.String getMediaType(byte[] bytes, java.lang.String filename) throws java.io.IOException
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:
java.io.IOException
- IO exception when reading original data
-
convertTextToPdf
public static byte[] convertTextToPdf(byte[] original, java.lang.String font, float fontSize) throws com.lowagie.text.DocumentException, java.io.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 documentjava.io.IOException
- IO exception when reading the original data
-
convertTextToPdf
public static byte[] convertTextToPdf(byte[] original, java.lang.String font, float fontSize, java.lang.String defaultCharset) throws com.lowagie.text.DocumentException, java.io.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 documentjava.io.IOException
- IO exception when reading the original data
-
getUnicodeString
public static java.lang.String getUnicodeString(byte[] original) throws java.io.IOException
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:
java.io.IOException
- IO exception when reading the original data
-
getUnicodeString
public static java.lang.String getUnicodeString(byte[] original, java.lang.String defaultCharset) throws java.io.IOException
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:
java.io.IOException
- IO exception when reading the original data
-
-