org.archive.util.anvl
Class ANVLRecord
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<Element>
org.archive.util.anvl.ANVLRecord
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Element>, java.util.Collection<Element>, java.util.List<Element>, java.util.RandomAccess, UTF8Bytes
public class ANVLRecord
- extends java.util.ArrayList<Element>
- implements UTF8Bytes
An ordered List
with 'data' Element
values.
ANVLRecords end with a blank line.
- Author:
- stack
- See Also:
- A Name-Value
Language (ANVL),
Serialized Form
Fields inherited from class java.util.AbstractList |
modCount |
Methods inherited from class java.util.ArrayList |
add, add, addAll, addAll, clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
containsAll, removeAll, retainAll |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList |
MIMETYPE
public static final java.lang.String MIMETYPE
- See Also:
- Constant Field Values
EMPTY_ANVL_RECORD
public static final ANVLRecord EMPTY_ANVL_RECORD
MAXIMUM_SIZE
public static final long MAXIMUM_SIZE
- Arbitrary upper bound on maximum size of ANVL Record.
Will throw an IOException if exceed this size.
- See Also:
- Constant Field Values
CRLF
static final java.lang.String CRLF
- An ANVL 'newline'.
- See Also:
- http://en.wikipedia.org/wiki/CRLF,
Constant Field Values
FOLD_PREFIX
static final java.lang.String FOLD_PREFIX
- See Also:
- Constant Field Values
ANVLRecord
public ANVLRecord()
ANVLRecord
public ANVLRecord(java.util.Collection<? extends Element> c)
ANVLRecord
public ANVLRecord(int initialCapacity)
addLabel
public boolean addLabel(java.lang.String l)
addLabelValue
public boolean addLabelValue(java.lang.String l,
java.lang.String v)
toString
public java.lang.String toString()
- Overrides:
toString
in class java.util.AbstractCollection<Element>
asMap
public java.util.Map<java.lang.String,java.lang.String> asMap()
clone
public ANVLRecord clone()
- Overrides:
clone
in class java.util.ArrayList<Element>
getUTF8Bytes
public byte[] getUTF8Bytes()
throws java.io.UnsupportedEncodingException
- Specified by:
getUTF8Bytes
in interface UTF8Bytes
- Returns:
- This ANVLRecord as UTF8 bytes.
- Throws:
java.io.UnsupportedEncodingException
load
public static ANVLRecord load(java.io.InputStream is)
throws java.io.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:
java.io.IOException
load
public static ANVLRecord load(java.lang.String s)
throws java.io.IOException
- Parse passed String for an ANVL Record.
Looked at writing javacc grammer but preprocessing is required to
handle folding: See
https://javacc.dev.java.net/servlets/BrowseList?list=users&by=thread&from=56173.
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:
java.io.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)
Copyright © 2003-2011 Internet Archive. All Rights Reserved.