Package org.omegat.util.xml
Class XMLReader
- java.lang.Object
-
- java.io.Reader
-
- org.omegat.util.xml.XMLReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class XMLReader extends java.io.ReaderThis class automatically detects encoding of an inner XML file and constructs a Reader with appropriate encoding.Detecting of encoding is done by reading a value from XML header
<?xml version="1.0" encoding="..."?>If encoding isn't specified, or it is not supported by Java platform, the file is opened in default system encoding (ISO-8859-2 in USA, Windows-1251 on my OS).
-
-
Constructor Summary
Constructors Constructor Description XMLReader(java.io.InputStream inputStream, java.lang.String encoding)XMLReader(java.lang.String fileName)Creates a new instance of XMLReader.XMLReader(java.lang.String fileName, java.lang.String encoding)Creates a new instance of XMLReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intread(char[] cbuf, int off, int len)
-
-
-
Constructor Detail
-
XMLReader
public XMLReader(java.lang.String fileName) throws java.io.IOExceptionCreates a new instance of XMLReader. If encoding cannot be detected, falls back to default encoding of Operating System.- Parameters:
fileName- - the file to read- Throws:
java.io.IOException
-
XMLReader
public XMLReader(java.lang.String fileName, java.lang.String encoding) throws java.io.IOExceptionCreates a new instance of XMLReader. 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.encoding- The encoding to use if we can't autodetect.- Throws:
java.io.IOException
-
XMLReader
public XMLReader(java.io.InputStream inputStream, java.lang.String encoding) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException- Specified by:
readin classjava.io.Reader- Throws:
java.io.IOException
-
-