Package de.tsl2.nano.scanner
Class FieldReader
java.lang.Object
de.tsl2.nano.scanner.FieldReader
reads any fields from any text file using a
Scanner. all lines starting with COMMENT will be
ignored.
Features: - key/value properties. - any field-structure per line - calls your ICallback in a foreach() loopyou can combine these features to read complex data structures.
- Version:
- $Revision$
- Author:
- Tom
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <RESULT> List<RESULT>forEach(InputStream stream, de.tsl2.nano.core.ICallback<RESULT> callback) convenience delegating toforEach(InputStream, String, String, ICallback)with standard block definitions.static <RESULT> List<RESULT>forEach(InputStream stream, String blockExpression, String keyValueDelimiter, de.tsl2.nano.core.ICallback<RESULT> callback) runs through the stream, searching for the given blocks and providing each block content as property map to the callback.static Propertiesread(InputStream stream, boolean doClose) delegates to#read(InputStream, String, String, Locale)static Propertiesread(InputStream stream, String keyValueDelimiter, String propDelimiter, Locale locale, boolean doClose) reads key/value properties from any file using aScanner.static Propertiesdelegates to#read(InputStream)readTable(InputStream stream, boolean horizontal, boolean header, boolean rowIDs, String rowPattern) readTable(InputStream stream, Class... columnTypes) delegates toreadTable(InputStream, String, Locale, boolean, boolean, boolean, Class...)for simple tables without header and rowIDs.readTable(InputStream stream, String rowPattern) delegates toreadTable(InputStream, boolean, boolean, boolean, String)for a simple table without header and row-ids.readTable(InputStream stream, String fieldDelimiter, Locale locale, boolean horizontal, boolean header, boolean rowIDs, Class... columnTypes) reads values in columns and rows from any file using aScanner.delegates toreadTable(InputStream, Class...)
-
Field Details
-
HEADER
- See Also:
-
DEL_KEYVALUE
- See Also:
-
DEL_PROP
- See Also:
-
DEL_CSV
- See Also:
-
-
Constructor Details
-
FieldReader
public FieldReader()
-
-
Method Details
-
readTable
delegates toreadTable(InputStream, Class...) -
readTable
delegates toreadTable(InputStream, String, Locale, boolean, boolean, boolean, Class...)for simple tables without header and rowIDs. -
readTable
public static Map<Object,List> readTable(InputStream stream, String fieldDelimiter, Locale locale, boolean horizontal, boolean header, boolean rowIDs, Class... columnTypes) reads values in columns and rows from any file using aScanner.- Parameters:
stream- input streamfieldDelimiter- delimiter between two values. normallyDEL_CSV.locale- locale to format formats etc. normally the default localeLocale.getDefault().horizontal- if false, the map will be rotated to provide columns instead of rowsheader- if true, the first line will be read as header informationrowIDs- if true, all first column values will be read as row-id objects - otherwise a line counter will be used.columnTypes- indicates the column value types. known Scanner types are: byte, boolean, short, int, long, float, double, BigInteger, BigDecimal. the given locale defines the format of that types.- Returns:
- map holding its keys in the sequentially order. an optional header is stored on key
HEADER. all other keys are rowIDs or line indexes.
-
readTable
delegates toreadTable(InputStream, boolean, boolean, boolean, String)for a simple table without header and row-ids. -
readTable
public static Map<Object,List> readTable(InputStream stream, boolean horizontal, boolean header, boolean rowIDs, String rowPattern) reads values in columns and rows from any file using aScanner. giving a rows regular expression defines the column formats for each row. seeScannerfor examples. the row pattern should have grouping with brackets like '(\w+) fish (\w+) fish (\w+)'.- Parameters:
stream- input streamfieldDelimiter- delimiter between two values. normallyDEL_CSV.locale- locale to format formats etc. normally the default localeLocale.getDefault().horizontal- if false, the map will be rotated to provide columns instead of rowsheader- if true, the first line will be read as header informationrowIDs- if true, all first column values will be read as row-id objects - otherwise a line counter will be used.rowPattern-- Returns:
- map holding its keys in the sequentially order. an optional header is stored on key
HEADER. all other keys are rowIDs or line indexes.
-
read
delegates to#read(InputStream) -
read
delegates to#read(InputStream, String, String, Locale) -
read
public static Properties read(InputStream stream, String keyValueDelimiter, String propDelimiter, Locale locale, boolean doClose) reads key/value properties from any file using aScanner.- Parameters:
stream- input streamkeyValueDelimiter- delimiter between key and value. normallyDEL_KEYVALUE.propDelimiter- delimiter between two property entries. normallyDEL_PROPlocale- locale to format formats etc. normally the default localeLocale.getDefault().- Returns:
- property map
-
forEach
public static <RESULT> List<RESULT> forEach(InputStream stream, de.tsl2.nano.core.ICallback<RESULT> callback) convenience delegating toforEach(InputStream, String, String, ICallback)with standard block definitions. -
forEach
public static <RESULT> List<RESULT> forEach(InputStream stream, String blockExpression, String keyValueDelimiter, de.tsl2.nano.core.ICallback<RESULT> callback) runs through the stream, searching for the given blocks and providing each block content as property map to the callback.- Parameters:
stream- source streamblockExpression- defining the content of one block to read the properties fromkeyValueDelimiter- key-value delimitercallback- worker- Returns:
- threadsafe list of loop-count elements containing all callback results (null results are allowed)
-