Class XMLEncodingUtils

java.lang.Object
org.gvsig.utils.xml.XMLEncodingUtils

public class XMLEncodingUtils extends Object
A set of methods to detect XML encoding. The class is able to autodetect certain encodings, and it reads the XML header for the rest of encodings.
Author:
César Martínez Izquierdo invalid input: '<'cesar.martinez@iver.es>
  • Constructor Details

    • XMLEncodingUtils

      public XMLEncodingUtils(InputStream is)
      Creates a new XMLEncodingUtils object.
      Parameters:
      is - An InputStream connected to the XML file to process.
  • Method Details

    • getEncoding

      public String getEncoding()
      Gets the encoding of the XML file. The following encodings can be detected: UTF-32BE, UTF-32LE, UTF-16BE, UTF-16-LE, UTF-8. The rest of the encodings are read from the XML header.
      Returns:
      Returns the encoding of the XML file, or null if the encoding couldn't be correctly detected or read from the XML header.
    • getReader

      public InputStreamReader getReader()
      Gets an InputStreamReader for the provided XML file. The reader uses the right encoding, as specified in the XML header (or autodetected).
      Returns:
      A reader which uses the right encoding, or null if the encoding couldn't be correctly detected or read from the XML header.
    • getReader

      public static InputStreamReader getReader(InputStream is)
      Gets an InputStreamReader for the provided XML file. The reader uses the right encoding, as specified in the XML header (or autodetected).
      Parameters:
      is - An InputStream connected to the XML file to process
      Returns:
      A reader for the provided XML file.
      See Also:
    • getEncoding

      public static String getEncoding(InputStream is)
      Gets the character encoding of the XML file.
      Parameters:
      is - An InputStream connected to the XML file to process
      Returns:
      The encoding of the file
      See Also:
    • getReader

      public static InputStreamReader getReader(File file) throws FileNotFoundException
      Gets an InputStreamReader for the provided XML file. The reader uses the right encoding, as specified in the XML header (or autodetected).
      Parameters:
      file - The XML file to process
      Returns:
      A reader for the provided XML file.
      Throws:
      FileNotFoundException
      See Also:
    • getEncoding

      public static String getEncoding(File file) throws FileNotFoundException
      Gets the character encoding of the XML file.
      Parameters:
      File - The XML file to process
      Returns:
      The encoding of the file
      Throws:
      FileNotFoundException
      See Also: