1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.runtime
.cldc
.io
;
12 import java
.io
.Closeable
;
13 import java
.io
.IOException
;
14 import java
.io
.PrintStream
;
15 import java
.io
.Writer
;
18 * This is a class which takes input characters and writes to the given
21 * This class is thread safe.
25 public class PrintStreamWriter
29 /** The stream to write to. */
30 protected final PrintStream output
;
33 * Initializes the wrapped print stream writer.
35 * @param __ps The stream to write to.
36 * @throws NullPointerException On null arguments.
39 public PrintStreamWriter(PrintStream __ps
)
40 throws NullPointerException
44 throw new NullPointerException("NARG");
51 * Initializes the wrapped print stream writer and using the given lock.
53 * @param __lock The lock to use.
54 * @param __ps The stream to write to.
55 * @throws NullPointerException On null arguments.
58 public PrintStreamWriter(Object __lock
, PrintStream __ps
)
59 throws NullPointerException
65 throw new NullPointerException("NARG");
80 PrintStream output
= this.output
;
81 synchronized (this.lock
)
97 PrintStream output
= this.output
;
98 synchronized (this.lock
)
110 public void write(int __c
)
114 PrintStream output
= this.output
;
115 synchronized (this.lock
)
117 output
.print((char)__c
);
130 public void write(char[] __c
, int __o
, int __l
)
131 throws IndexOutOfBoundsException
, IOException
, NullPointerException
135 throw new NullPointerException("NARG");
138 if (__o
< 0 || __l
< 0 || end
> n
)
139 throw new IndexOutOfBoundsException("IOOB");
142 PrintStream output
= this.output
;
143 synchronized (this.lock
)
146 for (int i
= __o
; i
< end
; i
++)
147 output
.print((char)__c
[i
]);
155 * Checks if the given stream has reported an error.
157 * @throws IOException If the stream has entered the error state.
160 private void __checkError()
163 /* {@squirreljme.error BD1n The underlying stream has entered the
165 if (this.output
.checkError())
166 throw new IOException("BD1n");