Class DataUtil
- java.lang.Object
-
- com.itextpdf.styledxmlparser.jsoup.helper.DataUtil
-
public final class DataUtil extends java.lang.ObjectInternal static utilities for handling data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDataUtil.BomCharset
-
Field Summary
Fields Modifier and Type Field Description (package private) static intboundaryLength(package private) static intbufferSizeprivate static java.util.regex.PatterncharsetPattern(package private) static java.lang.StringdefaultCharsetNameprivate static intfirstReadBufferSizeprivate static char[]mimeBoundaryCharsstatic java.nio.charset.CharsetUTF_8
-
Constructor Summary
Constructors Modifier Constructor Description privateDataUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidcrossStreams(java.io.InputStream in, java.io.OutputStream out)Writes the input stream to the output stream.private static DataUtil.BomCharsetdetectCharsetFromBom(java.nio.ByteBuffer byteData)(package private) static java.nio.ByteBufferemptyByteBuffer()(package private) static java.lang.StringgetCharsetFromContentType(java.lang.String contentType)Parse out a charset from a content type header.static Documentload(java.io.File in, java.lang.String charsetName, java.lang.String baseUri)Loads and parses a file to a Document.static Documentload(java.io.InputStream in, java.lang.String charsetName, java.lang.String baseUri)Parses a Document from an input steam.static Documentload(java.io.InputStream in, java.lang.String charsetName, java.lang.String baseUri, Parser parser)Parses a Document from an input steam, using the provided Parser.(package private) static DocumentparseInputStream(java.io.InputStream input, java.lang.String charsetName, java.lang.String baseUri, Parser parser)static java.nio.ByteBufferreadToByteBuffer(java.io.InputStream inStream, int maxSize)Read the input stream into a byte buffer.private static java.lang.StringvalidateCharset(java.lang.String cs)
-
-
-
Field Detail
-
charsetPattern
private static final java.util.regex.Pattern charsetPattern
-
UTF_8
public static final java.nio.charset.Charset UTF_8
-
defaultCharsetName
static final java.lang.String defaultCharsetName
-
firstReadBufferSize
private static final int firstReadBufferSize
- See Also:
- Constant Field Values
-
bufferSize
static final int bufferSize
- See Also:
- Constant Field Values
-
mimeBoundaryChars
private static final char[] mimeBoundaryChars
-
boundaryLength
static final int boundaryLength
- See Also:
- Constant Field Values
-
-
Method Detail
-
load
public static Document load(java.io.File in, java.lang.String charsetName, java.lang.String baseUri) throws java.io.IOException
Loads and parses a file to a Document. Files that are compressed with gzip (and end in.gzor.z) are supported in addition to uncompressed files.- Parameters:
in- file to loadcharsetName- (optional) character set of input; specifynullto attempt to autodetect. A BOM in the file will always override this setting.baseUri- base URI of document, to resolve relative links against- Returns:
- Document
- Throws:
java.io.IOException- on IO error
-
load
public static Document load(java.io.InputStream in, java.lang.String charsetName, java.lang.String baseUri) throws java.io.IOException
Parses a Document from an input steam.- Parameters:
in- input stream to parse. You will need to close it.charsetName- character set of inputbaseUri- base URI of document, to resolve relative links against- Returns:
- Document
- Throws:
java.io.IOException- on IO error
-
load
public static Document load(java.io.InputStream in, java.lang.String charsetName, java.lang.String baseUri, Parser parser) throws java.io.IOException
Parses a Document from an input steam, using the provided Parser.- Parameters:
in- input stream to parse. You will need to close it.charsetName- character set of inputbaseUri- base URI of document, to resolve relative links againstparser- alternateparserto use.- Returns:
- Document
- Throws:
java.io.IOException- on IO error
-
crossStreams
static void crossStreams(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionWrites the input stream to the output stream. Doesn't close them.- Parameters:
in- input stream to read fromout- output stream to write to- Throws:
java.io.IOException- on IO error
-
parseInputStream
static Document parseInputStream(java.io.InputStream input, java.lang.String charsetName, java.lang.String baseUri, Parser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
readToByteBuffer
public static java.nio.ByteBuffer readToByteBuffer(java.io.InputStream inStream, int maxSize) throws java.io.IOExceptionRead the input stream into a byte buffer. To deal with slow input streams, you may interrupt the thread this method is executing on. The data read until being interrupted will be available.- Parameters:
inStream- the input stream to read frommaxSize- the maximum size in bytes to read from the stream. Set to 0 to be unlimited.- Returns:
- the filled byte buffer
- Throws:
java.io.IOException- if an exception occurs whilst reading from the input stream.
-
emptyByteBuffer
static java.nio.ByteBuffer emptyByteBuffer()
-
getCharsetFromContentType
static java.lang.String getCharsetFromContentType(java.lang.String contentType)
Parse out a charset from a content type header. If the charset is not supported, returns null (so the default will kick in.)- Parameters:
contentType- e.g. "text/html; charset=EUC-JP"- Returns:
- "EUC-JP", or null if not found. Charset is trimmed and uppercased.
-
validateCharset
private static java.lang.String validateCharset(java.lang.String cs)
-
detectCharsetFromBom
private static DataUtil.BomCharset detectCharsetFromBom(java.nio.ByteBuffer byteData)
-
-