Merged the Streamable interface into the AuditListener interface. Having them

separate served no real purpose at the moment, except to complicate the
implementation.
This commit is contained in:
Oliver Burn 2002-02-20 23:19:08 +00:00
parent 339a7f5475
commit c85ec6f26a
6 changed files with 28 additions and 81 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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();
}
/**

View File

@ -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;

View File

@ -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.
* <p>
* 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.
* <i>
* (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).
* </i>
* 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 <a href="mailto:stephane.bailliez@wanadoo.fr">Stephane Bailliez</a>
* @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();
}

View File

@ -33,7 +33,7 @@ import java.io.UnsupportedEncodingException;
* @author <a href="mailto:stephane.bailliez@wanadoo.fr">Stephane Bailliez</a>
*/
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;