Java Utililty Methods File Read via ByteBuffer

List of utility methods to do File Read via ByteBuffer

Description

The list of methods to do File Read via ByteBuffer are organized into topic(s).

Method

Stringread(File from)
read
final FileInputStream istream = new FileInputStream(from);
final FileChannel channel = istream.getChannel();
final StringWriter writer = new StringWriter();
final ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
int read = 0;
while ((read = channel.read(buffer)) > 0) {
    writer.append(new String(buffer.array(), 0, read));
return writer.getBuffer().toString();
Stringread(final File source)
read
final FileInputStream stream = new FileInputStream(source);
try {
    final FileChannel fc = stream.getChannel();
    final MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
    return Charset.defaultCharset().decode(bb).toString();
} finally {
    stream.close();
byte[]read(final FileChannel channel)
Reads all data from the given file channel.
final ByteBuffer buffer;
try {
    buffer = ByteBuffer.allocateDirect((int) channel.size());
    channel.read(buffer);
} finally {
    channel.close();
final byte[] result = new byte[buffer.flip().limit()];
...
intread(final Reader input, final char[] buffer, final int offset, final int length)
Reads characters from an input character stream.
if (length < 0) {
    throw new IllegalArgumentException("Length must not be negative: " + length);
int remaining = length;
while (remaining > 0) {
    final int location = length - remaining;
    final int count = input.read(buffer, offset + location, remaining);
    if (EOF == count) { 
...
ByteArrayOutputStreamread(InputStream stream)
read
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fastCopy(stream, baos);
return baos;
Stringread(Path file)
read
return utf8(readBytes(file));
MappedByteBufferread(Path file, int pos, int length)
read
return getFileChannel(file, "r").map(FileChannel.MapMode.READ_ONLY, pos, length);
char[]read(Reader reader)
read
CharArrayWriter writer = new CharArrayWriter();
transfer(reader, writer);
return writer.toCharArray();
intread24BitInteger(byte[] threeBytes, ByteOrder order)
read Bit Integer
ByteBuffer tmp = ByteBuffer.allocate(4);
tmp.order(order);
if (order == ByteOrder.BIG_ENDIAN) {
    tmp.put((byte) 0x00);
    tmp.put(threeBytes[0]);
    tmp.put(threeBytes[1]);
    tmp.put(threeBytes[2]);
    return tmp.getInt(0);
...
Stringread_file(File input)
reafile
log = "";
String output = "";
FileInputStream stream;
try {
    stream = new FileInputStream(input);
    try {
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
...