umontreal.iro.lecuyer.util
Class TextDataReader
- java.lang.Object
-
- umontreal.iro.lecuyer.util.TextDataReader
-
public class TextDataReader extends java.lang.ObjectProvides static methods to read data from text files.
-
-
Constructor Summary
Constructors Constructor and Description TextDataReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.String[][]readCSVData(java.io.File file, char colDelim, char stringDelim)This is equivalent toreadDoubleData2D, for reading strings.static java.lang.String[][]readCSVData(java.io.Reader input, char colDelim, char stringDelim)Reads comma-separated values (CSV) from reader input, and returns a 2D array of strings corresponding to the read data.static java.lang.String[][]readCSVData(java.lang.String file, char colDelim, char stringDelim)This is equivalent toreadDoubleData2D, for reading strings.static java.lang.String[][]readCSVData(java.net.URL url, char colDelim, char stringDelim)Connects to the URL referred to by the URL object url, and callsreadCSVDatato obtain a matrix of strings from the resource.static double[]readDoubleData(java.io.File file)Opens the file referred to by the file object file, and callsreadDoubleDatato obtain an array of double-precision values from the file.static double[]readDoubleData(java.io.Reader input)Reads an array of double-precision values from the reader input.static double[]readDoubleData(java.lang.String file)Opens the file with name file, and callsreadDoubleDatato obtain an array of double-precision values from the file.static double[]readDoubleData(java.net.URL url)Connects to the URL referred to by the URL object url, and callsreadDoubleDatato obtain an array of double-precision values from the resource.static double[][]readDoubleData2D(java.io.File file)Opens the file referred to by the file object file, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the file.static double[][]readDoubleData2D(java.io.Reader input)Uses the reader input to obtain a 2-dimensional array of double-precision values.static double[][]readDoubleData2D(java.lang.String file)Opens the file with name file, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the file.static double[][]readDoubleData2D(java.net.URL url)Connects to the URL referred to by the URL object url, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the resource.static int[]readIntData(java.io.File file)This is equivalent toreadDoubleData, for reading integers.static int[]readIntData(java.io.Reader input)This is equivalent toreadDoubleData, for reading integers.static int[]readIntData(java.lang.String file)This is equivalent toreadDoubleData, for reading integers.static int[]readIntData(java.net.URL url)Connects to the URL referred to by the URL object url, and callsreadIntDatato obtain an array of integers from the resource.static int[][]readIntData2D(java.io.File file)This is equivalent toreadDoubleData2D, for reading integers.static int[][]readIntData2D(java.io.Reader input)This is equivalent toreadDoubleData2D, for reading integers.static int[][]readIntData2D(java.lang.String file)This is equivalent toreadDoubleData2D, for reading integers.static int[][]readIntData2D(java.net.URL url)Connects to the URL referred to by the URL object url, and callsreadDoubleDatato obtain a matrix of integers from the resource.static java.lang.String[]readStringData(java.io.File file)This is equivalent toreadDoubleData, for reading strings.static java.lang.String[]readStringData(java.io.Reader input)Reads an array of strings from the reader input.static java.lang.String[]readStringData(java.lang.String file)This is equivalent toreadDoubleData, for reading strings.static java.lang.String[]readStringData(java.net.URL url)Connects to the URL referred to by the URL object url, and callsreadStringDatato obtain an array of integers from the resource.
-
-
-
Method Detail
-
readDoubleData
public static double[] readDoubleData(java.io.Reader input) throws java.io.IOExceptionReads an array of double-precision values from the reader input. For each line of text obtained from the given reader, this method trims whitespaces, and parses the remaining text as a double-precision value. This method ignores every character other than the digits, the plus and minus signs, the period (.), and the letters e and E. Moreover, lines starting with a pound sign (#) are considered as comments and thus skipped. The method returns an array containing all the parsed values.- Parameters:
input- the reader to obtain data from.- Returns:
- the obtained array of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData
public static double[] readDoubleData(java.net.URL url) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadDoubleDatato obtain an array of double-precision values from the resource.- Parameters:
url- the URL object representing the resource to read.- Returns:
- the obtained array of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData
public static double[] readDoubleData(java.io.File file) throws java.io.IOExceptionOpens the file referred to by the file object file, and callsreadDoubleDatato obtain an array of double-precision values from the file.- Parameters:
file- the file object representing the file to read.- Returns:
- the obtained array of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData
public static double[] readDoubleData(java.lang.String file) throws java.io.IOExceptionOpens the file with name file, and callsreadDoubleDatato obtain an array of double-precision values from the file.- Parameters:
file- the name of the file to read.- Returns:
- the obtained array of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData
public static int[] readIntData(java.io.Reader input) throws java.io.IOExceptionThis is equivalent toreadDoubleData, for reading integers.- Parameters:
input- the reader to obtain data from.- Returns:
- the obtained array of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData
public static int[] readIntData(java.net.URL url) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadIntDatato obtain an array of integers from the resource.- Parameters:
url- the URL object representing the resource to read.- Returns:
- the obtained array of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData
public static int[] readIntData(java.io.File file) throws java.io.IOExceptionThis is equivalent toreadDoubleData, for reading integers.- Parameters:
file- the file object represented to file to read.- Returns:
- the array of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData
public static int[] readIntData(java.lang.String file) throws java.io.IOExceptionThis is equivalent toreadDoubleData, for reading integers.- Parameters:
file- the name of the file to read.- Returns:
- the array of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readStringData
public static java.lang.String[] readStringData(java.io.Reader input) throws java.io.IOExceptionReads an array of strings from the reader input. For each line of text obtained from the given reader, this method trims leading and trailing whitespaces, and stores the remaining string. Lines starting with a pound sign (#) are considered as comments and thus skipped. The method returns an array containing all the read strings.- Parameters:
input- the reader to obtain data from.- Returns:
- the obtained array of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readStringData
public static java.lang.String[] readStringData(java.net.URL url) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadStringDatato obtain an array of integers from the resource.- Parameters:
url- the URL object representing the resource to read.- Returns:
- the obtained array of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readStringData
public static java.lang.String[] readStringData(java.io.File file) throws java.io.IOExceptionThis is equivalent toreadDoubleData, for reading strings.- Parameters:
file- the file object represented to file to read.- Returns:
- the array of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readStringData
public static java.lang.String[] readStringData(java.lang.String file) throws java.io.IOExceptionThis is equivalent toreadDoubleData, for reading strings.- Parameters:
file- the name of the file to read.- Returns:
- the array of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData2D
public static double[][] readDoubleData2D(java.io.Reader input) throws java.io.IOExceptionUses the reader input to obtain a 2-dimensional array of double-precision values. For each line of text obtained from the given reader, this method trims whitespaces, and parses the remaining text as an array of double-precision values. Every character other than the digits, the plus (+) and minus (-) signs, the period (.), and the letters e and E are ignored and can be used to separate numbers on a line. Moreover, lines starting with a pound sign (#) are considered as comments and thus skipped. The lines containing only a semicolon sign (;) are considered as empty lines. The method returns a 2D array containing all the parsed values. The returned array is not always rectangular.- Parameters:
input- the reader to obtain data from.- Returns:
- the 2D array of double-precison values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData2D
public static double[][] readDoubleData2D(java.net.URL url) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the resource.- Parameters:
url- the URL object representing the resource to read.- Returns:
- the obtained matrix of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData2D
public static double[][] readDoubleData2D(java.io.File file) throws java.io.IOExceptionOpens the file referred to by the file object file, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the file.- Parameters:
file- the file object representing the file to read.- Returns:
- the obtained matrix of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readDoubleData2D
public static double[][] readDoubleData2D(java.lang.String file) throws java.io.IOExceptionOpens the file with name file, and callsreadDoubleData2Dto obtain a matrix of double-precision values from the file.- Parameters:
file- the name of the file to read.- Returns:
- the obtained matrix of double-precision values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData2D
public static int[][] readIntData2D(java.io.Reader input) throws java.io.IOExceptionThis is equivalent toreadDoubleData2D, for reading integers.- Parameters:
input- the reader to obtain data from.- Returns:
- the obtained 2D array of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData2D
public static int[][] readIntData2D(java.net.URL url) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadDoubleDatato obtain a matrix of integers from the resource.- Parameters:
url- the URL object representing the resource to read.- Returns:
- the obtained matrix of integers.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData2D
public static int[][] readIntData2D(java.io.File file) throws java.io.IOExceptionThis is equivalent toreadDoubleData2D, for reading integers.- Parameters:
file- the file object represented to file to read.- Returns:
- the obtained matrix of integer values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readIntData2D
public static int[][] readIntData2D(java.lang.String file) throws java.io.IOExceptionThis is equivalent toreadDoubleData2D, for reading integers.- Parameters:
file- the name of the file to read.- Returns:
- the obtained matrix of integer values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readCSVData
public static java.lang.String[][] readCSVData(java.io.Reader input, char colDelim, char stringDelim) throws java.io.IOExceptionReads comma-separated values (CSV) from reader input, and returns a 2D array of strings corresponding to the read data. Lines are delimited using line separators r, n, and rn. Each line contains one or more values, separated by the column delimiter colDelim. If a string of characters is surrounded with the string delimiter stringDelim, any line separator and column separator appear in the string. The string delimiter can be inserted in such a string by putting it twice. Usually, the column delimiter is the comma, and the string delimiter is the quotation mark. The following example uses these default delimiters."One","Two","Three" 1,2,3 "String with "" delimiter",n,mThis produces a matrix of strings with dimensions 3×3. The first row contains the strings One, Two, and Three while the second row contains the strings 1, 2, and 3. The first column of the last row contains the string String with " delimiter.- Parameters:
input- the reader to obtain data from.colDelim- the column delimiter.stringDelim- the string delimiter.- Returns:
- the obtained 2D array of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readCSVData
public static java.lang.String[][] readCSVData(java.net.URL url, char colDelim, char stringDelim) throws java.io.IOExceptionConnects to the URL referred to by the URL object url, and callsreadCSVDatato obtain a matrix of strings from the resource.- Parameters:
url- the URL object representing the resource to read.colDelim- the column delimiter.stringDelim- the string delimiter.- Returns:
- the obtained matrix of strings.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readCSVData
public static java.lang.String[][] readCSVData(java.io.File file, char colDelim, char stringDelim) throws java.io.IOExceptionThis is equivalent toreadDoubleData2D, for reading strings.- Parameters:
file- the file object represented to file to read.colDelim- the column delimiter.stringDelim- the string delimiter.- Returns:
- the obtained matrix of string values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
readCSVData
public static java.lang.String[][] readCSVData(java.lang.String file, char colDelim, char stringDelim) throws java.io.IOExceptionThis is equivalent toreadDoubleData2D, for reading strings.- Parameters:
file- the name of the file to read.colDelim- the column delimiter.stringDelim- the string delimiter.- Returns:
- the obtained matrix of string values.
- Throws:
java.io.IOException- if an I/O error occurs.
-
-
DMelt 3.0 © DataMelt by jWork.ORG