|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer java.io.PrintWriter net.sf.basedb.util.bfs.MetadataWriter
public class MetadataWriter
Writer implementation for writing BFS metadata files. The start
of file marker (BFSformat) is written immediately at object
construction. Use the bfsPrintSection(String, boolean, boolean)
to start a new section, and bfsPrintValue(String, String...)
to print a section entry. It is not recommended that any of
the superclass methods (eg. PrintWriter
methods} are used
directly as it can create an invalid BFS metadata file.
This class can be subclassed to get specific functionality in specific use cases.
Field Summary | |
---|---|
static String |
BOF_MARKER
|
private String |
currentSection
|
private EncoderDecoder |
encoder
|
private String |
filename
|
private int |
lineCount
|
private int |
sectionCount
|
private String |
subtype
|
private boolean |
uniqueKeys
|
private Set<String> |
usedKeys
|
private Set<String> |
usedSections
|
private int |
valueCount
|
Fields inherited from class java.io.PrintWriter |
---|
out |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
MetadataWriter(Writer out)
Create a new BFS metadata writer. |
Method Summary | ||
---|---|---|
void |
bfsPrintComment(String comment)
Prints one or more comment lines to the metadata file. |
|
void |
bfsPrintEmptyLine(int num)
Print one or more empty lines to the metadata file. |
|
void |
bfsPrintSection(String name,
boolean unique,
boolean uniqueKeys)
Start a new section. |
|
|
bfsPrintValue(String key,
Formatter<T> formatter,
T... values)
Prints a section entry. |
|
void |
bfsPrintValue(String key,
String... values)
Prints a section entry. |
|
|
bfsPrintValue(String key,
T... values)
Prints a section entry. |
|
static MetadataWriter |
create(File file)
Utility method for creating a metadata writer to a file in the BASE file system. |
|
static MetadataWriter |
create(File file)
Utility method for creating a metadata writer to a file in the native file system. |
|
static MetadataWriter |
create(OutputStream out,
String filename)
Utility method for creating a metadata writer when you have an output stream. |
|
String |
encodeValue(String value)
Encode a value for use in a BFS file. |
|
String |
getCurrentSection()
Get the name of the current section. |
|
String |
getFilename()
Get the file name that this writer is printing to. |
|
int |
getLineCount()
Get the number of lines that has been written to this file so far, including all comment lines, empty lines, sections headers, etc. |
|
int |
getSectionCount()
Get the number of sections that has been written to this file so far. |
|
String |
getSubtype()
Get the BFS subtype. |
|
boolean |
getUniqueKeys()
Checks if the current section requires entry names to be unique or not. |
|
int |
getValueCount()
Get the number of values that has been written to the current section so far. |
|
protected void |
internalPrintBofMarker()
Prints the beginning-of-file marker. |
|
protected void |
internalPrintComment(String comment)
Print a single-line comment. |
|
protected void |
internalPrintSection(String encodedName)
Prints a section header assuming that the name has already been encoded. |
|
protected void |
internalPrintValue(String encodedKey,
String encodedValue)
Prints a section entry assuming that the key and value has already been encoded. |
|
boolean |
isUsedKey(String key)
Checks if the current section already has an entry for the given key or not. |
|
void |
setFilename(String filename)
Set the file name that this writer is printing to. |
|
void |
setSubtype(String subtype)
Set the BFS subtype for this writer. |
Methods inherited from class java.io.PrintWriter |
---|
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String BOF_MARKER
private final EncoderDecoder encoder
private String filename
private String subtype
private Set<String> usedSections
private Set<String> usedKeys
private String currentSection
private boolean uniqueKeys
private int lineCount
private int sectionCount
private int valueCount
Constructor Detail |
---|
public MetadataWriter(Writer out)
out
- The parent writer which this writer will print toMethod Detail |
---|
public static MetadataWriter create(OutputStream out, String filename)
out
- The output stream the metadata writer should print tofilename
- Optional, the name of the file the output stream
is printing topublic static MetadataWriter create(File file)
file
- The file in the BASE file systempublic static MetadataWriter create(File file) throws IOException
file
- The file in the native file system
IOException
public String getFilename()
public void setFilename(String filename)
public String getSubtype()
public void setSubtype(String subtype)
subtype
- The subtype
IllegalStateException
- If data has already been writtenpublic String getCurrentSection()
public boolean getUniqueKeys()
public boolean isUsedKey(String key)
key
- The key to check
public String encodeValue(String value)
value
- The value to encode, may be null
public int getLineCount()
public int getSectionCount()
public int getValueCount()
public void bfsPrintEmptyLine(int num)
num
- The number of empty lines to print. If 0 or negative
nothing is writtenpublic void bfsPrintComment(String comment)
comment
- The comment stringpublic void bfsPrintSection(String name, boolean unique, boolean uniqueKeys)
name
- The name of the section, null is not allowedunique
- TRUE if this section must be unique within the metadata
fileuniqueKeys
- TRUE if all keys in this section must be unique
NullPointerException
- If the section name is null
IllegalArgumentException
- If the name is not unique and
the writer requires unique sectionspublic void bfsPrintValue(String key, String... values)
bfsPrintSection(String, boolean, boolean)
before this
method is invoked.
key
- The entry key; null is not allowed and it may not
start with '[' or '#'values
- An array of string values, each value will be encoded
independently and separated with a tab
NullPointerException
- If the key is null
IllegalArgumentException
- If the key starts with '[' or
'#', or if the key is not unique within a section that requires
unique keys
IllegalStateException
- If no section has been startedpublic <T> void bfsPrintValue(String key, T... values)
bfsPrintSection(String, boolean, boolean)
before this
method is invoked.
key
- The entry key; null is not allowed and it may not
start with '[' or '#'values
- An array of objects, each value will be be converted to
a string by calling the toString() method
NullPointerException
- If the key is null
IllegalArgumentException
- If the key starts with '[' or
'#', or if the key is not unique within a section that requires
unique keys
IllegalStateException
- If no section has been startedpublic <T> void bfsPrintValue(String key, Formatter<T> formatter, T... values)
bfsPrintSection(String, boolean, boolean)
before this
method is invoked.
key
- The entry key; null is not allowed and it may not
start with '[' or '#'formatter
- A formatter that should be used to convert the
values to strings, or null to simply use the toString() methodvalues
- An array of objects, each value will be encoded
independently and separated with a tab
NullPointerException
- If the key is null
IllegalArgumentException
- If the key starts with '[' or
'#', or if the key is not unique within a section that requires
unique keys
IllegalStateException
- If no section has been startedprotected void internalPrintBofMarker()
BFSformat<tab>subtype
protected void internalPrintComment(String comment)
protected void internalPrintSection(String encodedName)
protected void internalPrintValue(String encodedKey, String encodedValue)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |