public class LineIO extends Object
Constructor and Description |
---|
LineIO() |
Modifier and Type | Method and Description |
---|---|
static void |
append(String fileName,
Iterable<String> list)
Append a list of strings to a file, one per line
|
static <T> void |
append(String fileName,
Iterable<T> list,
ITransformer<T,String> transformer)
Append a list of items to a file, one per line
|
static void |
append(String fileName,
String line)
Append a string to a file
|
static <T> void |
append(String fileName,
T line,
ITransformer<T,String> transformer)
Append an item to a file
|
static InputStream |
getInputStream(String fileName)
This looks around to find the file, then returns an open inputstream.
|
static <T> ArrayList<T> |
read(InputStream fileStream,
String charsetName,
ITransformer<String,T> transformer)
This function reads an InputStream line-by-line and converts each line into an object using a
transformer that is passed as a parameter.
|
static ArrayList<String> |
read(String fileName)
An implementation of
read(String, Transformer<String, T>) . |
static <T> ArrayList<T> |
read(String fileName,
ITransformer<String,T> transformer)
This function reads a file line-by-line and converts each line into an object using a
transformer that is passed as a parameter.
|
static ArrayList<String> |
read(String fileName,
String charsetName)
An implementation of
read(String, Transformer<String, T>) . |
static <T> ArrayList<T> |
read(String fileName,
String charsetName,
ITransformer<String,T> transformer)
This function reads a file line-by-line and converts each line into an object using a
transformer that is passed as a parameter.
|
static ArrayList<String> |
readFromClasspath(String fileName)
This searches for the file on the classpath before reading it.
|
static ArrayList<String> |
readGZip(String fileName)
An implementation of
readGZip(String, Transformer<String, T>) . |
static <T> ArrayList<T> |
readGZip(String fileName,
ITransformer<String,T> transformer)
This function reads a gzipped file line-by-line and converts each line into an object using a
transformer that is passed as a parameter.
|
static String |
slurp(String fileName)
Read the contents of a file using the default charset and return as a single string
|
static String |
slurp(String fileName,
String charsetName)
Read the contents of a file and return as a single string
|
static void |
write(String fileName,
Iterable<String> list)
Writes a list of strings to a file, one per line.
|
static <T> void |
write(String fileName,
Iterable<T> list,
ITransformer<T,String> transformer)
This function writes a list of objects into a file, one per line.
|
static void |
writeGzip(String fileName,
Iterable<String> list)
Writes a list of strings to a file gzipped, one per line.
|
static <T> void |
writeGZip(String fileName,
Iterable<T> list,
ITransformer<T,String> transformer)
This function writes a list of objects into a Gzipped file, one per line.
|
public static String slurp(String fileName, String charsetName) throws FileNotFoundException
FileNotFoundException
public static String slurp(String fileName) throws FileNotFoundException
FileNotFoundException
public static <T> ArrayList<T> read(String fileName, String charsetName, ITransformer<String,T> transformer) throws FileNotFoundException
FileInputStream
created with
fileName
into
read(java.io.InputStream, String, ITransformer)
.T
- Each line of the file represents an object of type TfileName
- The name of the file to be readtransformer
- A transformer from String to type TArrayList
containing objects of type T, with one object corresponding to
each line.FileNotFoundException
public static <T> ArrayList<T> read(InputStream fileStream, String charsetName, ITransformer<String,T> transformer) throws FileNotFoundException
ArrayList
containing objects of type T, with one object corresponding to
each line.FileNotFoundException
public static <T> ArrayList<T> readGZip(String fileName, ITransformer<String,T> transformer) throws IOException
T
- Each line of the file represents an object of type TfileName
- The name of the file to be readtransformer
- A transformer from String to type TArrayList
containing objects of type T, with one object corresponding to
each line.IOException
public static <T> ArrayList<T> read(String fileName, ITransformer<String,T> transformer) throws FileNotFoundException
T
- Each line of the file represents an object of type TfileName
- The name of the file to be readtransformer
- A transformer from String to type TArrayList
containing objects of type T, with one object corresponding to
each line.FileNotFoundException
public static ArrayList<String> read(String fileName, String charsetName) throws FileNotFoundException
read(String, Transformer<String, T>)
. This function reads the
lines in a file and returns them.fileName
- The name of the file to be readFileNotFoundException
public static ArrayList<String> readGZip(String fileName) throws IOException
readGZip(String, Transformer<String, T>)
. This function reads
the lines in a gzipped file and returns them.fileName
- The name of the file to be readIOException
@AvoidUsing(reason="Cannot be used for accessing files inside jars in the classpath", alternative="readFromClasspath(String fileName)") public static ArrayList<String> read(String fileName) throws FileNotFoundException
read(String, Transformer<String, T>)
. This function reads the
lines in a file and returns them.fileName
- The name of the file to be readFileNotFoundException
public static ArrayList<String> readFromClasspath(String fileName) throws FileNotFoundException
FileNotFoundException
.fileName
- The name of the file to be readFileNotFoundException
public static InputStream getInputStream(String fileName) throws FileNotFoundException
ClassLoader.getResourceAsStream(String)
, which works better in maven.fileName
- The name of the file to be readFileNotFoundException
public static <T> void write(String fileName, Iterable<T> list, ITransformer<T,String> transformer) throws IOException
IOException
public static <T> void writeGZip(String fileName, Iterable<T> list, ITransformer<T,String> transformer) throws IOException
T
- Each line of the file represents an object of type TfileName
- The name of the file to be readtransformer
- A transformer from String to type TIOException
public static void write(String fileName, Iterable<String> list) throws IOException
IOException
public static void writeGzip(String fileName, Iterable<String> list) throws IOException
IOException
public static <T> void append(String fileName, Iterable<T> list, ITransformer<T,String> transformer) throws IOException
IOException
public static void append(String fileName, Iterable<String> list) throws IOException
IOException
public static <T> void append(String fileName, T line, ITransformer<T,String> transformer) throws IOException
IOException
public static void append(String fileName, String line) throws IOException
IOException
Copyright © 2017. All rights reserved.