Author: aslak
Date: 2010-07-09 12:16:18 -0400 (Fri, 09 Jul 2010)
New Revision: 4710
Modified:
shrinkwrap/trunk/extension-vfs3/src/main/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystem.java
shrinkwrap/trunk/extension-vfs3/src/test/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystemUnitTestCase.java
Log:
SHRINKWRAP-204 Added throw IOException if Node or Asset is null
Modified: shrinkwrap/trunk/extension-vfs3/src/main/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystem.java
===================================================================
--- shrinkwrap/trunk/extension-vfs3/src/main/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystem.java 2010-07-09 10:22:02 UTC (rev 4709)
+++ shrinkwrap/trunk/extension-vfs3/src/main/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystem.java 2010-07-09 16:16:18 UTC (rev 4710)
@@ -238,20 +238,23 @@
/** {@inheritDoc} */
public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException
{
- InputStream stream = null;
final Node node = getNode(mountPoint, target);
- if (node != null)
+ if(node == null || node.getAsset() == null)
{
- final File cachedFile = getCachedFile(node);
- if (cachedFile.exists())
- {
- stream = new FileInputStream(cachedFile);
- }
- else if (node.getAsset() != null)
- {
- stream = node.getAsset().openStream();
- }
+ throw new IOException("Target not found: " + target.getPathName());
}
+
+ InputStream stream = null;
+
+ final File cachedFile = getCachedFile(node);
+ if (cachedFile.exists())
+ {
+ stream = new FileInputStream(cachedFile);
+ }
+ else if (node.getAsset() != null)
+ {
+ stream = node.getAsset().openStream();
+ }
return stream;
}
Modified: shrinkwrap/trunk/extension-vfs3/src/test/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystemUnitTestCase.java
===================================================================
--- shrinkwrap/trunk/extension-vfs3/src/test/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystemUnitTestCase.java 2010-07-09 10:22:02 UTC (rev 4709)
+++ shrinkwrap/trunk/extension-vfs3/src/test/java/org/jboss/shrinkwrap/vfs3/ArchiveFileSystemUnitTestCase.java 2010-07-09 16:16:18 UTC (rev 4710)
@@ -18,6 +18,7 @@
import java.io.Closeable;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -155,6 +156,26 @@
Assert.assertFalse("File that doesn't exist should not report as a directory", doesNotExistFile.isDirectory());
}
+ /**
+ * Ensure that {@link VirtualFile#openStream()} throws IOException on non existing files and not return a null
+ * {@link InputStream}.
+ *
+ * SHRINKWRAP-
+ *
+ * @throws Exception
+ * @throws IOException Should throw IOException when trying to open a file that does not exist.
+ */
+ @Test(expected = IOException.class)
+ public void openingNonExistingFilesShouldResultInException() throws Exception
+ {
+
+ final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, NAME_ARCHIVE);
+ final VirtualFile virtualFile = this.createAndMountArchive(archive);
+
+ final VirtualFile doesNotExistFile = virtualFile.getChild("doesnotexist");
+ doesNotExistFile.openStream(); // IOException, file does not exist
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||