1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/*
* Copyright (C) 2005-2024 Sebastiano Vigna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package it.unimi.dsi.fastutil.io;
import static it.unimi.dsi.fastutil.BigArrays.SEGMENT_MASK;
import static it.unimi.dsi.fastutil.BigArrays.length;
import static it.unimi.dsi.fastutil.BigArrays.start;
import static it.unimi.dsi.fastutil.BigArrays.segment;
import static it.unimi.dsi.fastutil.BigArrays.ensureOffsetLength;
import java.io.*;
import java.util.*;
import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.longs.*;
import it.unimi.dsi.fastutil.doubles.*;
import it.unimi.dsi.fastutil.booleans.*;
import it.unimi.dsi.fastutil.bytes.*;
import it.unimi.dsi.fastutil.shorts.*;
import it.unimi.dsi.fastutil.floats.*;
/** Provides static methods to perform easily textual I/O.
*
* <p>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.
*
* <p>For each primitive type, this class provides methods that read elements
* from a {@link BufferedReader} or from a filename (which will be opened
* using a buffer of {@link #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 {@link PrintStream} or to a given
* filename.
*
* <p>Finally, there are useful wrapper methods that {@linkplain #asIntIterator(CharSequence)
* exhibit a file as a type-specific iterator}.
*
* <p>Note that, contrarily to the binary case, there is no way to
* {@linkplain BinIO#loadInts(CharSequence) load from a file without providing an array}. You can
* easily work around the problem as follows:
* <pre>
* array = IntIterators.unwrap(TextIO.asIntIterator("foo"));
* </pre>
*
* @since 4.4
*/
public class TextIO {
private TextIO() {}
/** The size of the buffer used for all I/O on files. */
public static final int BUFFER_SIZE = 8 * 1024;
#include "src/it/unimi/dsi/fastutil/io/IntTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/LongTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/DoubleTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/BooleanTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/ByteTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/ShortTextIOFragment.h"
#include "src/it/unimi/dsi/fastutil/io/FloatTextIOFragment.h"
}
|