Package com.topjohnwu.superuser.io
Class SuRandomAccessFile
java.lang.Object
com.topjohnwu.superuser.io.SuRandomAccessFile
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
Access files using the main shell and mimics
RandomAccessFile
.
Usage of this class is not recommended. Each I/O operation comes with a large
overhead and depends on certain behavior of the command dd
.
Writing to files through shell commands is proven to be error prone.
YOU HAVE BEEN WARNED!
Please use SuFileInputStream
and SuFileOutputStream
whenever possible.
This class always checks whether using a shell is necessary. If not, it simply opens a new
RandomAccessFile
and behaves as a wrapper. This class has almost the exact same
methods as RandomAccessFile
and can be treated as a drop-in replacement.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract long
abstract long
length()
static SuRandomAccessFile
static SuRandomAccessFile
SuRandomAccessFile.open(new File(path), mode)
abstract int
read()
abstract int
read
(byte[] b) abstract int
read
(byte[] b, int off, int len) abstract void
seek
(long pos) abstract void
setLength
(long newLength) Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
Methods inherited from interface java.io.DataOutput
write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Constructor Details
-
SuRandomAccessFile
public SuRandomAccessFile()
-
-
Method Details
-
open
@NonNull public static SuRandomAccessFile open(@NonNull File file, String mode) throws FileNotFoundException - Parameters:
file
- the file object.mode
- the access mode. Note:rws
,rwd
behaves exactly the same asrw
if it end up using shell-backed implementation.- Returns:
- an instance of
SuRandomAccessFile
. - Throws:
FileNotFoundException
- See Also:
-
open
@NonNull public static SuRandomAccessFile open(@NonNull String path, String mode) throws FileNotFoundException SuRandomAccessFile.open(new File(path), mode)
- Throws:
FileNotFoundException
-
read
- Throws:
IOException
- See Also:
-
read
- Throws:
IOException
- See Also:
-
read
- Throws:
IOException
- See Also:
-
seek
- Throws:
IOException
- See Also:
-
setLength
- Throws:
IOException
- See Also:
-
length
- Throws:
IOException
- See Also:
-
getFilePointer
- Throws:
IOException
- See Also:
-