public class SimpleFieldSet
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
SimpleFieldSet.KeyIterator |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
header |
static char |
KEYVALUE_SEPARATOR_CHAR |
static char |
MULTI_LEVEL_CHAR |
static char |
MULTI_VALUE_CHAR |
Constructor and Description |
---|
SimpleFieldSet(boolean shortLived) |
SimpleFieldSet(boolean shortLived,
boolean alwaysUseBase64)
Create a SimpleFieldSet.
|
SimpleFieldSet(java.io.BufferedReader br,
boolean allowMultiple,
boolean shortLived) |
SimpleFieldSet(java.io.BufferedReader br,
boolean allowMultiple,
boolean shortLived,
boolean allowBase64,
boolean alwaysBase64)
Construct a SimpleFieldSet from reading a BufferedReader.
|
SimpleFieldSet(LineReader lis,
int maxLineLength,
int lineBufferSize,
boolean utf8OrIso88591,
boolean allowMultiple,
boolean shortLived) |
SimpleFieldSet(LineReader lis,
int maxLineLength,
int lineBufferSize,
boolean utf8OrIso88591,
boolean allowMultiple,
boolean shortLived,
boolean allowBase64) |
SimpleFieldSet(SimpleFieldSet sfs)
Copy constructor
|
SimpleFieldSet(java.lang.String[] content,
boolean allowMultiple,
boolean shortLived,
boolean allowBase64)
Construct from a
String array. |
SimpleFieldSet(java.lang.String content,
boolean allowMultiple,
boolean shortLived,
boolean allowBase64)
Construct from a string.
|
Modifier and Type | Method and Description |
---|---|
java.util.Set<java.lang.String> |
directKeys()
Get a read-only set of direct key names.
|
java.util.Map<java.lang.String,java.lang.String> |
directKeyValues()
Get a read-only map of direct key name:value pairs.
|
java.util.Iterator<java.lang.String> |
directSubsetNameIterator()
Iterator over the names of direct subsets, i.e.
|
java.util.Map<java.lang.String,SimpleFieldSet> |
directSubsets()
Get a read-only set of direct subsets.
|
java.lang.String |
get(java.lang.String key)
Get a value for a key as a String.
|
java.lang.String[] |
getAll(java.lang.String key) |
java.lang.String[] |
getAllEncoded(java.lang.String key)
Get a list of String's from a single value, encoded in Base64.
|
boolean |
getBoolean(java.lang.String key) |
boolean |
getBoolean(java.lang.String key,
boolean def) |
boolean[] |
getBooleanArray(java.lang.String key) |
byte |
getByte(java.lang.String key)
Get a byte value for the given key (represented as a number in decimal).
|
byte |
getByte(java.lang.String key,
byte def)
Get a byte value for the given key (represented as a number in decimal).
|
byte[] |
getByteArray(java.lang.String key)
Get a byte array for the given key (represented in Base64).
|
char |
getChar(java.lang.String key)
Get a char for the given key (represented as a single character).
|
char |
getChar(java.lang.String key,
char def)
Get a char for the given key (represented as a single character).
|
double |
getDouble(java.lang.String key)
Get a double precision value for the given key.
|
double |
getDouble(java.lang.String key,
double def)
Get a double precision value for the given key.
|
double[] |
getDoubleArray(java.lang.String key) |
java.lang.String |
getEndMarker() |
float[] |
getFloatArray(java.lang.String key) |
java.lang.String[] |
getHeader()
Get the headers.
|
int |
getInt(java.lang.String key)
Get an integer value for the given key.
|
int |
getInt(java.lang.String key,
int def)
Get an integer value for the given key.
|
int[] |
getIntArray(java.lang.String key) |
long |
getLong(java.lang.String key)
Get a long value for the given key.
|
long |
getLong(java.lang.String key,
long def)
Get a long value for the given key.
|
long[] |
getLongArray(java.lang.String key) |
short |
getShort(java.lang.String key)
Get a short value for the given key.
|
short |
getShort(java.lang.String key,
short def)
Get a short value for the given key.
|
short[] |
getShortArray(java.lang.String key) |
java.lang.String |
getString(java.lang.String key) |
SimpleFieldSet |
getSubset(java.lang.String key)
Like subset(), only throws instead of returning null.
|
boolean |
isEmpty()
Is this SimpleFieldSet empty?
|
java.util.Iterator<java.lang.String> |
keyIterator()
Iterate over all keys in the SimpleFieldSet, even if they are at lower levels.
|
SimpleFieldSet.KeyIterator |
keyIterator(java.lang.String prefix)
Iterate over all keys in the SimpleFieldSet, even if they are at lower levels.
|
java.lang.String[] |
namesOfDirectSubsets()
Get the names of direct subsets, i.e.
|
void |
put(java.lang.String key,
boolean b) |
void |
put(java.lang.String key,
boolean[] value) |
void |
put(java.lang.String key,
byte[] bytes) |
void |
put(java.lang.String key,
char c) |
void |
put(java.lang.String key,
double windowSize) |
void |
put(java.lang.String key,
double[] value) |
void |
put(java.lang.String key,
float[] value) |
void |
put(java.lang.String key,
int value) |
void |
put(java.lang.String key,
int[] value) |
void |
put(java.lang.String key,
long value) |
void |
put(java.lang.String key,
long[] value) |
void |
put(java.lang.String key,
short value) |
void |
put(java.lang.String key,
short[] value) |
void |
put(java.lang.String key,
SimpleFieldSet fs)
Add a name:value pair, traversing the tree and creating sub-SFS's if necessary.
|
void |
put(java.lang.String key,
java.lang.String[] values) |
void |
putAllOverwrite(SimpleFieldSet fs)
Put contents of a fieldset, overwrite old values.
|
void |
putAppend(java.lang.String key,
java.lang.String value)
Aggregating put.
|
void |
putEncoded(java.lang.String key,
java.lang.String[] strings) |
void |
putOverwrite(java.lang.String key,
java.lang.String value)
Set a key to a value, overwriting any existing value if present.
|
void |
putOverwrite(java.lang.String key,
java.lang.String[] strings) |
void |
putSingle(java.lang.String key,
java.lang.String value)
Set a key to a value.
|
static SimpleFieldSet |
readFrom(java.io.File f,
boolean allowMultiple,
boolean shortLived)
Read a SimpleFieldSet from a File.
|
static SimpleFieldSet |
readFrom(java.io.InputStream is,
boolean allowMultiple,
boolean shortLived)
Read a SimpleFieldSet from an InputStream in the standard format, using UTF-8, and not
allowing the Base64 encoding.
|
static SimpleFieldSet |
readFrom(java.io.InputStream is,
boolean allowMultiple,
boolean shortLived,
boolean allowBase64,
boolean alwaysBase64)
Read a SimpleFieldSet from an InputStream.
|
void |
removeSubset(java.lang.String key)
It removes the specified subset.
|
void |
removeValue(java.lang.String key)
Remove a name:value pair at any point in the tree.
|
void |
setEndMarker(java.lang.String s) |
void |
setHeader(java.lang.String... headers)
Set the headers.
|
static java.lang.String[] |
split(java.lang.String string)
Split a set of String's delimeted by MULTI_VALUE_CHAR, accepting empty strings at both ends.
|
SimpleFieldSet |
subset(java.lang.String key) |
java.lang.String |
toOrderedString() |
java.lang.String |
toOrderedStringWithBase64() |
java.util.Iterator<java.lang.String> |
toplevelKeyIterator()
Iterate over keys that are in the top level of the tree, i.e.
|
java.lang.String |
toString() |
void |
tput(java.lang.String key,
SimpleFieldSet fs)
Tolerant put(); does nothing if fs is empty
|
void |
writeTo(java.io.OutputStream os)
Write to the given OutputStream (as UTF-8) and flush it.
|
void |
writeTo(java.io.OutputStream os,
int bufferSize)
Write to the given OutputStream and flush it.
|
void |
writeTo(java.io.Writer w)
Write the contents of the SimpleFieldSet to a Writer.
|
void |
writeToBigBuffer(java.io.OutputStream os)
Write to the given OutputStream and flush it.
|
void |
writeToOrdered(java.io.Writer w) |
protected java.lang.String[] header
public static final char MULTI_LEVEL_CHAR
public static final char MULTI_VALUE_CHAR
public static final char KEYVALUE_SEPARATOR_CHAR
public SimpleFieldSet(boolean shortLived)
public SimpleFieldSet(boolean shortLived, boolean alwaysUseBase64)
shortLived
- If false, strings will be interned to ensure that they use as
little memory as possible. Only set to true if the SFS will be short-lived or
small.alwaysUseBase64
- If true, the SFS can contain newlines etc in values, and we will
always use base64 for the values if they contain such invalid characters.public SimpleFieldSet(java.io.BufferedReader br, boolean allowMultiple, boolean shortLived) throws java.io.IOException
java.io.IOException
public SimpleFieldSet(java.io.BufferedReader br, boolean allowMultiple, boolean shortLived, boolean allowBase64, boolean alwaysBase64) throws java.io.IOException
br
- allowMultiple
- If true, multiple lines with the same field name will be
combined; if false, the constructor will throw.shortLived
- If false, strings will be interned to ensure that they use as
little memory as possible. Only set to true if the SFS will be short-lived or
small.java.io.IOException
- If the buffer could not be read, or if there was a formatting
problem.public SimpleFieldSet(SimpleFieldSet sfs)
public SimpleFieldSet(LineReader lis, int maxLineLength, int lineBufferSize, boolean utf8OrIso88591, boolean allowMultiple, boolean shortLived) throws java.io.IOException
java.io.IOException
public SimpleFieldSet(LineReader lis, int maxLineLength, int lineBufferSize, boolean utf8OrIso88591, boolean allowMultiple, boolean shortLived, boolean allowBase64) throws java.io.IOException
java.io.IOException
public SimpleFieldSet(java.lang.String content, boolean allowMultiple, boolean shortLived, boolean allowBase64) throws java.io.IOException
shortLived
- If false, strings will be interned to ensure that they use as
little memory as possible. Only set to true if the SFS will be short-lived or
small.java.io.IOException
- if the string is too short or invalid.public SimpleFieldSet(java.lang.String[] content, boolean allowMultiple, boolean shortLived, boolean allowBase64) throws java.io.IOException
String
array.
Similar to #SimpleFieldSet(String, boolean, boolean)
,
but each item of array represents a single line
content
- to be parsedallowMultiple
- If true
, multiple lines with the same field name will be
combined; if false
, the constructor will throw.shortLived
- If false
, strings will be interned to ensure that they use as
little memory as possible. Only set to true
if the SFS will be short-lived or
small.java.io.IOException
public java.lang.String get(java.lang.String key)
key
- The key to look up.public java.lang.String[] getAll(java.lang.String key)
public java.lang.String[] getAllEncoded(java.lang.String key) throws IllegalBase64Exception
IllegalBase64Exception
public static java.lang.String[] split(java.lang.String string)
public void putAllOverwrite(SimpleFieldSet fs)
public void putSingle(java.lang.String key, java.lang.String value)
key
- The key.value
- The value.public void putAppend(java.lang.String key, java.lang.String value)
key
- The key.value
- The value.public void putOverwrite(java.lang.String key, java.lang.String value)
key
- The key.value
- The value.public void put(java.lang.String key, int value)
public void put(java.lang.String key, long value)
public void put(java.lang.String key, short value)
public void put(java.lang.String key, char c)
public void put(java.lang.String key, boolean b)
public void put(java.lang.String key, double windowSize)
public void put(java.lang.String key, byte[] bytes)
public void writeTo(java.io.Writer w) throws java.io.IOException
java.io.IOException
public void writeToOrdered(java.io.Writer w) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toOrderedString()
public java.lang.String toOrderedStringWithBase64()
public java.lang.String getEndMarker()
public void setEndMarker(java.lang.String s)
public SimpleFieldSet subset(java.lang.String key)
public SimpleFieldSet getSubset(java.lang.String key) throws FSParseException
FSParseException
public java.util.Iterator<java.lang.String> keyIterator()
public SimpleFieldSet.KeyIterator keyIterator(java.lang.String prefix)
prefix
- Add the given prefix to lower levels. This is used recursively by KeyIterator.public java.util.Iterator<java.lang.String> toplevelKeyIterator()
public java.util.Map<java.lang.String,java.lang.String> directKeyValues()
public java.util.Set<java.lang.String> directKeys()
public java.util.Map<java.lang.String,SimpleFieldSet> directSubsets()
public void tput(java.lang.String key, SimpleFieldSet fs)
public void put(java.lang.String key, SimpleFieldSet fs)
key
- Name of the key to add.fs
- Subset under the key.public void removeValue(java.lang.String key)
public void removeSubset(java.lang.String key)
is
- the subset to removepublic boolean isEmpty()
public java.util.Iterator<java.lang.String> directSubsetNameIterator()
public java.lang.String[] namesOfDirectSubsets()
public static SimpleFieldSet readFrom(java.io.InputStream is, boolean allowMultiple, boolean shortLived) throws java.io.IOException
is
- The InputStream to read from. We will use the UTF-8 charset.allowMultiple
- Whether to allow multiple entries for each key (and automatically
combine them). Not usually useful except maybe in FCP.shortLived
- If true, don't intern the strings.java.io.IOException
- If a read error occurs, including a formatting error, illegal
characters etc.public static SimpleFieldSet readFrom(java.io.InputStream is, boolean allowMultiple, boolean shortLived, boolean allowBase64, boolean alwaysBase64) throws java.io.IOException
is
- The InputStream to read from. We will use the UTF-8 charset.allowMultiple
- Whether to allow multiple entries for each key (and automatically
combine them). Not usually useful except maybe in FCP.shortLived
- If true, don't intern the strings.allowBase64
- If true, allow reading Base64 encoded lines (key==base64(value)).alwaysBase64
- If true, the resulting SFS should have the alwaysUseBase64 flag enabled,
i.e it can store anything in key values including newlines, special chars such as = etc.
Otherwise, even if allowBase64 is enabled, invalid chars will not be.java.io.IOException
- If a read error occurs, including a formatting error, illegal
characters etc.public static SimpleFieldSet readFrom(java.io.File f, boolean allowMultiple, boolean shortLived) throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public void writeToBigBuffer(java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStream os, int bufferSize) throws java.io.IOException
java.io.IOException
public int getInt(java.lang.String key, int def)
key
- The key to fetch.def
- The default value to return if the key does not exist or can't be parsed.public int getInt(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key=value pair does not exist or if the value cannot be
parsed as an integer.public double getDouble(java.lang.String key, double def)
key
- The key to fetch.def
- The default value to return if the key does not exist or can't be parsed.public double getDouble(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key=value pair does not exist or if the value cannot be
parsed as a double.public long getLong(java.lang.String key, long def)
key
- The key to fetch.def
- The default value to return if the key does not exist or can't be parsed.public long getLong(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key=value pair does not exist or if the value cannot be
parsed as a long.public short getShort(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key=value pair does not exist or if the value cannot be
parsed as a short.public short getShort(java.lang.String key, short def)
key
- The key to fetch.public byte getByte(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key=value pair does not exist or if the value cannot be
parsed as a byte.public byte getByte(java.lang.String key, byte def)
key
- The key to fetch.public byte[] getByteArray(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key does not exist or cannot be parsed as a byte array.public char getChar(java.lang.String key) throws FSParseException
key
- The key to fetch.FSParseException
- If the key does not exist or there is more than one character.public char getChar(java.lang.String key, char def)
key
- The key to fetch.def
- The default value to return if the key does not exist or can't be parsed.FSParseException
- If the key does not exist or there is more than one character.public boolean getBoolean(java.lang.String key, boolean def)
public boolean getBoolean(java.lang.String key) throws FSParseException
FSParseException
public void put(java.lang.String key, int[] value)
public void put(java.lang.String key, double[] value)
public void put(java.lang.String key, float[] value)
public void put(java.lang.String key, short[] value)
public void put(java.lang.String key, long[] value)
public void put(java.lang.String key, boolean[] value)
public int[] getIntArray(java.lang.String key)
public short[] getShortArray(java.lang.String key)
public long[] getLongArray(java.lang.String key)
public double[] getDoubleArray(java.lang.String key)
public float[] getFloatArray(java.lang.String key)
public boolean[] getBooleanArray(java.lang.String key)
public void putOverwrite(java.lang.String key, java.lang.String[] strings)
public void putEncoded(java.lang.String key, java.lang.String[] strings)
public java.lang.String getString(java.lang.String key) throws FSParseException
FSParseException
public void setHeader(java.lang.String... headers)
headers
- The list of lines to precede the SimpleFieldSet by when we write it.public java.lang.String[] getHeader()
public void put(java.lang.String key, java.lang.String[] values)