Remove clashing error prefix; Use better name for RatufaCoat ROMs.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / util / LinePushOutputStream.java
blob0c4e4c49f6898958ddedde12e1714092287c7de4
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;
16 /**
17 * Output stream for pushing lines out.
19 * @since 2022/09/11
21 public abstract class LinePushOutputStream
22 extends OutputStream
24 /** The working output buffer for logging. */
25 private final ByteArrayOutputStream _buffer =
26 new ByteArrayOutputStream();
28 /**
29 * Pushes the given string.
31 * @param __string The string to push.
32 * @since 2022/09/11
34 protected abstract void push(String __string);
36 /**
37 * {@inheritDoc}
38 * @since 2022/07/01
40 @Override
41 public final void write(int __b)
42 throws IOException
44 synchronized (this)
46 if (__b == '\r' || __b == '\n')
47 this.__push((byte)__b);
48 else
49 this._buffer.write(__b);
53 /**
54 * {@inheritDoc}
55 * @since 2022/07/01
57 @Override
58 public final void write(byte[] __b)
59 throws NullPointerException
61 if (__b == null)
62 throw new NullPointerException("NARG");
64 this.write(__b, 0, __b.length);
67 /**
68 * {@inheritDoc}
69 * @since 2022/07/01
71 @Override
72 public final void write(byte[] __b, int __o, int __l)
73 throws IndexOutOfBoundsException, NullPointerException
75 if (__b == null)
76 throw new NullPointerException("NARG");
77 if (__o < 0 || __l < 0 || (__o + __l) < 0 || (__o + __l) > __b.length)
78 throw new IndexOutOfBoundsException("IOOB");
80 synchronized (this)
82 for (int i = 0; i < __l; i++)
84 byte b = __b[__o + i];
86 if (b == '\r' || b == '\n')
87 this.__push(b);
88 else
89 this._buffer.write(b);
94 /**
95 * Pushes the byte to the output.
97 * @param __b The byte which triggered the push.
98 * @since 2022/07/01
100 private void __push(byte __b)
102 // Ignore carriage returns
103 if (__b == '\r')
104 return;
106 // Read string to print, wipe everything for the next round
107 ByteArrayOutputStream buffer = this._buffer;
108 String string = buffer.toString();
109 buffer.reset();
111 // Inform subclass
112 this.push(string);