Remove clashing error prefix; Use better name for RatufaCoat ROMs.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / util / GuardedOutputStream.java
blob376ea49c2bbca86ab0e6e6cfbad8c05ca5c712c0
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // 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.IOException;
13 import java.io.OutputStream;
15 /**
16 * This is an output stream that is guarded by being closed.
18 * @since 2020/11/21
20 public final class GuardedOutputStream
21 extends OutputStream
23 /** The true output stream. */
24 protected final OutputStream out;
26 /** Is this closed? */
27 volatile boolean _closed;
29 /**
30 * Initializes the guarded stream.
32 * @param __out The output stream.
33 * @throws NullPointerException On null arguments.
34 * @since 2020/11/21
36 public GuardedOutputStream(OutputStream __out)
37 throws NullPointerException
39 if (__out == null)
40 throw new NullPointerException("NARG");
42 this.out = __out;
45 /**
46 * {@inheritDoc}
47 * @since 2020/11/21
49 @Override
50 public void close()
51 throws IOException
53 if (!this._closed)
55 // Make sure everything is written before closing
56 try
58 this.out.flush();
60 finally
62 this._closed = true;
67 /**
68 * {@inheritDoc}
69 * @since 2020/11/21
71 @Override
72 public void flush()
73 throws IOException
75 if (this._closed)
76 throw new IOException("Stream is closed.");
78 this.out.flush();
81 /**
82 * {@inheritDoc}
83 * @since 2020/11/21
85 @Override
86 public void write(int __b)
87 throws IOException
89 if (this._closed)
90 throw new IOException("Stream is closed.");
92 this.out.write(__b);
95 /**
96 * {@inheritDoc}
97 * @since 2020/11/21
99 @Override
100 public void write(byte[] __b)
101 throws IOException
103 if (this._closed)
104 throw new IOException("Stream is closed.");
106 this.out.write(__b);
110 * {@inheritDoc}
111 * @since 2020/11/21
113 @Override
114 public void write(byte[] __b, int __o, int __l)
115 throws IOException
117 if (this._closed)
118 throw new IOException("Stream is closed.");
120 this.out.write(__b, __o, __l);