public class FileAppend
extends java.lang.Object
implements java.lang.Appendable, java.io.Closeable, java.io.Flushable
append(CharSequence)
is exception-free similar as in System.out
( PrintStream
).
Advantage for the user: exchange both without effort of try-catch.
open(String, boolean)
and open(String, String, boolean)
a path with environment variables
or starting with "/tmp/" or "~" can be used.
Modifier and Type | Class and Description |
---|---|
static class |
FileAppend.Wr |
Modifier and Type | Field and Description |
---|---|
private int |
error |
static int |
kFileNotFound |
static int |
kFileOpenError |
static int |
kWriteError |
java.lang.String |
sError |
static java.lang.String |
sVersion
Version, history and license.
|
protected FileAppend.Wr |
writer
The OutputStreamWriter can't be used as superclass, because the file is able to open
only with calling constructor.
|
Constructor and Description |
---|
FileAppend() |
Modifier and Type | Method and Description |
---|---|
java.lang.Appendable |
append(char c) |
FileAppend.Wr |
append(java.lang.CharSequence text)
In opposite to the original
Writer.append(CharSequence)
this operation does not throw. |
java.lang.Appendable |
append(java.lang.CharSequence csq,
int start,
int end) |
void |
close() |
void |
finalize()
Important: On garbage at least close() is called here to prevent resource leaks.
|
void |
flush() |
int |
getError() |
boolean |
isOpen() |
int |
open(java.lang.String filePath,
boolean append)
opens a file to write.
|
int |
open(java.lang.String fileName,
java.lang.String sEncoding,
boolean append)
opens a file to write.
|
void |
write(java.lang.String text) |
public static final java.lang.String sVersion
open(String, String, boolean)
with specific encoding.
protected FileAppend.Wr writer
public static final int kFileNotFound
public static final int kFileOpenError
public static final int kWriteError
public java.lang.String sError
private int error
public int open(java.lang.String filePath, boolean append)
close()
on end of usage.filePath
- Path to the file. To separate folder, a slash '/' should be used.
But a backslash is also accepted.
An absolute path should be start either with slash
or with a one-char drive specifier, following by ':/'.
The filePath can also contain environment variables due to Arguments.replaceEnv(String)
.
and also can start with /tmp/ or ~ for home, see FileFunctions.absolutePath(String, java.io.File)
.append
- If the file exists, the content written than is appended.public int open(java.lang.String fileName, java.lang.String sEncoding, boolean append)
close()
on end of usage.filePath
- Path to the file. To separate folder, a slash '/' should be used.
But a backslash is also accepted.
An absolute path should be start either with slash
or with a one-char drive specifier, following by ':/'.
The filePath can also contain environment variables due to Arguments.replaceEnv(String)
and also can start with /tmp/ or ~ for home, see FileFunctions.absolutePath(String, java.io.File)
.sEncoding
- character encoding for the binary file, "UTF-8" etc.
see OutputStreamWriter.OutputStreamWriter(java.io.OutputStream, String)
append
- If the file exists, the content written than is appended.public boolean isOpen()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public void write(java.lang.String text) throws java.io.IOException
java.io.IOException
public FileAppend.Wr append(java.lang.CharSequence text)
Writer.append(CharSequence)
this operation does not throw. Instead it does nothing on error,
but the internal error
is set to -3, returned by getError()
.
The original throw is catched here.
It is similar System.out.append(), the user does not need additional try,
An error is able to check for the whole output.append
in interface java.lang.Appendable
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
java.io.IOException
public void finalize()
finalize
in class java.lang.Object
public int getError()
public java.lang.Appendable append(java.lang.CharSequence csq, int start, int end) throws java.io.IOException
append
in interface java.lang.Appendable
java.io.IOException
public java.lang.Appendable append(char c) throws java.io.IOException
append
in interface java.lang.Appendable
java.io.IOException