1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.util
;
12 import java
.io
.ByteArrayOutputStream
;
13 import java
.io
.IOException
;
14 import java
.io
.OutputStream
;
17 * Output stream for pushing lines out.
21 public abstract class LinePushOutputStream
24 /** The working output buffer for logging. */
25 private final ByteArrayOutputStream _buffer
=
26 new ByteArrayOutputStream();
29 * Pushes the given string.
31 * @param __string The string to push.
34 protected abstract void push(String __string
);
41 public final void write(int __b
)
46 if (__b
== '\r' || __b
== '\n')
47 this.__push((byte)__b
);
49 this._buffer
.write(__b
);
58 public final void write(byte[] __b
)
59 throws NullPointerException
62 throw new NullPointerException("NARG");
64 this.write(__b
, 0, __b
.length
);
72 public final void write(byte[] __b
, int __o
, int __l
)
73 throws IndexOutOfBoundsException
, NullPointerException
76 throw new NullPointerException("NARG");
77 if (__o
< 0 || __l
< 0 || (__o
+ __l
) < 0 || (__o
+ __l
) > __b
.length
)
78 throw new IndexOutOfBoundsException("IOOB");
82 for (int i
= 0; i
< __l
; i
++)
84 byte b
= __b
[__o
+ i
];
86 if (b
== '\r' || b
== '\n')
89 this._buffer
.write(b
);
95 * Pushes the byte to the output.
97 * @param __b The byte which triggered the push.
100 private void __push(byte __b
)
102 // Ignore carriage returns
106 // Read string to print, wipe everything for the next round
107 ByteArrayOutputStream buffer
= this._buffer
;
108 String string
= buffer
.toString();