[jboss-cvs] JBossAS SVN: r101075 - in projects/vfs/trunk/src: main/java/org/jboss/vfs/protocol and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 17 09:59:01 EST 2010
Author: alesj
Date: 2010-02-17 09:59:00 -0500 (Wed, 17 Feb 2010)
New Revision: 101075
Modified:
projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
Log:
[JBVFS-132]; temp fix for Mac OS temp files reading in VFURLConnnection.
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java 2010-02-17 14:35:43 UTC (rev 101074)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java 2010-02-17 14:59:00 UTC (rev 101075)
@@ -154,6 +154,7 @@
* @return the child
*
* @throws IllegalArgumentException if the path is null
+ * @throws java.net.URISyntaxException for any uri error
*/
public static VirtualFile getChild(URL url) throws URISyntaxException {
return getChild(url.toURI());
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java 2010-02-17 14:35:43 UTC (rev 101074)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java 2010-02-17 14:59:00 UTC (rev 101075)
@@ -21,18 +21,20 @@
*/
package org.jboss.vfs.protocol;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
-import java.net.URLDecoder;
import java.security.Permission;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VirtualFile;
-
/**
* Implements basic URLConnection for a VirtualFile
*
@@ -40,42 +42,61 @@
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-class VirtualFileURLConnection extends URLConnection {
+class VirtualFileURLConnection extends URLConnection
+{
+ private final VirtualFile file;
- protected VirtualFile file;
+ public VirtualFileURLConnection(URL url) throws IOException
+ {
+ super(url);
+ file = VFS.getChild(toURI(url));
+ }
- public VirtualFileURLConnection(URL url) throws IOException {
- super(url);
- file = VFS.getChild(URLDecoder.decode(url.getPath(), "UTF-8"));
- }
+ public void connect() throws IOException
+ {
+ }
- public void connect() throws IOException {
- }
+ public VirtualFile getContent() throws IOException
+ {
+ return file;
+ }
- public VirtualFile getContent() throws IOException {
- return file;
- }
+ public int getContentLength()
+ {
+ final long size = file.getSize();
+ return size > (long) Integer.MAX_VALUE ? -1 : (int) size;
+ }
- public int getContentLength() {
- final long size = file.getSize();
- return size > (long) Integer.MAX_VALUE ? -1 : (int) size;
- }
+ public long getLastModified()
+ {
+ return file.getLastModified();
+ }
- public long getLastModified() {
- return file.getLastModified();
- }
+ public InputStream getInputStream() throws IOException
+ {
+ return file.openStream();
+ }
- public InputStream getInputStream() throws IOException {
- return file.openStream();
- }
+ public Permission getPermission() throws IOException
+ {
+ String decodedPath = toURI(url).getPath(); // TODO -- is this OK?
+ if (File.separatorChar != '/')
+ decodedPath = decodedPath.replace('/', File.separatorChar);
- public Permission getPermission() throws IOException {
- String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
- if (File.separatorChar == '/') {
- return new FilePermission(decodedPath, "read");
- } else {
- return new FilePermission(
- decodedPath.replace('/', File.separatorChar), "read");
- }
- }
+ return new FilePermission(decodedPath, "read");
+ }
+
+ private static URI toURI(URL url) throws IOException
+ {
+ try
+ {
+ return VFSUtils.toURI(url);
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-02-17 14:35:43 UTC (rev 101074)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-02-17 14:59:00 UTC (rev 101075)
@@ -22,14 +22,17 @@
package org.jboss.test.vfs;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
+import java.util.List;
import junit.framework.Test;
+import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
/**
@@ -114,6 +117,28 @@
assertTrue(Arrays.equals(readBytes(file.openStream()), readBytes(conn.getInputStream())));
}
+ public void testPathWithSpaces() throws Exception
+ {
+ VirtualFile root = getVirtualFile("/vfs/test/");
+ VirtualFile file = root.getChild("path with spaces/spaces.ear");
+ File real = file.getPhysicalFile();
+ assertTrue(real.exists());
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertTrue(Arrays.equals(readBytes(conn.getInputStream()), readBytes(file.openStream())));
+ }
+
+ public void testTempPath() throws Exception
+ {
+ File temp = File.createTempFile("123", ".tmp");
+ temp.deleteOnExit();
+ VirtualFile file = VFS.getChild(temp.toURI());
+ assertTrue(file.exists());
+ URL url = file.toURL();
+ URLConnection conn = url.openConnection();
+ assertEquals(file.getLastModified(), conn.getLastModified());
+ }
+
protected static byte[] readBytes(InputStream inputStream) throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
More information about the jboss-cvs-commits
mailing list