Class JsonArrayFixingInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class JsonArrayFixingInputStream
    extends java.io.InputStream
    Fixes a poorly formatted jSON array such as those returned by go list -json -m all.

    Example:

    { "name1": "value" } { "name2" : "value" } Would be transformed into: [{ "name1": "value" }, { "name2" : "value" }]

    Note that this is a naive implementation and will incorrectly transform a stream if there are '}' contained within the names of values.

    Author:
    Jeremy Long
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonArrayFixingInputStream​(java.io.InputStream in)
      Constructs a new filtering input stream used to fix a poorly formatted JSON array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      protected boolean isWhiteSpace​(byte c)
      Tests if the byte passed in is a white space character.
      boolean markSupported()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      long skip​(long n)  
      • Methods inherited from class java.io.InputStream

        mark, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

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

      • JsonArrayFixingInputStream

        public JsonArrayFixingInputStream​(java.io.InputStream in)
        Constructs a new filtering input stream used to fix a poorly formatted JSON array.
        Parameters:
        in - the InputStream containing the poorly formed JSON array
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream
      • isWhiteSpace

        protected boolean isWhiteSpace​(byte c)
        Tests if the byte passed in is a white space character.
        Parameters:
        c - the byte representing the character to test
        Returns:
        true if the byte is white space; otherwise false