Class XmlInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.owasp.dependencycheck.xml.XmlInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

@NotThreadSafe public class XmlInputStream extends FilterInputStream
Cleans up often very bad XML. Primarily, this will convert named HTM entities into their HTM encoded Unicode code point representation.
  1. Strips leading white space
  2. Recodes £ etc to &#...;
  3. Recodes lone & as &

This is a slightly modified (class/method rename) from an SO answer: https://stackoverflow.com/questions/7286428/help-the-java-sax-parser-to-understand-bad-xml

Author:
https://stackoverflow.com/users/823393/oldcurmudgeon
  • Constructor Details

    • XmlInputStream

      public XmlInputStream(InputStream in)
      Constructs a new XML Input Stream.
      Parameters:
      in - the base input stream
  • Method Details

    • length

      public int length()
      NB: This is a Troll length (i.e. it goes 1, 2, many) so 2 actually means "at least 2"
      Returns:
      the length
    • read

      public int read() throws IOException
      Reads the next byte.
      Overrides:
      read in class FilterInputStream
      Returns:
      the byte read
      Throws:
      IOException - thrown when there is an problem reading
    • read

      public int read(@NonNull byte[] data, int offset, int length) throws IOException
      Reads the next length of bytes from the stream into the given byte array at the given offset.
      Overrides:
      read in class FilterInputStream
      Parameters:
      data - the buffer to store the data read
      offset - the offset in the buffer to start writing
      length - the length of data to read
      Returns:
      the number of bytes read
      Throws:
      IOException - thrown when there is an issue with the underlying stream
    • toString

      public String toString()
      To string implementation.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the data given and read from the stream.