[jboss-cvs] JBossAS SVN: r75834 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 15 05:03:24 EDT 2008
Author: alesj
Date: 2008-07-15 05:03:24 -0400 (Tue, 15 Jul 2008)
New Revision: 75834
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/URLConnectionUnitTestCase.java
Log:
[JBVFS-46]; override some of URLConnection methods.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java 2008-07-15 08:59:04 UTC (rev 75833)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java 2008-07-15 09:03:24 UTC (rev 75834)
@@ -70,6 +70,35 @@
return getVirtualFile();
}
+ public int getContentLength()
+ {
+ try
+ {
+ return (int)getVirtualFile().getSize();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public long getLastModified()
+ {
+ try
+ {
+ return getVirtualFile().getLastModified();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ return getVirtualFile().openStream();
+ }
+
@SuppressWarnings("deprecation")
protected static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
{
@@ -121,9 +150,4 @@
}
return file;
}
-
- public InputStream getInputStream() throws IOException
- {
- return getVirtualFile().openStream();
- }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/URLConnectionUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/URLConnectionUnitTestCase.java 2008-07-15 08:59:04 UTC (rev 75833)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/URLConnectionUnitTestCase.java 2008-07-15 09:03:24 UTC (rev 75834)
@@ -21,7 +21,16 @@
*/
package org.jboss.test.virtual.test;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+
import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
/**
* Basic tests of URL connection
@@ -40,11 +49,95 @@
return suite(URLConnectionUnitTestCase.class);
}
+ protected String getFileName()
+ {
+ return "outer.jar";
+ }
+
+ protected VirtualFile getFile() throws IOException
+ {
+ URL url = getResource("/vfs/test/");
+ VirtualFile root = VFS.getRoot(url);
+ VirtualFile file = root.getChild(getFileName());
+ assertNotNull(file);
+ return file;
+ }
+
/**
- * Test url content
+ * Test url connection content.
+ *
* @throws Exception for any error
*/
public void testContent() throws Exception
{
+ VirtualFile file = getFile();
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertEquals(file, conn.getContent());
}
+
+ /**
+ * Test url connection content lenght.
+ *
+ * @throws Exception for any error
+ */
+ public void testContentLenght() throws Exception
+ {
+ VirtualFile file = getFile();
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertEquals(file.getSize(), conn.getContentLength());
+ }
+
+ /**
+ * Test url connection last modified.
+ *
+ * @throws Exception for any error
+ */
+ public void testLastModified() throws Exception
+ {
+ VirtualFile file = getFile();
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertEquals(file.getLastModified(), conn.getLastModified());
+ }
+
+ /**
+ * Test url connection input stream.
+ *
+ * @throws Exception for any error
+ */
+ public void testInputStream() throws Exception
+ {
+ VirtualFile file = getFile();
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertTrue(Arrays.equals(readBytes(file.openStream()), readBytes(conn.getInputStream())));
+ }
+
+ protected static byte[] readBytes(InputStream inputStream) throws Exception
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ int read = 0;
+ byte[] bytes = new byte[1024];
+ try
+ {
+ while (read >=0)
+ {
+ read = inputStream.read(bytes);
+ baos.write(bytes);
+ }
+ }
+ finally
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ return baos.toByteArray();
+ }
}
More information about the jboss-cvs-commits
mailing list