RandomAccessFile abstract class
RandomAccessFile provides random access to the data in a
file. RandomAccessFile objects are obtained by calling the
open method on a File object.
abstract class RandomAccessFile {
/**
* Closes the file. Returns a [:Future<RandomAccessFile>:] that
* completes with this RandomAccessFile when it has been closed.
*/
Future<RandomAccessFile> close();
/**
* Synchronously closes the file.
*
* Throws a [FileIOException] if the operation fails.
*/
void closeSync();
/**
* Reads a byte from the file. Returns a [:Future<int>:] that
* completes with the byte, or with -1 if end-of-file has been reached.
*/
Future<int> readByte();
/**
* Synchronously reads a single byte from the file. If end-of-file
* has been reached -1 is returned.
*
* Throws a [FileIOException] if the operation fails.
*/
int readByteSync();
/**
* Reads [bytes] bytes from a file and returns the result as a list of bytes.
*/
Future<List<int>> read(int bytes);
/**
* Synchronously reads a maximum of [bytes] bytes from a file and
* returns the result in a list of bytes.
*
* Throws a [FileIOException] if the operation fails.
*/
List<int> readSync(int bytes);
/**
* Reads into an existing List<int> from the file. If [start] is present, the
* bytes will be filled into [buffer] from at index [start], otherwise index
* 0. If [end] is present, the [end] - [start] bytes will be read into
* [buffer], otherwise up to [buffer.length]. If [end] == [start] nothing
* happends.
*
* Returns a [:Future<int>:] that completes with the number of bytes read.
*/
Future<int> readInto(List<int> buffer, [int start, int end]);
/**
* Synchronously reads into an existing List<int> from the file. If [start] is
* present, the bytes will be filled into [buffer] from at index [start],
* otherwise index 0. If [end] is present, the [end] - [start] bytes will be
* read into [buffer], otherwise up to [buffer.length]. If [end] == [start]
* nothing happends.
*
* Throws a [FileIOException] if the operation fails.
*/
int readIntoSync(List<int> buffer, [int start, int end]);
/**
* Writes a single byte to the file. Returns a
* [:Future<RandomAccessFile>:] that completes with this
* RandomAccessFile when the write completes.
*/
Future<RandomAccessFile> writeByte(int value);
/**
* Synchronously writes a single byte to the file. Returns the
* number of bytes successfully written.
*
* Throws a [FileIOException] if the operation fails.
*/
int writeByteSync(int value);
/**
* Writes from a [List<int>] to the file. It will read the buffer from index
* [start] to index [end]. If [start] is omitted, it'll start from index 0.
* If [end] is omitted, it will write to end of [buffer].
*
* Returns a [:Future<RandomAccessFile>:] that completes with this
* [RandomAccessFile] when the write completes.
*/
Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]);
/**
* Synchronously writes from a [List<int>] to the file. It will read the
* buffer from index [start] to index [end]. If [start] is omitted, it'll
* start from index 0. If [end] is omitted, it will write to the end of
* [buffer].
*
* Throws a [FileIOException] if the operation fails.
*/
void writeFromSync(List<int> buffer, [int start, int end]);
/**
* Writes a string to the file using the given [Encoding]. Returns a
* [:Future<RandomAccessFile>:] that completes with this
* RandomAccessFile when the write completes.
*/
Future<RandomAccessFile> writeString(String string,
{Encoding encoding: Encoding.UTF_8});
/**
* Synchronously writes a single string to the file using the given
* [Encoding].
*
* Throws a [FileIOException] if the operation fails.
*/
void writeStringSync(String string,
{Encoding encoding: Encoding.UTF_8});
/**
* Gets the current byte position in the file. Returns a
* [:Future<int>:] that completes with the position.
*/
Future<int> position();
/**
* Synchronously gets the current byte position in the file.
*
* Throws a [FileIOException] if the operation fails.
*/
int positionSync();
/**
* Sets the byte position in the file. Returns a
* [:Future<RandomAccessFile>:] that completes with this
* RandomAccessFile when the position has been set.
*/
Future<RandomAccessFile> setPosition(int position);
/**
* Synchronously sets the byte position in the file.
*
* Throws a [FileIOException] if the operation fails.
*/
void setPositionSync(int position);
/**
* Truncates (or extends) the file to [length] bytes. Returns a
* [:Future<RandomAccessFile>:] that completes with this
* RandomAccessFile when the truncation has been performed.
*/
Future<RandomAccessFile> truncate(int length);
/**
* Synchronously truncates (or extends) the file to [length] bytes.
*
* Throws a [FileIOException] if the operation fails.
*/
void truncateSync(int length);
/**
* Gets the length of the file. Returns a [:Future<int>:] that
* completes with the length in bytes.
*/
Future<int> length();
/**
* Synchronously gets the length of the file.
*
* Throws a [FileIOException] if the operation fails.
*/
int lengthSync();
/**
* Flushes the contents of the file to disk. Returns a
* [:Future<RandomAccessFile>:] that completes with this
* RandomAccessFile when the flush operation completes.
*/
Future<RandomAccessFile> flush();
/**
* Synchronously flushes the contents of the file to disk.
*
* Throws a [FileIOException] if the operation fails.
*/
void flushSync();
/**
* Returns a human-readable string for this RandomAccessFile instance.
*/
String toString();
/**
* Gets the path of the file underlying this RandomAccessFile.
*/
String get path;
}
Properties
Methods
abstract Future<RandomAccessFile> close() #
Closes the file. Returns a Future<RandomAccessFile> that
completes with this RandomAccessFile when it has been closed.
abstract void closeSync() #
Synchronously closes the file.
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> flush() #
Flushes the contents of the file to disk. Returns a
Future<RandomAccessFile> that completes with this
RandomAccessFile when the flush operation completes.
abstract void flushSync() #
Synchronously flushes the contents of the file to disk.
Throws a FileIOException if the operation fails.
abstract Future<int> length() #
Gets the length of the file. Returns a Future<int> that
completes with the length in bytes.
abstract int lengthSync() #
Synchronously gets the length of the file.
Throws a FileIOException if the operation fails.
abstract Future<int> position() #
Gets the current byte position in the file. Returns a
Future<int> that completes with the position.
abstract int positionSync() #
Synchronously gets the current byte position in the file.
Throws a FileIOException if the operation fails.
abstract Future<List<int>> read(int bytes) #
Reads bytes bytes from a file and returns the result as a list of bytes.
abstract Future<int> readByte() #
Reads a byte from the file. Returns a Future<int> that
completes with the byte, or with -1 if end-of-file has been reached.
abstract int readByteSync() #
Synchronously reads a single byte from the file. If end-of-file has been reached -1 is returned.
Throws a FileIOException if the operation fails.
abstract Future<int> readInto(List<int> buffer, [int start, int end]) #
Reads into an existing List<int> from the file. If
start is present, the
bytes will be filled into
buffer from at index
start, otherwise index
0. If
end is present, the
end -
start bytes will be read into
buffer, otherwise up to buffer.length. If
end ==
start nothing
happends.
Returns a Future<int> that completes with the number of bytes read.
abstract int readIntoSync(List<int> buffer, [int start, int end]) #
Synchronously reads into an existing List<int> from the file. If
start is
present, the bytes will be filled into
buffer from at index
start,
otherwise index 0. If
end is present, the
end -
start bytes will be
read into
buffer, otherwise up to buffer.length. If
end ==
start
nothing happends.
Throws a FileIOException if the operation fails.
abstract List<int> readSync(int bytes) #
Synchronously reads a maximum of bytes bytes from a file and returns the result in a list of bytes.
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> setPosition(int position) #
Sets the byte position in the file. Returns a
Future<RandomAccessFile> that completes with this
RandomAccessFile when the position has been set.
abstract void setPositionSync(int position) #
Synchronously sets the byte position in the file.
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> truncate(int length) #
Truncates (or extends) the file to
length bytes. Returns a
Future<RandomAccessFile> that completes with this
RandomAccessFile when the truncation has been performed.
abstract void truncateSync(int length) #
Synchronously truncates (or extends) the file to length bytes.
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> writeByte(int value) #
Writes a single byte to the file. Returns a
Future<RandomAccessFile> that completes with this
RandomAccessFile when the write completes.
abstract int writeByteSync(int value) #
Synchronously writes a single byte to the file. Returns the number of bytes successfully written.
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]) #
Writes from a [List
Returns a Future<RandomAccessFile> that completes with this
RandomAccessFile when the write completes.
abstract void writeFromSync(List<int> buffer, [int start, int end]) #
Synchronously writes from a [List
Throws a FileIOException if the operation fails.
abstract Future<RandomAccessFile> writeString(String string, {Encoding encoding: Encoding.UTF_8}) #
Writes a string to the file using the given Encoding. Returns a
Future<RandomAccessFile> that completes with this
RandomAccessFile when the write completes.
abstract void writeStringSync(String string, {Encoding encoding: Encoding.UTF_8}) #
Synchronously writes a single string to the file using the given Encoding.
Throws a FileIOException if the operation fails.