Package com.github.dagnelies.filemap
Class BufferedRandomAccessFile
- java.lang.Object
-
- java.io.InputStream
-
- com.github.dagnelies.filemap.BufferedRandomAccessFile
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BufferedRandomAccessFile extends InputStream
In core Java, you have the choice between: - RandomAccessFile: random access but slow (unbuffered) - BufferedInputStream/Reader: fast (buffered) but no random access Sadly, both are incompatible and there is no meaningful way to combine them. This is the reason of this BufferedRandomAccessFile. To provide random access along with fast read capabilities thanks to buffering.- Author:
- dagnelies
-
-
Constructor Summary
Constructors Constructor Description BufferedRandomAccessFile(File file, String mode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanisEOF()longlength()longpos()intread()intread(byte[] b, int off, int len)StringreadLine()Reads the next line, interpreted as UTF-8, excluding the newline character.byte[]readUntil(byte delimiter)voidseek(long pos)voidskipUntil(byte delimiter)Skip all bytes until delimiter(inclusive) is encountered.voidtruncate(long len)voidwrite(byte b)voidwrite(byte[] data)voidwrite(String str)-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
BufferedRandomAccessFile
public BufferedRandomAccessFile(File file, String mode) throws IOException
- Throws:
IOException
-
-
Method Detail
-
write
public void write(byte[] data) throws IOException- Throws:
IOException
-
write
public void write(String str) throws IOException
- Throws:
IOException
-
write
public void write(byte b) throws IOException- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
truncate
public void truncate(long len) throws IOException- Throws:
IOException
-
seek
public void seek(long pos) throws IOException- Throws:
IOException
-
pos
public long pos()
-
length
public long length()
-
isEOF
public boolean isEOF()
-
readUntil
public byte[] readUntil(byte delimiter) throws IOException- Throws:
IOException
-
skipUntil
public void skipUntil(byte delimiter) throws IOExceptionSkip all bytes until delimiter(inclusive) is encountered.- Parameters:
delimiter-- Throws:
IOException
-
readLine
public String readLine() throws IOException
Reads the next line, interpreted as UTF-8, excluding the newline character.- Throws:
IOException
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
-