From c85ec6f26ade692103ac27383a87c3402b4d66ca Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Wed, 20 Feb 2002 23:19:08 +0000 Subject: [PATCH] Merged the Streamable interface into the AuditListener interface. Having them separate served no real purpose at the moment, except to complicate the implementation. --- .../tools/checkstyle/AuditListener.java | 10 ++++ .../tools/checkstyle/CheckStyleTask.java | 5 +- .../puppycrawl/tools/checkstyle/Checker.java | 25 ++++---- .../tools/checkstyle/DefaultLogger.java | 6 +- .../tools/checkstyle/Streamable.java | 57 ------------------- .../tools/checkstyle/XMLLogger.java | 6 +- 6 files changed, 28 insertions(+), 81 deletions(-) delete mode 100644 src/checkstyle/com/puppycrawl/tools/checkstyle/Streamable.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/AuditListener.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/AuditListener.java index fd8e8fb9a..d11bf0465 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/AuditListener.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/AuditListener.java @@ -18,6 +18,7 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle; +import java.io.OutputStream; import java.util.EventListener; /** @@ -37,6 +38,15 @@ import java.util.EventListener; public interface AuditListener extends EventListener { + /** + * Set a stream to write information to. + * @param aOS the outputstream to be set. + */ + void setOutputStream(OutputStream aOS); + + /** @return the stream used to write information to. **/ + OutputStream getOutputStream(); + /** * notify that the audit is about to start * @param aEvt the event details diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java index d55050150..85c79dacd 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java @@ -504,10 +504,7 @@ public class CheckStyleTask { final Class clazz = Class.forName(mClassName); final AuditListener listener = (AuditListener) clazz.newInstance(); - if (listener instanceof Streamable) { - final Streamable o = (Streamable) listener; - o.setOutputStream(createOutputStream(aTask)); - } + listener.setOutputStream(createOutputStream(aTask)); return listener; } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index ae57548f8..adaff4d44 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -68,25 +68,22 @@ public class Checker { mCache.destroy(); - // close all streamable listeners + // close all listeners final Iterator it = mListeners.iterator(); while (it.hasNext()) { - final Object obj = it.next(); - if (obj instanceof Streamable) { - final Streamable str = (Streamable) obj; - final OutputStream os = str.getOutputStream(); - // close only those that can be closed... - if ((os != System.out) && (os != System.err) && (os != null)) { - try { - os.flush(); - os.close(); - } - catch (IOException ignored) { - } + final AuditListener listener = (AuditListener) it.next(); + final OutputStream os = listener.getOutputStream(); + // close only those that can be closed... + if ((os != System.out) && (os != System.err) && (os != null)) { + try { + os.flush(); + os.close(); + } + catch (IOException ignored) { } } - it.remove(); } + it.remove(); } /** diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultLogger.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultLogger.java index f8dad6a17..e06856ed3 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultLogger.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/DefaultLogger.java @@ -32,7 +32,7 @@ import java.io.PrintWriter; * @see XMLLogger */ public class DefaultLogger - implements AuditListener, Streamable + implements AuditListener { /** where to log **/ private OutputStream mStream; @@ -55,14 +55,14 @@ public class DefaultLogger setOutputStream(aOS); } - /** @see Streamable **/ + /** @see AuditListener **/ public void setOutputStream(OutputStream aOS) { mWriter = new PrintWriter(aOS); mStream = aOS; } - /** @see Streamable **/ + /** @see AuditListener **/ public OutputStream getOutputStream() { return mStream; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Streamable.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Streamable.java deleted file mode 100644 index 3d8fbe883..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Streamable.java +++ /dev/null @@ -1,57 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code for adherence to a set of rules. -// Copyright (C) 2001-2002 Oliver Burn -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -//////////////////////////////////////////////////////////////////////////////// -package com.puppycrawl.tools.checkstyle; - -import java.io.OutputStream; - -/** - * Mainly use to give an Audit listener the ability to pass - * an OutputStream without cluttering the original Listener - * interfaces. - *

- * This will be used to set the appropriate stream at configuration - * time (ie, a file, stdout or whatever) and the stream will be - * closed once the checker is destroyed. - * - * (We cannot rely on the finalizer to close the file because it can - * takes some time and on Window we cannot delete the generated file - * if there is still a handle on it). - * - * Pay attention to keep the original stream so that getOutputStream - * sends back the setted one (You would me to close stdout or stderr - * right ?) - * - * @author Stephane Bailliez - * @see AuditListener - * @see CheckStyleTask - * @see Checker - */ -public interface Streamable -{ - /** - * Set a stream to write information to. - * @param aOS the outputstream to be set. - */ - void setOutputStream(OutputStream aOS); - - /** - * @return the stream used to write information to. - */ - OutputStream getOutputStream(); -} diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/XMLLogger.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/XMLLogger.java index 6c31b7ca5..0b604a854 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/XMLLogger.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/XMLLogger.java @@ -33,7 +33,7 @@ import java.io.UnsupportedEncodingException; * @author Stephane Bailliez */ public class XMLLogger - implements AuditListener, Streamable + implements AuditListener { /** the original wrapped stream */ private OutputStream mStream; @@ -59,7 +59,7 @@ public class XMLLogger setOutputStream(aOS); } - /** @see Streamable **/ + /** @see AuditListener **/ public void setOutputStream(OutputStream aOS) { try { @@ -75,7 +75,7 @@ public class XMLLogger } } - /** @see Streamable **/ + /** @see AuditListener **/ public OutputStream getOutputStream() { return mStream;