Top Description Constructors Methods
org.eclipse.jgit.util

public Class IO

extends Object
Class Inheritance
Imports
java.io.EOFException, .File, .FileNotFoundException, .IOException, .InputStream, .Reader, java.nio.ByteBuffer, java.nio.channels.ReadableByteChannel, java.text.MessageFormat, java.util.ArrayList, .List, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.util.io.SilentFileInputStream

Input/Output utilities

Constructor Summary

AccessConstructor and Description
private
IO()

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

number of bytes actually read.
read
(ReadableByteChannel
channel to read data from.
channel
,
byte[]
buffer that must be fully populated, [off, off+len).
dst
,
int
position within the buffer to start writing to.
off
,
int
number of bytes that should be read.
len
)

Read as much of the array as possible from a channel.

public static final byte[]

Returns:

complete contents of the requested local file.
readFully
(File
location of the file to read.
path
)

Read an entire local file into memory as a byte array.

public static final byte[]

Returns:

complete contents of the requested local file.
readFully
(File
location of the file to read.
path
,
int
maximum number of bytes to read, if the file is larger than this limit an IOException is thrown.
max
)

Read an entire local file into memory as a byte array.

public static void
readFully(final InputStream
input stream to read the data from.
fd
,
final byte[]
buffer that must be fully populated, [off, off+len).
dst
,
int
position within the buffer to start writing to.
off
,
int
number of bytes that must be read.
len
)

Read the entire byte array into memory, or throw an exception.

public static void
readFully(InputStream
input stream to read the data from.
fd
,
byte[]
buffer that must be fully populated
dst
)

Read from input until the entire byte array filled, or throw an exception if stream ends first.

public static int

Returns:

number of bytes read
readFully
(InputStream
input stream to read the data from.
fd
,
byte[]
buffer that must be fully populated, [off, off+len).
dst
,
int
position within the buffer to start writing to.
off
)

Read the entire byte array into memory, unless input is shorter

public static String

Returns:

the next line from the input, always ending in \n unless EOF was reached.
readLine
(Reader
the reader to read from.
in
,
int
hint for buffer sizing; 0 or negative for default.
sizeHint
)

Read the next line from a reader.

public static List<String>

Returns:

the string divided into lines
readLines
(String
the string to read
s
)

Divides the given string into lines.

public static final byte[]

Returns:

complete contents of the requested local file. If the contents exceeds the limit, then only the limit is returned.
readSome
(File
location of the file to read.
path
,
int
maximum number of bytes to read, if the file is larger than only the first limit number of bytes are returned
limit
)

Read at most limit bytes from the local file into memory as a byte array.

public static ByteBuffer

Returns:

complete contents of the input stream. The ByteBuffer always has a writable backing array, with position() == 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.
readWholeStream
(InputStream
input stream to be read.
in
,
int
a hint on the approximate number of bytes contained in the stream, used to allocate temporary buffers more efficiently
sizeHint
)

Read an entire input stream into memory as a ByteBuffer.

private static void
resetAndSkipFully(Reader fd, long toSkip)

public static void
skipFully(InputStream
the stream to skip bytes from.
fd
,
long
total number of bytes to be discarded. Must be >= 0.
toSkip
)

Skip an entire region of an input stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IOback to summary
private IO()

Method Detail

readback to summary
public static int read(ReadableByteChannel channel, byte[] dst, int off, int len) throws IOException

Read as much of the array as possible from a channel.

Parameters
channel:ReadableByteChannel

channel to read data from.

dst:byte[]

buffer that must be fully populated, [off, off+len).

off:int

position within the buffer to start writing to.

len:int

number of bytes that should be read.

Returns:int

number of bytes actually read.

Exceptions
IOException:
there was an error reading from the channel.
readFullyback to summary
public static final byte[] readFully(File path) throws FileNotFoundException, IOException

Read an entire local file into memory as a byte array.

Parameters
path:File

location of the file to read.

Returns:byte[]

complete contents of the requested local file.

Exceptions
FileNotFoundException:
the file does not exist.
IOException:
the file exists, but its contents cannot be read.
readFullyback to summary
public static final byte[] readFully(File path, int max) throws FileNotFoundException, IOException

Read an entire local file into memory as a byte array.

Parameters
path:File

location of the file to read.

max:int

maximum number of bytes to read, if the file is larger than this limit an IOException is thrown.

Returns:byte[]

complete contents of the requested local file.

Exceptions
FileNotFoundException:
the file does not exist.
IOException:
the file exists, but its contents cannot be read.
readFullyback to summary
public static void readFully(final InputStream fd, final byte[] dst, int off, int len) throws IOException

Read the entire byte array into memory, or throw an exception.

Parameters
fd:InputStream

input stream to read the data from.

dst:byte[]

buffer that must be fully populated, [off, off+len).

off:int

position within the buffer to start writing to.

len:int

number of bytes that must be read.

Exceptions
IOException:
there was an error reading from the stream.
EOFException:
the stream ended before dst was fully populated.
readFullyback to summary
public static void readFully(InputStream fd, byte[] dst) throws IOException

Read from input until the entire byte array filled, or throw an exception if stream ends first.

Parameters
fd:InputStream

input stream to read the data from.

dst:byte[]

buffer that must be fully populated

Exceptions
IOException:
there was an error reading from the stream.
EOFException:
the stream ended before dst was fully populated.
Since
6.5
readFullyback to summary
public static int readFully(InputStream fd, byte[] dst, int off) throws IOException

Read the entire byte array into memory, unless input is shorter

Parameters
fd:InputStream

input stream to read the data from.

dst:byte[]

buffer that must be fully populated, [off, off+len).

off:int

position within the buffer to start writing to.

Returns:int

number of bytes read

Exceptions
IOException:
there was an error reading from the stream.
readLineback to summary
public static String readLine(Reader in, int sizeHint) throws IOException

Read the next line from a reader.

Like java.io.BufferedReader#readLine(), but only treats \n as end-of-line, and includes the trailing newline.

Parameters
in:Reader

the reader to read from.

sizeHint:int

hint for buffer sizing; 0 or negative for default.

Returns:String

the next line from the input, always ending in \n unless EOF was reached.

Exceptions
IOException:
there was an error reading from the stream.
Since
4.1
readLinesback to summary
public static List<String> readLines(String s)

Divides the given string into lines.

Parameters
s:String

the string to read

Returns:List<String>

the string divided into lines

Since
2.0
readSomeback to summary
public static final byte[] readSome(File path, int limit) throws FileNotFoundException, IOException

Read at most limit bytes from the local file into memory as a byte array.

Parameters
path:File

location of the file to read.

limit:int

maximum number of bytes to read, if the file is larger than only the first limit number of bytes are returned

Returns:byte[]

complete contents of the requested local file. If the contents exceeds the limit, then only the limit is returned.

Exceptions
FileNotFoundException:
the file does not exist.
IOException:
the file exists, but its contents cannot be read.
readWholeStreamback to summary
public static ByteBuffer readWholeStream(InputStream in, int sizeHint) throws IOException

Read an entire input stream into memory as a ByteBuffer.

Note

The stream is read to its end and is not usable after calling this method. The caller is responsible for closing the stream.

Parameters
in:InputStream

input stream to be read.

sizeHint:int

a hint on the approximate number of bytes contained in the stream, used to allocate temporary buffers more efficiently

Returns:ByteBuffer

complete contents of the input stream. The ByteBuffer always has a writable backing array, with position() == 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.

Exceptions
IOException:
there was an error reading from the stream.
resetAndSkipFullyback to summary
private static void resetAndSkipFully(Reader fd, long toSkip) throws IOException
skipFullyback to summary
public static void skipFully(InputStream fd, long toSkip) throws IOException

Skip an entire region of an input stream.

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.

Parameters
fd:InputStream

the stream to skip bytes from.

toSkip:long

total number of bytes to be discarded. Must be >= 0.

Exceptions
IOException:
there was an error reading from the stream.
EOFException:
the stream ended before the requested number of bytes were skipped.