Class ANVLRecord

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Element>, Collection<Element>, Deque<Element>, List<Element>, Queue<Element>, UTF8Bytes

public class ANVLRecord extends LinkedList<Element> implements UTF8Bytes
An ordered List with 'data' Element values. ANVLRecords end with a blank line.
Author:
stack
See Also:
  • Field Details

  • Constructor Details

    • ANVLRecord

      public ANVLRecord()
    • ANVLRecord

      public ANVLRecord(Collection<? extends Element> c)
  • Method Details

    • addLabel

      public boolean addLabel(String l)
    • addLabelValue

      public boolean addLabelValue(String l, String v)
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<Element>
    • asMap

      public Map<String,String> asMap()
    • clone

      public ANVLRecord clone()
      Overrides:
      clone in class LinkedList<Element>
    • getUTF8Bytes

      public byte[] getUTF8Bytes() throws UnsupportedEncodingException
      Specified by:
      getUTF8Bytes in interface UTF8Bytes
      Returns:
      This ANVLRecord as UTF8 bytes.
      Throws:
      UnsupportedEncodingException
    • load

      public static ANVLRecord load(InputStream is) throws IOException
      Parses a single ANVLRecord from passed InputStream. Read as a single-byte stream until we get to a CRLFCRLF which signifies End-of-ANVLRecord. Then parse all read as a UTF-8 Stream. Doing it this way, while requiring a double-scan, it makes it so do not need to be passed a RepositionableStream or a Stream that supports marking. Also no danger of over-reading which can happen when we wrap passed Stream with an InputStreamReader for doing UTF-8 character conversion (See the ISR class comment).
      Parameters:
      is - InputStream
      Returns:
      An ANVLRecord instance.
      Throws:
      IOException
    • load

      public static ANVLRecord load(String s) throws IOException
      Parse passed String for an ANVL Record. Looked at writing javacc grammer but preprocessing is required to handle folding: See here. Looked at Terence Parr's ANTLR. More capable. Can set lookahead count. A value of 3 would help with folding. But its a pain defining UNICODE grammers -- needed by ANVL -- and support seems incomplete anyways: http://www.doc.ic.ac.uk/lab/secondyear/Antlr/lexer.html#unicode. For now, go with the below hand-rolled parser.
      Parameters:
      s - String with an ANVLRecord.
      Returns:
      ANVLRecord parsed from passed String.
      Throws:
      IOException
    • getLength

      public int getLength()
      Returns:
      Count of ANVLRecord bytes. Be careful, an empty ANVLRecord is CRLFCRLF so is of size 4. Also, expensive, since it makes String of the record so it can count bytes.
    • isCROrLF

      public static boolean isCROrLF(char c)
    • isCR

      public static boolean isCR(char c)
    • isLF

      public static boolean isLF(char c)