List of utility methods to do File Read via ByteBuffer
String | read(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(); |
String | read(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()]; ... |
int | read(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) { ... |
ByteArrayOutputStream | read(InputStream stream) read ByteArrayOutputStream baos = new ByteArrayOutputStream(); fastCopy(stream, baos); return baos; |
String | read(Path file) read return utf8(readBytes(file));
|
MappedByteBuffer | read(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(); |
int | read24BitInteger(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); ... |
String | read_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()); ... |