|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.unimi.dsi.fastutil.io.TextIO
Provides static methods to perform easily textual I/O.
This class fills a gap in the Java API: a natural operation on sequences of primitive elements is to load or store them in textual form. This format makes files humanly readable.
For each primitive type, this class provides methods that read elements
from a BufferedReader
or from a filename (which will be opened
using a buffer of BUFFER_SIZE
bytes) into an array. Analogously,
there are methods that store the content of an array (fragment) or the
elements returned by an iterator to a PrintStream
or to a given
filename.
Finally, there are useful wrapper methods that exhibit a file as a type-specific iterator.
Note that, contrarily to the binary case, there is no way to load an array from a file. You can easily work around the problem as follows:
array = IntIterators.unwrap( TextIO.asIntIterator("foo") );
Field Summary | |
static int |
BUFFER_SIZE
The size of the buffer used for all I/O on files. |
Method Summary | |
static ByteIterator |
asByteIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static ByteIterator |
asByteIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static DoubleIterator |
asDoubleIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static DoubleIterator |
asDoubleIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static FloatIterator |
asFloatIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static FloatIterator |
asFloatIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static IntIterator |
asIntIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static IntIterator |
asIntIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static LongIterator |
asLongIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static LongIterator |
asLongIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static ShortIterator |
asShortIterator(BufferedReader reader)
Wraps the given buffered reader into an iterator. |
static ShortIterator |
asShortIterator(CharSequence filename)
Wraps the given filename into an iterator. |
static int |
loadBytes(BufferedReader reader,
byte[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadBytes(BufferedReader reader,
byte[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadBytes(CharSequence filename,
byte[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadBytes(CharSequence filename,
byte[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static int |
loadDoubles(BufferedReader reader,
double[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadDoubles(BufferedReader reader,
double[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadDoubles(CharSequence filename,
double[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadDoubles(CharSequence filename,
double[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static int |
loadFloats(BufferedReader reader,
float[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadFloats(BufferedReader reader,
float[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadFloats(CharSequence filename,
float[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadFloats(CharSequence filename,
float[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static int |
loadInts(BufferedReader reader,
int[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadInts(BufferedReader reader,
int[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadInts(CharSequence filename,
int[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadInts(CharSequence filename,
int[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static int |
loadLongs(BufferedReader reader,
long[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadLongs(BufferedReader reader,
long[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadLongs(CharSequence filename,
long[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadLongs(CharSequence filename,
long[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static int |
loadShorts(BufferedReader reader,
short[] array)
Loads elements from a given buffered reader, storing them in a given array. |
static int |
loadShorts(BufferedReader reader,
short[] array,
int offset,
int length)
Loads elements from a given fast buffered reader, storing them in a given array fragment. |
static int |
loadShorts(CharSequence filename,
short[] array)
Loads elements from a given filename, storing them in a given array. |
static int |
loadShorts(CharSequence filename,
short[] array,
int offset,
int length)
Loads elements from a given filename, storing them in a given array fragment. |
static void |
storeBytes(byte[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeBytes(byte[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeBytes(byte[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeBytes(byte[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeBytes(ByteIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeBytes(ByteIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
static void |
storeDoubles(double[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeDoubles(double[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeDoubles(double[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeDoubles(double[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeDoubles(DoubleIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeDoubles(DoubleIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
static void |
storeFloats(float[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeFloats(float[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeFloats(float[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeFloats(float[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeFloats(FloatIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeFloats(FloatIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
static void |
storeInts(int[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeInts(int[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeInts(int[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeInts(int[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeInts(IntIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeInts(IntIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
static void |
storeLongs(long[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeLongs(long[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeLongs(long[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeLongs(long[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeLongs(LongIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeLongs(LongIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
static void |
storeShorts(short[] array,
CharSequence filename)
Stores an array to a given filename. |
static void |
storeShorts(short[] array,
int offset,
int length,
CharSequence filename)
Stores an array fragment to a given filename. |
static void |
storeShorts(short[] array,
int offset,
int length,
PrintStream stream)
Stores an array fragment to a given print stream. |
static void |
storeShorts(short[] array,
PrintStream stream)
Stores an array to a given print stream. |
static void |
storeShorts(ShortIterator i,
CharSequence filename)
Stores the element returned by an iterator to a given filename. |
static void |
storeShorts(ShortIterator i,
PrintStream stream)
Stores the element returned by an iterator to a given print stream. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int BUFFER_SIZE
Method Detail |
public static int loadBytes(BufferedReader reader, byte[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadBytes(BufferedReader reader, byte[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadBytes(CharSequence filename, byte[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadBytes(CharSequence filename, byte[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeBytes(byte[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeBytes(byte[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeBytes(byte[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeBytes(byte[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeBytes(ByteIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeBytes(ByteIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static ByteIterator asByteIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static ByteIterator asByteIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
public static int loadShorts(BufferedReader reader, short[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadShorts(BufferedReader reader, short[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadShorts(CharSequence filename, short[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadShorts(CharSequence filename, short[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeShorts(short[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeShorts(short[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeShorts(short[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeShorts(short[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeShorts(ShortIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeShorts(ShortIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static ShortIterator asShortIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static ShortIterator asShortIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
public static int loadInts(BufferedReader reader, int[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadInts(BufferedReader reader, int[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadInts(CharSequence filename, int[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadInts(CharSequence filename, int[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeInts(int[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeInts(int[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeInts(int[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeInts(int[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeInts(IntIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeInts(IntIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static IntIterator asIntIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static IntIterator asIntIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
public static int loadLongs(BufferedReader reader, long[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadLongs(BufferedReader reader, long[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadLongs(CharSequence filename, long[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadLongs(CharSequence filename, long[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeLongs(long[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeLongs(long[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeLongs(long[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeLongs(long[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeLongs(LongIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeLongs(LongIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static LongIterator asLongIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static LongIterator asLongIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
public static int loadFloats(BufferedReader reader, float[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadFloats(BufferedReader reader, float[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadFloats(CharSequence filename, float[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadFloats(CharSequence filename, float[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeFloats(float[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeFloats(float[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeFloats(float[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeFloats(float[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeFloats(FloatIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeFloats(FloatIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static FloatIterator asFloatIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static FloatIterator asFloatIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
public static int loadDoubles(BufferedReader reader, double[] array, int offset, int length) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
reader
(it might be less than length
if reader
ends).
IOException
public static int loadDoubles(BufferedReader reader, double[] array) throws IOException
reader
- a buffered reader.array
- an array which will be filled with data from reader
.
reader
(it might be less than the array length if reader
ends).
IOException
public static int loadDoubles(CharSequence filename, double[] array, int offset, int length) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.offset
- the index of the first element of array
to be filled.length
- the number of elements of array
to be filled.
length
if the file is too short).
IOException
public static int loadDoubles(CharSequence filename, double[] array) throws IOException
filename
- a file name.array
- an array which will be filled with data from the specified file.
IOException
public static void storeDoubles(double[] array, int offset, int length, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.stream
- a print stream.
IOException
public static void storeDoubles(double[] array, PrintStream stream) throws IOException
array
- an array whose elements will be written to stream
.stream
- a print stream.
IOException
public static void storeDoubles(double[] array, int offset, int length, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.offset
- the index of the first element of array
to be written.length
- the number of elements of array
to be written.filename
- a file name.
IOException
public static void storeDoubles(double[] array, CharSequence filename) throws IOException
array
- an array whose elements will be written to filename
.filename
- a file name.
IOException
public static void storeDoubles(DoubleIterator i, PrintStream stream) throws IOException
i
- an iterator whose output will be written to stream
.stream
- a print stream.
IOException
public static void storeDoubles(DoubleIterator i, CharSequence filename) throws IOException
i
- an iterator whose output will be written to filename
.filename
- a file name.
IOException
public static DoubleIterator asDoubleIterator(BufferedReader reader) throws IOException
reader
- a buffered reader.
IOException
public static DoubleIterator asDoubleIterator(CharSequence filename) throws IOException
filename
- a file name.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |