2013-07-03 02:52:38 +00:00
|
|
|
/* Copyright (c) 2008-2013, Avian Contributors
|
2008-02-19 18:06:52 +00: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-25 00:34:45 +00:00
|
|
|
package java.io;
|
|
|
|
|
|
|
|
public class PrintStream extends OutputStream {
|
|
|
|
private final OutputStream out;
|
|
|
|
private final boolean autoFlush;
|
|
|
|
|
2007-09-30 02:48:27 +00:00
|
|
|
private static class Static {
|
|
|
|
private static final byte[] newline
|
|
|
|
= System.getProperty("line.separator").getBytes();
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:34:45 +00:00
|
|
|
public PrintStream(OutputStream out, boolean autoFlush) {
|
|
|
|
this.out = out;
|
2007-07-29 23:32:23 +00:00
|
|
|
this.autoFlush = autoFlush;
|
2007-07-25 00:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public PrintStream(OutputStream out) {
|
|
|
|
this(out, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized void print(String s) {
|
|
|
|
try {
|
|
|
|
out.write(s.getBytes());
|
2010-09-05 15:07:18 +00:00
|
|
|
if (autoFlush) flush();
|
2007-07-25 00:34:45 +00:00
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:38:35 +00:00
|
|
|
public void print(Object o) {
|
2007-09-27 21:05:55 +00:00
|
|
|
print(String.valueOf(o));
|
2007-07-29 23:38:35 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 15:26:56 +00:00
|
|
|
public void print(boolean v) {
|
|
|
|
print(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:38:35 +00:00
|
|
|
public void print(char c) {
|
|
|
|
print(String.valueOf(c));
|
|
|
|
}
|
|
|
|
|
2011-01-20 15:26:56 +00: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));
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:34:45 +00:00
|
|
|
public synchronized void println(String s) {
|
|
|
|
try {
|
|
|
|
out.write(s.getBytes());
|
2007-09-30 02:48:27 +00:00
|
|
|
out.write(Static.newline);
|
2007-07-25 00:34:45 +00:00
|
|
|
if (autoFlush) flush();
|
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
2007-07-29 23:32:23 +00:00
|
|
|
|
|
|
|
public synchronized void println() {
|
|
|
|
try {
|
2007-09-30 02:48:27 +00:00
|
|
|
out.write(Static.newline);
|
2007-07-29 23:32:23 +00:00
|
|
|
if (autoFlush) flush();
|
|
|
|
} catch (IOException e) { }
|
|
|
|
}
|
2007-07-29 23:38:35 +00:00
|
|
|
|
|
|
|
public void println(Object o) {
|
2007-09-27 21:21:39 +00:00
|
|
|
println(String.valueOf(o));
|
2007-07-29 23:38:35 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 15:26:56 +00:00
|
|
|
public void println(boolean v) {
|
|
|
|
println(String.valueOf(v));
|
|
|
|
}
|
|
|
|
|
2007-07-29 23:38:35 +00:00
|
|
|
public void println(char c) {
|
|
|
|
println(String.valueOf(c));
|
|
|
|
}
|
2011-01-20 15:26:56 +00: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-25 00:34:45 +00: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 23:45:47 +00:00
|
|
|
public void flush() {
|
|
|
|
try {
|
|
|
|
out.flush();
|
|
|
|
} catch (IOException e) { }
|
2007-07-25 00:34:45 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
public void close() {
|
|
|
|
try {
|
|
|
|
out.close();
|
|
|
|
} catch (IOException e) { }
|
2007-07-25 00:34:45 +00:00
|
|
|
}
|
|
|
|
}
|