commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r520065 - in /jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs: Resources.properties util/MonitorOutputStream.java
Date Mon, 19 Mar 2007 19:41:44 GMT
Author: imario
Date: Mon Mar 19 12:41:43 2007
New Revision: 520065

URL: http://svn.apache.org/viewvc?view=rev&rev=520065
Log:
VFS-111: fail fast when trying to write to a closed file

Modified:
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
    jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/util/MonitorOutputStream.java

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties?view=diff&rev=520065&r1=520064&r2=520065
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/Resources.properties
Mon Mar 19 12:41:43 2007
@@ -62,6 +62,7 @@
 vfs.provider/random-access.error=Could not read/write file "{0}".
 vfs.provider/read-not-readable.error=File "{0}" is not readable.
 vfs.provider/read-not-file.error=Could not read from "{0}" because it is a not a file.
+vfs.provider/closed.error=File closed.
 
 # DefaultFileContent
 vfs.provider/get-size-not-file.error=Could not determine the size of "{0}" because it is
not a file.

Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/util/MonitorOutputStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/util/MonitorOutputStream.java?view=diff&rev=520065&r1=520064&r2=520065
==============================================================================
--- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/util/MonitorOutputStream.java
(original)
+++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/util/MonitorOutputStream.java
Mon Mar 19 12:41:43 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.vfs.util;
 
+import org.apache.commons.vfs.FileSystemException;
+
 import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -75,7 +77,45 @@
         }
     }
 
-    /**
+
+	public synchronized void write(int b) throws IOException
+	{
+		assertOpen();
+		super.write(b);
+	}
+
+	public synchronized void write(byte b[], int off, int len) throws IOException
+	{
+		assertOpen();
+		super.write(b, off, len);
+	}
+
+	public synchronized void flush() throws IOException
+	{
+		assertOpen();
+		super.flush();
+	}
+
+	public void write(byte b[]) throws IOException
+	{
+		assertOpen();
+		super.write(b);
+	}
+
+	/**
+	 * check if file is still open. <br />
+	 * This is a workaround for an oddidy with javas BufferedOutputStream where you can write
to
+	 * even if the stream has been closed
+	 */
+	protected void assertOpen() throws FileSystemException
+	{
+		if (finished)
+		{
+			throw new FileSystemException("vfs.provider/closed.error");
+		}
+	}
+
+	/**
      * Called after this stream is closed.  This implementation does nothing.
      */
     protected void onClose() throws IOException



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message