Class FormatUtil

java.lang.Object
au.com.acegi.xmlformat.FormatUtil

final class FormatUtil extends Object
Utility methods private to the package.
  • Field Details

    • TMP_FILE_PREFIX

      private static final String TMP_FILE_PREFIX
  • Constructor Details

    • FormatUtil

      private FormatUtil()
  • Method Details

    • format

      static void format(InputStream in, OutputStream out, XmlOutputFormat fmt) throws org.dom4j.DocumentException, IOException
      Ingest an input stream, writing formatted XML to the output stream. The caller is responsible for closing the input and output streams. Any errors in the input stream will cause an exception and the output stream should not be relied upon.
      Parameters:
      in - input XML stream
      out - output XML stream
      fmt - format configuration to apply
      Throws:
      org.dom4j.DocumentException - if input XML could not be parsed
      IOException - if output XML stream could not be written
    • getXmlWriter

      private static org.dom4j.io.XMLWriter getXmlWriter(OutputStream out, XmlOutputFormat fmt) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • formatInPlace

      static boolean formatInPlace(File file, XmlOutputFormat fmt) throws org.dom4j.DocumentException, IOException
      Formats the input file, overwriting the input file with the new content if the formatted content differs.
      Parameters:
      file - to read and then potentially overwrite
      fmt - format configuration to apply
      Returns:
      true if the file was overwritten
      Throws:
      org.dom4j.DocumentException - if input XML could not be parsed
      IOException - if output XML stream could not be written
    • needsFormatting

      static boolean needsFormatting(File file, XmlOutputFormat fmt) throws org.dom4j.DocumentException, IOException
      Only checks if the input file would be modified by the formatter, without overwriting it.
      Parameters:
      file - to read
      fmt - format configuration to apply
      Returns:
      true if the file would be modified by the formatter
      Throws:
      org.dom4j.DocumentException - if input XML could not be parsed
      IOException - if output XML stream could not be written