| Modifier and Type | Class and Description |
|---|---|
static class |
RubyIO.Mode
This Mode enum contains all open modes of
RubyIO.r : Read. r+ : Read and Write. w : Write. w+ : Write and Read. a : Append. a+ : Append and Read. |
| Modifier and Type | Field and Description |
|---|---|
protected java.io.File |
file |
protected RubyIO.Mode |
mode |
protected java.io.RandomAccessFile |
raFile |
| Constructor and Description |
|---|
RubyIO(java.io.File file,
RubyIO.Mode mode)
Creates a
RubyIO by given File and Mode. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this IO.
|
RubyEnumerator<java.lang.String> |
eachLine()
Returns a
RubyEnumerator of lines in the file. |
static RubyEnumerator<java.lang.String> |
foreach(java.lang.String path)
Returns a
RubyEnumerator of lines in given file. |
static void |
foreach(java.lang.String path,
Block<java.lang.String> block)
Iterates a file line by line.
|
static RubyIO |
open(java.lang.String path)
Creates a
RubyIO by given file. |
static RubyIO |
open(java.lang.String path,
java.lang.String mode)
Creates a
RubyIO by given path and mode. |
void |
puts(java.lang.String words)
Writes a line in the file.
|
java.lang.String |
read()
Reads the content of a file.
|
void |
seek(long pos)
Moves the cursor to certain position.
|
java.lang.String |
toString() |
int |
write(java.lang.String words)
Writes to the file.
|
protected final java.io.File file
protected final java.io.RandomAccessFile raFile
protected final RubyIO.Mode mode
public RubyIO(java.io.File file,
RubyIO.Mode mode)
throws java.io.IOException
RubyIO by given File and Mode.file - a Filemode - a Modejava.lang.NullPointerException - if file is nulljava.io.IOException - if file can't not openRubyIO.Modepublic static RubyIO open(java.lang.String path, java.lang.String mode)
RubyIO by given path and mode.path - of a Filemode - r, rw, w, w+, a, a+RubyIORubyIO.Modepublic static RubyIO open(java.lang.String path)
RubyIO by given file. Sets the mode to read-only.path - of a fileRubyIOpublic static RubyEnumerator<java.lang.String> foreach(java.lang.String path)
RubyEnumerator of lines in given file.path - of a FileRubyEnumeratorpublic static void foreach(java.lang.String path,
Block<java.lang.String> block)
path - of a Fileblock - to process each linepublic void close()
public RubyEnumerator<java.lang.String> eachLine()
RubyEnumerator of lines in the file.RubyEnumeratorjava.lang.IllegalStateException - if file is not readablepublic void puts(java.lang.String words)
words - to write a linejava.lang.IllegalStateException - if file is not writablepublic java.lang.String read()
java.lang.IllegalStateException - if file is not readablepublic void seek(long pos)
pos - position of the filepublic int write(java.lang.String words)
words - to writejava.lang.IllegalStateException - if file is not writablepublic java.lang.String toString()
toString in class java.lang.Object