public class LeolaFile extends Object
RandomAccessFile
Constructor and Description |
---|
LeolaFile(RandomAccessFile raf) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the this.
|
long |
length()
Returns the length of the file in bytes
|
long |
position()
The current file position pointer
|
int |
read() |
boolean |
readBoolean() |
int |
readBuffer(Buffer buffer)
Reads the contents of the file into the supplied
Buffer according to the
Buffer.position() and Buffer.limit() . |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
String |
readFully()
Read the full contents of the file and stores it in a
String . |
int |
readInt() |
String |
readLine()
Reads the next line of text from this file.
|
LeoArray |
readLines()
Reads all lines according to the same rules as
readLine() |
long |
readLong() |
short |
readShort() |
String |
readUTF()
Reads in a string from this file.
|
void |
seek(long pos)
Seeks into a this.
|
void |
setLength(int newLength)
Sets the new length of the this.
|
LeoObject |
with(LeoObject func)
Executes the supplied function and always closes the file afterwards (even if
an exception occurs).
|
void |
write(int b) |
void |
writeBoolean(boolean b) |
void |
writeBuffer(Buffer buffer)
Writes out bytes from the
Buffer |
void |
writeByte(byte b) |
void |
writeBytes(byte[] bytes)
Writes
b.length bytes from the specified byte array
to this file, starting at the current file pointer. |
void |
writeBytes(byte[] bytes,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to this file. |
void |
writeChar(char b) |
void |
writeDouble(double b) |
void |
writeFloat(float b) |
void |
writeInt(int b) |
void |
writeLine(String line)
Writes the string to the file as a sequence of bytes.
|
void |
writeLines(LeoArray array)
Write out each element in the supplied
LeoArray , each element is
treated as a string, after which a new line will be appended. |
void |
writeLong(long b) |
void |
writeShort(short b) |
void |
writeUTF(String line)
Writes a string to the file using
modified UTF-8
encoding in a machine-independent manner.
|
public LeolaFile(RandomAccessFile raf)
raf
- the RandomAccessFile
that has been openedruntime
- the Leola runtimepublic LeoObject with(LeoObject func) throws Exception
func
- Exception
public final int readBuffer(Buffer buffer) throws Exception
Buffer
according to the
Buffer.position()
and Buffer.limit()
.buffer
- Exception
public final String readUTF() throws Exception
The first two bytes are read, starting from the current file
pointer, as if by
readUnsignedShort
. This value gives the number of
following bytes that are in the encoded string, not
the length of the resulting string. The following bytes are then
interpreted as bytes encoding characters in the modified UTF-8 format
and are converted into characters.
This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.
EOFException
- if this file reaches the end before
reading all the bytes.IOException
- if an I/O error occurs.UTFDataFormatException
- if the bytes do not represent
valid modified UTF-8 encoding of a Unicode string.Exception
RandomAccessFile.readUnsignedShort()
public final String readLine() throws Exception
A line of text is terminated by a carriage-return character
('\r'
), a newline character ('\n'
), a
carriage-return character immediately followed by a newline character,
or the end of the file. Line-terminating characters are discarded and
are not included as part of the string returned.
This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the file is reached, or an exception is thrown.
IOException
- if an I/O error occurs.Exception
public final String readFully() throws Exception
String
. Users
of this must be aware of memory consumption, as this will put the full file
into VM memory.public final LeoArray readLines() throws Exception
readLine()
Exception
public final void writeBuffer(Buffer buffer) throws Exception
Buffer
buffer
- Exception
public final void writeUTF(String line) throws Exception
First, two bytes are written to the file, starting at the
current file pointer, as if by the
writeShort
method giving the number of bytes to
follow. This value is the number of bytes actually written out,
not the length of the string. Following the length, each character
of the string is output, in sequence, using the modified UTF-8 encoding
for each character.
line
- a string to be written.IOException
- if an I/O error occurs.Exception
public final void writeLine(String line) throws Exception
line
- a string of bytes to be written.IOException
- if an I/O error occurs.Exception
public final void writeBytes(byte[] bytes, int off, int len) throws Exception
len
bytes from the specified byte array
starting at offset off
to this file.bytes
- the data.off
- the start offset in the data.len
- the number of bytes to write.IOException
- if an I/O error occurs.Exception
public final void writeBytes(byte[] bytes) throws Exception
b.length
bytes from the specified byte array
to this file, starting at the current file pointer.bytes
- the data.IOException
- if an I/O error occurs.Exception
public final void writeLines(LeoArray array) throws Exception
LeoArray
, each element is
treated as a string, after which a new line will be appended.
file.writeLines( [ "a", "b", "c" ] ) // writes: // a // b // c
array
- Exception
public final void seek(long pos) throws Exception
pos
- the position in number of bytesException
public final long position() throws Exception
Exception
seek(long)
public final long length() throws Exception
Exception
Copyright © 2010–2015. All rights reserved.