public class IO extends Object
Modifier and Type | Method and Description |
---|---|
static int |
read(ReadableByteChannel channel,
byte[] dst,
int off,
int len)
Read as much of the array as possible from a channel.
|
static byte[] |
readFully(File path)
Read an entire local file into memory as a byte array.
|
static byte[] |
readFully(File path,
int max)
Read an entire local file into memory as a byte array.
|
static int |
readFully(InputStream fd,
byte[] dst,
int off)
Read the entire byte array into memory, unless input is shorter
|
static void |
readFully(InputStream fd,
byte[] dst,
int off,
int len)
Read the entire byte array into memory, or throw an exception.
|
static String |
readLine(Reader in,
int sizeHint)
Read the next line from a reader.
|
static List<String> |
readLines(String s)
Divides the given string into lines.
|
static byte[] |
readSome(File path,
int limit)
Read at most limit bytes from the local file into memory as a byte array.
|
static ByteBuffer |
readWholeStream(InputStream in,
int sizeHint)
Read an entire input stream into memory as a ByteBuffer.
|
static void |
skipFully(InputStream fd,
long toSkip)
Skip an entire region of an input stream.
|
public static final byte[] readFully(File path) throws FileNotFoundException, IOException
path
- location of the file to read.FileNotFoundException
- the file does not exist.IOException
- the file exists, but its contents cannot be read.public static final byte[] readSome(File path, int limit) throws FileNotFoundException, IOException
path
- location of the file to read.limit
- maximum number of bytes to read, if the file is larger than
only the first limit number of bytes are returnedFileNotFoundException
- the file does not exist.IOException
- the file exists, but its contents cannot be read.public static final byte[] readFully(File path, int max) throws FileNotFoundException, IOException
path
- location of the file to read.max
- maximum number of bytes to read, if the file is larger than
this limit an IOException is thrown.FileNotFoundException
- the file does not exist.IOException
- the file exists, but its contents cannot be read.public static ByteBuffer readWholeStream(InputStream in, int sizeHint) throws IOException
in
- input stream to be read.sizeHint
- a hint on the approximate number of bytes contained in the
stream, used to allocate temporary buffers more efficientlyposition() == 0
and
limit()
equal to the actual length read. Callers may rely
on obtaining the underlying array for efficient data access. If
sizeHint
was too large, the array may be over-allocated,
resulting in limit() < array().length
.IOException
- there was an error reading from the stream.public static void readFully(InputStream fd, byte[] dst, int off, int len) throws IOException
fd
- input stream to read the data from.dst
- buffer that must be fully populated, [off, off+len).off
- position within the buffer to start writing to.len
- number of bytes that must be read.EOFException
- the stream ended before dst was fully populated.IOException
- there was an error reading from the stream.public static int read(ReadableByteChannel channel, byte[] dst, int off, int len) throws IOException
channel
- channel to read data from.dst
- buffer that must be fully populated, [off, off+len).off
- position within the buffer to start writing to.len
- number of bytes that should be read.IOException
- there was an error reading from the channel.public static int readFully(InputStream fd, byte[] dst, int off) throws IOException
fd
- input stream to read the data from.dst
- buffer that must be fully populated, [off, off+len).off
- position within the buffer to start writing to.IOException
- there was an error reading from the stream.public static void skipFully(InputStream fd, long toSkip) throws IOException
The input stream's position is moved forward by the number of requested bytes, discarding them from the input. This method does not return until the exact number of bytes requested has been skipped.
fd
- the stream to skip bytes from.toSkip
- total number of bytes to be discarded. Must be >= 0.EOFException
- the stream ended before the requested number of bytes were
skipped.IOException
- there was an error reading from the stream.public static List<String> readLines(String s)
s
- the string to readpublic static String readLine(Reader in, int sizeHint) throws IOException
Like BufferedReader.readLine()
, but only treats
\n
as end-of-line, and includes the trailing newline.
in
- the reader to read from.sizeHint
- hint for buffer sizing; 0 or negative for default.\n
unless
EOF was reached.IOException
- there was an error reading from the stream.Copyright © 2016 Eclipse JGit Project. All rights reserved.