Package org.omegat.filters2.html2
Class HTMLReader
java.lang.Object
java.io.Reader
java.io.BufferedReader
org.omegat.util.BufferedFileReader
org.omegat.filters2.html2.HTMLReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
This class automatically detects encoding of an inner HTML file and
constructs a Reader with appropriate encoding. Detecting of encoding is done
by reading a possible
<META http-equiv="content-type" content="text/html; charset=...">
and a value from XML header (in case there is one)
<?xml version="1.0" encoding="..."?>. If encoding isn't
specified, or it is not supported by Java platform, the file is opened in
encoding passed to constructor or default system encoding (ISO-8859-2 in USA,
Windows-1251 on my OS).-
Constructor Summary
ConstructorsConstructorDescriptionHTMLReader(String fileName, String defaultEncoding) Creates a new instance of HTMLReader. -
Method Summary
Modifier and TypeMethodDescriptionintread(char[] cbuf, int off, int len) Reads characters into a portion of an array.Methods inherited from class org.omegat.util.BufferedFileReader
getEncodingMethods inherited from class java.io.BufferedReader
close, lines, mark, markSupported, read, readLine, ready, reset, skipMethods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Constructor Details
-
HTMLReader
Creates a new instance of HTMLReader. If encoding cannot be detected, falls back to suppliedencoding, or (if supplied null, or supplied encoding is not supported by JVM) falls back to default encoding of Operating System.- Parameters:
fileName- The file to read.defaultEncoding- The encoding to use if we can't autodetect.- Throws:
FileNotFoundException
-
-
Method Details
-
read
Reads characters into a portion of an array. If this is the first time the method is invoked, it ensures that the Byte Order Mark (BOM) is handled correctly by resetting the stream if a BOM is not present. Subsequent reads proceed as normal.- Overrides:
readin classBufferedReader- Parameters:
cbuf- the destination buffer to hold the characters read from the streamoff- the start offset in the buffer where characters are writtenlen- the maximum number of characters to read- Returns:
- the number of characters read into the buffer or -1 if the end of the stream has been reached
- Throws:
IOException- if an I/O error occurs
-