From: jprocter Date: Wed, 30 Nov 2005 18:06:04 +0000 (+0000) Subject: wrapper class to prevent client from closing JarOutputStream when it closes the AppDa... X-Git-Tag: Release_0.2~418 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=182b7b1359e39d1357939c4c834f52abaf2651c6;p=vamsas.git wrapper class to prevent client from closing JarOutputStream when it closes the AppData writing stream. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@102 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/AppDataOutputStream.java b/src/org/vamsas/client/simpleclient/AppDataOutputStream.java new file mode 100644 index 0000000..db13652 --- /dev/null +++ b/src/org/vamsas/client/simpleclient/AppDataOutputStream.java @@ -0,0 +1,86 @@ +/** + * + */ +package org.vamsas.client.simpleclient; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author jimp + * + */ +public class AppDataOutputStream extends DataOutputStream { + private Log log = LogFactory.getLog(AppDataOutputStream.class); + private boolean isOpen=true; + /** + * @param out + */ + public AppDataOutputStream(OutputStream out) { + super(out); + isOpen=true; + } + /* (non-Javadoc) + * @see java.io.DataOutputStream#flush() + */ + public void flush() throws IOException { + if (isOpen) + super.flush(); + else + log.warn("flush() called on closed AppDataOutputStream"); + } + /* (non-Javadoc) + * @see java.io.DataOutputStream#write(byte[], int, int) + */ + public synchronized void write(byte[] b, int off, int len) throws IOException { + if (isOpen) { + super.write(b, off, len); + } else { + log.debug("write(b,off,len) called on closed AppDataOutputStream"); + throw new IOException("Attempt to write to closed AppDataOutputStream"); + } + } + /* (non-Javadoc) + * @see java.io.DataOutputStream#write(int) + */ + public synchronized void write(int b) throws IOException { + if (isOpen) { + super.write(b); + } else { + log.debug("write(b) called on closed AppDataOutputStream"); + throw new IOException("Attempt to write to closed AppDataOutputStream"); + } + } + /** + * Sets an internal flag preventing further write operations + * to the AppData output stream and flushes any pending writes. + * @see java.io.FilterOutputStream#close() + */ + public void close() throws IOException { + isOpen=false; + super.flush(); + log.debug("AppDataOutputStream was closed."); + } + /* (non-Javadoc) + * @see java.io.FilterOutputStream#write(byte[]) + */ + public void write(byte[] b) throws IOException { + if (isOpen) { + super.write(b); + } else { + log.debug("write(b[]) called on closed AppDataOutputStream"); + throw new IOException("Attempt to write to closed AppDataOutputStream"); + } + } + /** + * @return true if stream is still Open. + */ + public boolean isOpen() { + return isOpen; + } + +}