Package org.omegat.filters3.xml
Class XMLReader
- java.lang.Object
-
- java.io.Reader
-
- org.omegat.filters3.xml.XMLReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public class XMLReader extends java.io.Reader
This class automatically detects encoding of an inner XML file and constructs a Reader with appropriate encoding.Detecting of encoding is done first by reading a possible BOM, to detect UTF-16 or UTF-8 then by reading a value from the XML header
<?xml version="1.0" encoding="..."?>
If encoding isn't specified, or it is not supported by the Java platform, the file is opened in UTF-8, in compliance with the XML specifications
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.lang.String
getEncoding()
Returns detected encoding.java.lang.String
getEol()
Returns detected EOL chars.int
read(char[] cbuf, int off, int len)
-
-
-
Constructor Detail
-
XMLReader
public XMLReader(java.io.InputStream is) throws java.io.IOException
Creates a new instance of XMLReader. If encoding cannot be detected, falls back to default UTF-8.- Parameters:
fileName
- - the file to read- Throws:
java.io.IOException
-
XMLReader
public XMLReader(java.io.File file) throws java.io.IOException
Creates a new instance of XMLReader. If encoding cannot be detected, falls back to default UTF-8.- Parameters:
fileName
- - the file to read- Throws:
java.io.IOException
-
XMLReader
public XMLReader(java.io.File file, java.lang.String encoding) throws java.io.IOException
Creates 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 UTF-8.- Parameters:
fileName
- The file to read.encoding
- The encoding to use if we can't autodetect.- Throws:
java.io.IOException
-
-
Method Detail
-
getEncoding
public java.lang.String getEncoding()
Returns detected encoding.
-
getEol
public java.lang.String getEol()
Returns detected EOL chars.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Reader
- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException
- Specified by:
read
in classjava.io.Reader
- Throws:
java.io.IOException
-
-