2015-03-13 12:52:59 -06:00
|
|
|
/* Copyright (c) 2008-2015, Avian Contributors
|
2008-02-19 11:06:52 -07:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-24 18:34:45 -06:00
|
|
|
package java.io;
|
|
|
|
|
|
|
|
public class PrintStream extends OutputStream {
|
|
|
|
private final OutputStream out;
|
|
|
|
private final boolean autoFlush;
|
|
|
|
|
2007-09-29 20:48:27 -06:00
|
|
|
private static class Static {
|
|
|
|
private static final byte[] newline
|
|
|
|
= System.getProperty("line.separator").getBytes();
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:34:45 -06:00
|
|
|
public PrintStream(OutputStream out, boolean autoFlush) {
|
|
|
|
this.out = out;
|
2007-07-29 17:32:23 -06:00
|
|
|
this.autoFlush = autoFlush;
|
2007-07-24 18:34:45 -06:00
|
|
|
}
|
|
|
|
|
2014-05-09 16:38:33 -06:00
|
|
|
public PrintStream(OutputStream out, boolean autoFlush, String encoding)
|
|
|
|
throws UnsupportedEncodingException
|
|
|
|
{
|
|
|
|
this.out = out;
|
|
|
|
this.autoFlush = autoFlush;
|
|
|
|
|
|
|
|
if (! (encoding.equals("UTF-8") || encoding.equals("ISO-8859-1"))) {
|
|
|
|
throw new UnsupportedEncodingException(encoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:34:45 -06:00
|
|
|
public PrintStream(OutputStream out) {
|
|
|
|
this(out, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void print(String s) {
|
|
|
|
try {
|
|
|
|
out.write(s.getBytes());
|
2010-09-05 09:07:18 -06:00
|
|
|
if (autoFlush) flush();
|
2007-07-24 18:34:45 -06:00
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
|
|
|
|
2007-07-29 17:38:35 -06:00
|
|
|
public void print(Object o) {
|
2007-09-27 15:05:55 -06:00
|
|
|
print(String.valueOf(o));
|
2007-07-29 17:38:35 -06:00
|
|
|
}
|
|
|
|
|
2011-01-20 08:26:56 -07:00
|
|
|
public void print(boolean v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
2007-07-29 17:38:35 -06:00
|
|
|
public void print(char c) {
|
|
|
|
print(String.valueOf(c));
|
|
|
|
}
|
|
|
|
|
2011-01-20 08:26:56 -07:00
|
|
|
public void print(int v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void print(long v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void print(float v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void print(double v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void print(char[] s) {
|
|
|
|
print(String.valueOf(s));
|
|
|
|
}
|
|
|
|
|
2015-03-15 00:28:45 -04:00
|
|
|
public synchronized void printf(java.util.Locale locale, String format, Object... args) {
|
|
|
|
// should this be cached in an instance variable??
|
|
|
|
final java.util.Formatter formatter = new java.util.Formatter(this);
|
|
|
|
formatter.format(locale, format, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void printf(String format, Object... args) {
|
|
|
|
final java.util.Formatter formatter = new java.util.Formatter(this);
|
|
|
|
formatter.format(format, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void format(String format, Object... args) {
|
|
|
|
printf(format, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void format(java.util.Locale locale, String format, Object... args) {
|
|
|
|
printf(locale, format, args);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:34:45 -06:00
|
|
|
public synchronized void println(String s) {
|
|
|
|
try {
|
|
|
|
out.write(s.getBytes());
|
2007-09-29 20:48:27 -06:00
|
|
|
out.write(Static.newline);
|
2007-07-24 18:34:45 -06:00
|
|
|
if (autoFlush) flush();
|
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
2007-07-29 17:32:23 -06:00
|
|
|
|
|
|
|
public synchronized void println() {
|
|
|
|
try {
|
2007-09-29 20:48:27 -06:00
|
|
|
out.write(Static.newline);
|
2007-07-29 17:32:23 -06:00
|
|
|
if (autoFlush) flush();
|
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
2007-07-29 17:38:35 -06:00
|
|
|
|
|
|
|
public void println(Object o) {
|
2007-09-27 15:21:39 -06:00
|
|
|
println(String.valueOf(o));
|
2007-07-29 17:38:35 -06:00
|
|
|
}
|
|
|
|
|
2011-01-20 08:26:56 -07:00
|
|
|
public void println(boolean v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
2007-07-29 17:38:35 -06:00
|
|
|
public void println(char c) {
|
|
|
|
println(String.valueOf(c));
|
|
|
|
}
|
2011-01-20 08:26:56 -07:00
|
|
|
|
|
|
|
public void println(int v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void println(long v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void println(float v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void println(double v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void println(char[] s) {
|
|
|
|
println(String.valueOf(s));
|
|
|
|
}
|
2007-07-24 18:34:45 -06:00
|
|
|
|
|
|
|
public void write(int c) throws IOException {
|
|
|
|
out.write(c);
|
|
|
|
if (autoFlush && c == '\n') flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(byte[] buffer, int offset, int length) throws IOException {
|
|
|
|
out.write(buffer, offset, length);
|
|
|
|
if (autoFlush) flush();
|
|
|
|
}
|
|
|
|
|
2007-08-10 17:45:47 -06:00
|
|
|
public void flush() {
|
|
|
|
try {
|
|
|
|
out.flush();
|
|
|
|
} catch (IOException e) { }
|
2007-07-24 18:34:45 -06:00
|
|
|
}
|
|
|
|
|
2007-08-10 17:45:47 -06:00
|
|
|
public void close() {
|
|
|
|
try {
|
|
|
|
out.close();
|
|
|
|
} catch (IOException e) { }
|
2007-07-24 18:34:45 -06:00
|
|
|
}
|
|
|
|
}
|