public final class DataUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
DataUtil.BomCharset |
Modifier and Type | Field and Description |
---|---|
(package private) static int |
boundaryLength |
(package private) static int |
bufferSize |
private static java.util.regex.Pattern |
charsetPattern |
(package private) static java.lang.String |
defaultCharsetName |
private static int |
firstReadBufferSize |
private static char[] |
mimeBoundaryChars |
static java.nio.charset.Charset |
UTF_8 |
Modifier | Constructor and Description |
---|---|
private |
DataUtil() |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
crossStreams(java.io.InputStream in,
java.io.OutputStream out)
Writes the input stream to the output stream.
|
private static DataUtil.BomCharset |
detectCharsetFromBom(java.nio.ByteBuffer byteData) |
(package private) static java.nio.ByteBuffer |
emptyByteBuffer() |
(package private) static java.lang.String |
getCharsetFromContentType(java.lang.String contentType)
Parse out a charset from a content type header.
|
static Document |
load(java.io.File file,
java.lang.String charsetName,
java.lang.String baseUri)
Loads and parses a file to a Document, with the HtmlParser.
|
static Document |
load(java.io.File file,
java.lang.String charsetName,
java.lang.String baseUri,
Parser parser)
Loads and parses a file to a Document.
|
static Document |
load(java.io.InputStream in,
java.lang.String charsetName,
java.lang.String baseUri)
Parses a Document from an input steam.
|
static Document |
load(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 java.lang.String |
mimeBoundary()
Creates a random string, suitable for use as a mime boundary
|
(package private) static Document |
parseInputStream(java.io.InputStream input,
java.lang.String charsetName,
java.lang.String baseUri,
Parser parser) |
static java.nio.ByteBuffer |
readToByteBuffer(java.io.InputStream inStream,
int maxSize)
Read the input stream into a byte buffer.
|
private static java.lang.String |
validateCharset(java.lang.String cs) |
private static final java.util.regex.Pattern charsetPattern
public static final java.nio.charset.Charset UTF_8
static final java.lang.String defaultCharsetName
private static final int firstReadBufferSize
static final int bufferSize
private static final char[] mimeBoundaryChars
static final int boundaryLength
public static Document load(java.io.File file, @Nullable java.lang.String charsetName, java.lang.String baseUri) throws java.io.IOException
.gz
or .z
)
are supported in addition to uncompressed files.file
- file to loadcharsetName
- (optional) character set of input; specify null
to attempt to autodetect. A BOM in
the file will always override this setting.baseUri
- base URI of document, to resolve relative links againstjava.io.IOException
- on IO errorpublic static Document load(java.io.File file, @Nullable java.lang.String charsetName, java.lang.String baseUri, Parser parser) throws java.io.IOException
.gz
or .z
)
are supported in addition to uncompressed files.file
- file to loadcharsetName
- (optional) character set of input; specify null
to attempt to autodetect. A BOM in
the file will always override this setting.baseUri
- base URI of document, to resolve relative links againstparser
- alternate parser
to use.java.io.IOException
- on IO errorpublic static Document load(@WillClose java.io.InputStream in, @Nullable java.lang.String charsetName, java.lang.String baseUri) throws java.io.IOException
in
- input stream to parse. The stream will be closed after reading.charsetName
- character set of input (optional)baseUri
- base URI of document, to resolve relative links againstjava.io.IOException
- on IO errorpublic static Document load(@WillClose java.io.InputStream in, @Nullable java.lang.String charsetName, java.lang.String baseUri, Parser parser) throws java.io.IOException
in
- input stream to parse. The stream will be closed after reading.charsetName
- character set of input (optional)baseUri
- base URI of document, to resolve relative links againstparser
- alternate parser
to use.java.io.IOException
- on IO errorstatic void crossStreams(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- input stream to read fromout
- output stream to write tojava.io.IOException
- on IO errorstatic Document parseInputStream(@Nullable @WillClose java.io.InputStream input, @Nullable java.lang.String charsetName, java.lang.String baseUri, Parser parser) throws java.io.IOException
java.io.IOException
public static java.nio.ByteBuffer readToByteBuffer(java.io.InputStream inStream, int maxSize) throws java.io.IOException
inStream
- the input stream to read frommaxSize
- the maximum size in bytes to read from the stream. Set to 0 to be unlimited.java.io.IOException
- if an exception occurs whilst reading from the input stream.static java.nio.ByteBuffer emptyByteBuffer()
@Nullable static java.lang.String getCharsetFromContentType(@Nullable java.lang.String contentType)
contentType
- e.g. "text/html; charset=EUC-JP"@Nullable private static java.lang.String validateCharset(@Nullable java.lang.String cs)
static java.lang.String mimeBoundary()
@Nullable private static DataUtil.BomCharset detectCharsetFromBom(java.nio.ByteBuffer byteData)