public class PropertiesLexer extends Object
Parse a properties file generally conformant to the description at http://download.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader) into tokens. The lexer will be slightly more true to the data than java.util. For example, it will preserve whitespace in the value as valid data, which java.util.Properties would silently strip off. The lexer will also happily consume UTF-8 (no need for unicode-style escapes). Use Mode.Compatibility for better compatibility to the java.util package and the "spec" above. There is one additional extension in the lexer: a comment line which starts with #;; is treated as transient (not read in as a comment or saved as a comment in the properties results). This can be used to generate a transient header and footer. As of version 1.3.2-SNAPSHOT and above, these lines are parsed as META_DATA tokens and are available in the parse phase. This class is an "off-line" (non-streaming) lexer, it is backed by a String as input, which implies it is limited by memory resources. That's not a problem for all but unusually large properties files on contemporary hardware.
PropertiesToken,
PropertiesTokenType,
InputAdapter| Modifier and Type | Field and Description |
|---|---|
(package private) int |
index |
(package private) String |
input |
(package private) List<PropertiesToken> |
list |
private Lock |
lock |
| Constructor and Description |
|---|
PropertiesLexer(File in,
Charset charset)
Convenience method, swallows the input whole
This method filters for unicode escapes if the mode is Compatibility
This method requires we specify the explicit charset of the file
|
PropertiesLexer(InputStream in)
Convenience method, swallows the input whole
This method filters for unicode escapes if the mode is Compatibility
|
PropertiesLexer(InputStream in,
Charset charset) |
PropertiesLexer(Reader in)
Convenience method, swallows the input whole
This method filters for unicode escapes if the mode is Compatibility
|
PropertiesLexer(String input)
Convenience method, swallows the input whole
This method filters for unicode escapes if the mode is Compatibility
|
| Modifier and Type | Method and Description |
|---|---|
private void |
analyzeLine(String buf,
PropertiesToken tok,
long count) |
private void |
comment(String buf) |
List<PropertiesToken> |
getList() |
private boolean |
hasNext() |
private Character |
la(int count) |
void |
lex() |
private char |
next() |
private void |
scanKeyValue(String buf,
PropertiesToken eol) |
private PropertiesToken |
scanLineBreak() |
final String input
int index
final List<PropertiesToken> list
private final Lock lock
public PropertiesLexer(String input)
in - public PropertiesLexer(Reader in)
in - public PropertiesLexer(File in, Charset charset)
in - public PropertiesLexer(InputStream in)
in - public PropertiesLexer(InputStream in, Charset charset)
public void lex()
private void analyzeLine(String buf, PropertiesToken tok, long count)
private void scanKeyValue(String buf, PropertiesToken eol)
private void comment(String buf)
private PropertiesToken scanLineBreak()
private boolean hasNext()
private char next()
private Character la(int count)
public List<PropertiesToken> getList()
Copyright © 2011-2014 David R. Smith. All Rights Reserved.