@MinDoc(copyright="Copyright 2001, 2009, 2014 A. Weinert", author="Albrecht Weinert", version="V.44", lastModified="6.05.2021", usage="use instead of own normal I/O plumbing", purpose="the I/O base for java applications") public final class AppIO extends Object
out
) for normal output,err
) for error messageslog
) with optional branching to
normal output and to a file,in
) for normal input,System
.out, .err and .in) and graphic / file
encoding. These differences usually occur with Windows'
shell.TeeWriter
s are utilised in the following way:App
get these functions automatically by
an associated AppIO
(and anAppBase
) object.Modifier and Type | Field and Description |
---|---|
protected String |
codePage
Code-Page for Reader in and the Writer out and err.
|
protected String |
cp2
The TeeWriter's log encoding for its second output stream.
|
PrintWriter |
err
The error output as PrintWriter.
|
TeeWriter |
errTW
The TeeWriter for err.
|
protected OutputStreamWriter |
esw
The OutputStreamWriter decorating System.err .
|
BufferedReader |
in
The normal input as BufferedReader.
|
protected InputStreamReader |
isr
The InputStreamReader underlying the SwitchedReader swr.
|
PrintWriter |
log
A log output as PrintWriter.
|
protected String |
logDat
The name of a log file (if given / used).
|
protected File |
logFile
The log file (if given / used).
|
TeeWriter |
logTW
The TeeWriter connected to the PrintWriter log .
|
protected OutputStreamWriter |
osw
The OutputStreamWriter decorating System.out .
|
PrintWriter |
out
The standard output as PrintWriter.
|
protected String |
outDat
The name of a out file (if given / used).
|
protected File |
outFile
The out file (if given / used).
|
TeeWriter |
outTW
The TeeWriter for out.
|
protected SwitchedReader |
swr
The SwitchedReader underlying the BufferedReader in.
|
Modifier and Type | Method and Description |
---|---|
void |
closeLogHandler()
Closing the Logger handler.
|
int |
connect(OutMode outMode,
PropMap prop,
boolean askGraf)
Connect the TeeWriter's outputs for log and out by a PropMap.
|
static AppIO |
get()
Make with default settings.
|
static AppIO |
get(int outBuffLen,
int logBuffLen,
Object consEncoding)
Make with settings.
|
Logger |
getAppLogger()
Base logger for the applications.
|
String |
getCodePage()
Code-Page for Reader in and the Writer out and err.
|
String |
getLogDat()
The name of a log file (if given / used).
|
File |
getLogFile()
The log file (if given / used).
|
LogWriterHandler |
getLogHandler()
The Logger handler.
|
String |
getOutDat()
The name of a out file (if given / used).
|
File |
getOutFile()
The out file (if given / used).
|
void |
set(PropMap prop)
Set some properties by a PropMap object.
|
boolean |
setCodePages(CharSequence codePage)
Set code-Page for Reader in and the Writer out and err.
|
boolean |
setErrCodePage(CharSequence codePage)
Set PrintWriter err's code page (character encoding).
|
boolean |
setInCodePage(CharSequence codePage)
Set BufferedReader in's code page (character encoding).
|
boolean |
setLogDat(String name,
String encoding,
OutMode outMode,
boolean logOnLog)
Setting a file for the log output.
|
void |
setLogOut2(OutputStream os2,
String cp2)
Set log's second writer as stream.
|
void |
setLogOut2(Writer wr2)
Set log's second writer as writer.
|
boolean |
setOutCodePage(CharSequence codePage)
Set normal out's code page (character encoding).
|
boolean |
setOutDat(String name,
String encoding,
OutMode outMode,
boolean logOnLog)
Setting the file fort the output out.
|
PrintWriter |
toOutln(CharSequence s)
Output only a not empty String as line.
|
public final BufferedReader in
System.in
,
which delivers it to via isr
.IOException
s,
which System.in
avoids. readline()
as EoF
(End of File). setInCodePage(String)
,
out
,
err
,
log
,
FilterReader
protected final SwitchedReader swr
in
.setInCodePage(String)
protected InputStreamReader isr
CONSOL_ENCODING
.setInCodePage(String)
public final PrintWriter err
System.err
, which it is connected to by esw
and
errTW
.setErrCodePage(String)
,
out
,
in
,
log
public final TeeWriter errTW
protected volatile OutputStreamWriter esw
CONSOL_ENCODING
.setErrCodePage()
public final PrintWriter out
System.out
, which it is connected to by osw
and
outTW
.setOutCodePage()
,
in
,
err
,
log
protected volatile OutputStreamWriter osw
CONSOL_ENCODING
.setOutCodePage()
public final TeeWriter outTW
public final PrintWriter log
TeeWriter
logTW
the (normal)
output outTW
and optionally a (log) file.setLogOut2()
to set the second output to whatever (usually a file).public final TeeWriter logTW
protected String cp2
protected volatile String logDat
protected volatile File logFile
protected volatile String outDat
out
instead of them
going to System.out .protected volatile File outFile
protected volatile String codePage
getCodePage()
public final LogWriterHandler getLogHandler()
public final void closeLogHandler()
LogWriterHandler
made by
getLogHandler()
, it will be closed, opted out (if known to it)
from an appLogger
and cleared away.public final Logger getAppLogger()
AppIO
object. The Logger
will be made on the first
call.Logger
's name will be "de.frame4j"Handler
available by
getLogHandler()
, and hence a LogTextFormatter
object for
output to log
.Level
set will be t
INFO
. If this Logger
should
have been indirectly via
App
.getAppLogger()
the
Level
will be set automatically according
to App
.verbosity
. The same applies for
logHandler
.Logger
is the last one in a handler chain; that means it will
not delegate further to a Java-Logging-API made default Logger, like
ConsoleHandler
. This would counteract all
Frame4J's respectively AppIO
's or App
's I/O
organisation.public final String getLogDat()
public File getLogFile()
public boolean setLogDat(String name, String encoding, OutMode outMode, boolean logOnLog)
name
- the file name; null or "null" just means close the
actual file.encoding
- character encoding; null or "defaultEncoding"
or non implemented ones mean default (system file) encoding.outMode
- Ask, Append, Overwrite or CreatelogOnLog
- true means do report success or failure on log
public final String getOutDat()
out
instead of them
going to System.out .public File getOutFile()
public boolean setOutDat(String name, String encoding, OutMode outMode, boolean logOnLog)
name
- the file name; null or "null" just means close the
actual file.encoding
- character encoding; null or "defaultEncoding"
or non implemented ones mean default (system file) encoding.outMode
- Ask, Append, Overwrite or CreatelogOnLog
- true means do report success or failure on log
public void set(PropMap prop)
public static AppIO get(int outBuffLen, int logBuffLen, Object consEncoding)
TeeWriter
s logTW
and outTW
as well as the
console I/O's encoding.outTW
's output 2 remains unconnected as well as
errTW
's output 1.outBuffLen
- buffer size out TeeWriter,
1024 to 400000 character, default 20KlogBuffLen
- buffer size log TeeWriter,
1024 to 400000 character, default 10KconsEncoding
- null: CONSOL_ENCODING
;public static AppIO get()
CONSOL_ENCODING
is used
and the platforms default file encoding for all else.public void setLogOut2(OutputStream os2, String cp2)
os2
will be decorated by a Writer and set as log
's
second output.logTW
's out1.os2
- The stream to connect tocp2
- The encoding to use; null will be
CONSOL_ENCODING
public void setLogOut2(Writer wr2)
wr2
will be set as log
's second output.logTW
's out1.wr2
- the Writer to connect topublic boolean setOutCodePage(CharSequence codePage)
outTW
encoding for branch normal output will be
changed.codePage
is empty
CONSOL_ENCODING
is used.codePage
- encoding to setpublic boolean setErrCodePage(CharSequence codePage)
errTW
encoding for branch normal output will be
changed.codePage
is empty
CONSOL_ENCODING
is used.codePage
- encoding to setpublic boolean setInCodePage(CharSequence codePage)
in
(normal input) encoding will be changed.codePage
is empty
CONSOL_ENCODING
is used.codePage
- encoding to setpublic String getCodePage()
setCodePages(CharSequence)
the setting is provided
here for reference. null means no such or failed setting attempt.public boolean setCodePages(CharSequence codePage)
codePage
is empty
CONSOL_ENCODING
is used.codePage
- encoding to setsetOutCodePage()
,
setErrCodePage()
,
setInCodePage()
public PrintWriter toOutln(CharSequence s)
out
.println(), if and only if
if is not empty.public int connect(OutMode outMode, PropMap prop, boolean askGraf)
TeeWriter
s
logTW
respectively outTW
using the appropriate
connect..() methods.prop
serves to set the properties of the graphical "file ask window"
if that could be needed (askGraf true) (see
FileVisitor.AskGrafImpl
).prop
- must not be nulloutMode
- null acts like OutMode.ASK