Class FormatUtil


  • final class FormatUtil
    extends java.lang.Object
    Utility methods private to the package.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String TMP_FILE_PREFIX  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FormatUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void format​(java.io.InputStream in, java.io.OutputStream out, XmlOutputFormat fmt)
      Ingest an input stream, writing formatted XML to the output stream.
      (package private) static boolean formatInPlace​(java.io.File file, XmlOutputFormat fmt)
      Formats the input file, overwriting the input file with the new content if the formatted content differs.
      private static org.dom4j.io.XMLWriter getXmlWriter​(java.io.OutputStream out, XmlOutputFormat fmt)  
      (package private) static boolean needsFormatting​(java.io.File file, XmlOutputFormat fmt)
      Only checks if the input file would be modified by the formatter, without overwriting it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TMP_FILE_PREFIX

        private static final java.lang.String TMP_FILE_PREFIX
    • Constructor Detail

      • FormatUtil

        private FormatUtil()
    • Method Detail

      • format

        static void format​(java.io.InputStream in,
                           java.io.OutputStream out,
                           XmlOutputFormat fmt)
                    throws org.dom4j.DocumentException,
                           java.io.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
        java.io.IOException - if output XML stream could not be written
      • getXmlWriter

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

        static boolean formatInPlace​(java.io.File file,
                                     XmlOutputFormat fmt)
                              throws org.dom4j.DocumentException,
                                     java.io.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
        java.io.IOException - if output XML stream could not be written
      • needsFormatting

        static boolean needsFormatting​(java.io.File file,
                                       XmlOutputFormat fmt)
                                throws org.dom4j.DocumentException,
                                       java.io.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
        java.io.IOException - if output XML stream could not be written