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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longabstract longlength()static SuRandomAccessFilestatic SuRandomAccessFileSuRandomAccessFile.open(new File(path), mode)abstract intread()abstract intread(byte[] b) abstract intread(byte[] b, int off, int len) abstract voidseek(long pos) abstract voidsetLength(long newLength) Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytesMethods 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,rwdbehaves exactly the same asrwif 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:
-