Class XMLReader

java.lang.Object
java.io.Reader
org.omegat.filters3.xml.XMLReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class XMLReader extends 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

  • Constructor Details

    • XMLReader

      public XMLReader(InputStream is) throws IOException
      Creates a new instance of XMLReader. If encoding cannot be detected, falls back to default UTF-8.
      Parameters:
      is - the InputStream instance to read
      Throws:
      IOException
    • XMLReader

      public XMLReader(File file) throws IOException
      Creates a new instance of XMLReader. If encoding cannot be detected, falls back to default UTF-8.
      Parameters:
      file - - the file to read
      Throws:
      IOException
    • XMLReader

      public XMLReader(File file, @Nullable String defaultEncoding) throws IOException
      Creates a new instance of XMLReader. If encoding cannot be detected, falls back to supplied encoding, or (if supplied null, or supplied encoding is not supported by JVM) falls back to UTF-8.
      Parameters:
      file - The file to read.
      defaultEncoding - The encoding to use if we can't autodetect.
      Throws:
      IOException
  • Method Details