util
Class AsciiReader

java.lang.Object
  extended by util.AsciiReader

public class AsciiReader
extends Object

A class providing static methods for reading ASCII-files. Used to spare comment lines, marked with a starting COMMENT char, from input.


Nested Class Summary
static class AsciiReader.BlockData
          Reads a block file and prints the desired columns to standard out.
static class AsciiReader.BlockReformat
          Similar to block data, this class reads an ascii-column file, but on output performs a re-format using the decimal formatters specified.
static class AsciiReader.InsertColumn
          Reads a block file and adds a column to the data.
static class AsciiReader.PixelMatch
          Reads two files with 2D points given at the appropriate indices and matches them for the desired precision.
static class AsciiReader.Time
          Converts lines in hh:mm:ss.sss to ms.
 
Field Summary
static char[] COMMENT
          A char array with comment-line markers.
private static String STRCOM
          The string representation of the COMMENT array for ease.
 
Constructor Summary
AsciiReader()
           
 
Method Summary
static List<List<String>> extractTokens(List<String> lines, List<Integer> cols)
          Extract only the requested columns as string tokens in the requested order.
static Map<Integer,List<Double>> getDoubleColumns(List<String> lines, Collection<Integer> columns)
          Takes a list of valid lines and extracts double values out of it.
static List<String> getLines(File file)
          Converts the filename into a file from which the names are read in.
static List<String> getLines(File listfile, boolean trim)
          Retrieves a list of strings from a file.
static List<String> getLines(InputStream in)
          Reads from an input stream with trimming enabled.
static List<String> getLines(InputStream instream, boolean trim)
          Reads from an input stream.
static List<String> getLines(String filename)
          Converts the filename into a file from which the names are read in.
static List<String> getLines(String path, String filename)
          Converts the filename into a file from which the names are read in.
static List<String> getLines(URL resource)
          Retrieves a list of strings from a URL.
static List<String> getLines(URL resource, boolean trim)
          Retrieves a list of strings from a URL.
static
<T extends Number>
Map<Integer,List<T>>
getNumberColumns(List<String> lines, Map<Integer,Class<T>> columns)
          Extract valid lines to numbers of the given types.
static List<Double> getSingleColumn(List<String> lines, int c)
          Returns a list of doubles from the stated colum.
static Map<Integer,List<String>> getTokenColumns(List<String> lines, Collection<Integer> cols)
          Extract columns to strings.
static Map<Integer,List<Number>> parseNumberColumns(List<String> lines, Map<Integer,? extends NumberFormat> format)
          Extract valid lines to numbers of the given types.
static VectorG[] parseVector(List<String> lines, Collection<Integer> columns)
          Parses a list of lines into an array of VectorGs.
static VectorG[] parseVector(List<String> lines, Map<Integer,? extends NumberFormat> format)
          Parses a list of lines into an array of VectorGs.
private static
<T extends Number>
VectorG[]
vectorParsing(Collection<Integer> columns, Map<Integer,List<T>> col2vals)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMENT

public static final char[] COMMENT
A char array with comment-line markers.


STRCOM

private static final String STRCOM
The string representation of the COMMENT array for ease.

Constructor Detail

AsciiReader

public AsciiReader()
Method Detail

getLines

public static List<String> getLines(String path,
                                    String filename)
Converts the filename into a file from which the names are read in. Lines are trimmed.

Returns:
A list of Strings
See Also:
FileAccess.fromName(java.lang.String, java.lang.String)

getLines

public static List<String> getLines(String filename)
Converts the filename into a file from which the names are read in. Lines are trimmed.

Returns:
A list of Strings
See Also:
FileAccess.fromName(java.lang.String, java.lang.String)

getLines

public static List<String> getLines(File file)
Converts the filename into a file from which the names are read in. Lines are trimmed.

Returns:
A list of Strings
See Also:
FileAccess.fromName(java.lang.String, java.lang.String)

getLines

public static List<String> getLines(File listfile,
                                    boolean trim)
Retrieves a list of strings from a file. Each line read in the input file is considered to be a string. Lines starting with one of the chars in COMMENT are ignored. If the target file cannot be found or read, null is returned. If the target list file is empty or consists of only comment lines an empty list is returned.

Parameters:
listfile - An ASCII-file with comments.
trim - True if lines should be trimmed.
Returns:
A list of Strings

getLines

public static List<String> getLines(URL resource)
Retrieves a list of strings from a URL. Each line read in the input stream is considered to be a string. Lines starting with one of the chars in COMMENT are ignored. If the target cannot be found or opened, null is returned. If the target list is empty or consists of only comment lines an empty list is returned.
This method does trim the lines read.

Parameters:
resource - An URL pointing to an ASCII-file.
Returns:
A list of Strings

getLines

public static List<String> getLines(URL resource,
                                    boolean trim)
Retrieves a list of strings from a URL. Each line read in the input stream is considered to be a string. Lines starting with one of the chars in COMMENT are ignored. If the target cannot be found or opened, null is returned. If the target list is empty or consists of only comment lines an empty list is returned.

Parameters:
resource - An URL pointing to an ASCII-file.
trim - True if lines should be trimmed.
Returns:
A list of Strings

getLines

public static List<String> getLines(InputStream in)
Reads from an input stream with trimming enabled.


getLines

public static List<String> getLines(InputStream instream,
                                    boolean trim)
Reads from an input stream. The stream is not closed.


getSingleColumn

public static List<Double> getSingleColumn(List<String> lines,
                                           int c)
Returns a list of doubles from the stated colum.


getDoubleColumns

public static Map<Integer,List<Double>> getDoubleColumns(List<String> lines,
                                                         Collection<Integer> columns)
Takes a list of valid lines and extracts double values out of it. Provided is a collection of column numbers, returned a mapping of the column numbers to lists of doubles. Column numbering starts with 1.


parseVector

public static VectorG[] parseVector(List<String> lines,
                                    Map<Integer,? extends NumberFormat> format)
Parses a list of lines into an array of VectorGs. The array returned can be parsed to an array of Vector2D, resp. Vector3D, if the number of columns is appropriate.


parseVector

public static VectorG[] parseVector(List<String> lines,
                                    Collection<Integer> columns)
Parses a list of lines into an array of VectorGs. The array returned can be parsed to an array of Vector2D, resp. Vector3D, if the number of columns is appropriate.


vectorParsing

private static <T extends Number> VectorG[] vectorParsing(Collection<Integer> columns,
                                                          Map<Integer,List<T>> col2vals)

getTokenColumns

public static Map<Integer,List<String>> getTokenColumns(List<String> lines,
                                                        Collection<Integer> cols)
Extract columns to strings.


extractTokens

public static List<List<String>> extractTokens(List<String> lines,
                                               List<Integer> cols)
Extract only the requested columns as string tokens in the requested order.


parseNumberColumns

public static Map<Integer,List<Number>> parseNumberColumns(List<String> lines,
                                                           Map<Integer,? extends NumberFormat> format)
                                                    throws ParseException
Extract valid lines to numbers of the given types. Provided is a mapping of column numbers to Number classes, returned a mapping of the column numbers to lists of Numbers. Column numbering starts with 1.

Throws:
ParseException

getNumberColumns

public static <T extends Number> Map<Integer,List<T>> getNumberColumns(List<String> lines,
                                                                       Map<Integer,Class<T>> columns)
Extract valid lines to numbers of the given types. Provided is a mapping of column numbers to Number classes, returned a mapping of the column numbers to lists of Numbers. Column numbering starts with 1.