[jboss-svn-commits] JBoss Common SVN: r2852 - in common-core/trunk/src: test/java/org/jboss/test/util/test and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 27 21:52:58 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-05-27 21:52:58 -0400 (Tue, 27 May 2008)
New Revision: 2852
Added:
common-core/trunk/src/test/java/org/jboss/test/util/test/protocol/
common-core/trunk/src/test/java/org/jboss/test/util/test/protocol/FileURLConnectionTestCase.java
Removed:
common-core/trunk/src/main/java/org/jboss/net/protocol/file/FileURLConnection.java
common-core/trunk/src/main/java/org/jboss/net/protocol/file/Handler.java
common-core/trunk/src/main/java/org/jboss/net/protocol/file/package.html
Log:
JBCOMMON-55, drop the jboss file protocol handler URLConnection implementation.
Deleted: common-core/trunk/src/main/java/org/jboss/net/protocol/file/FileURLConnection.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/net/protocol/file/FileURLConnection.java 2008-05-23 18:55:59 UTC (rev 2851)
+++ common-core/trunk/src/main/java/org/jboss/net/protocol/file/FileURLConnection.java 2008-05-28 01:52:58 UTC (rev 2852)
@@ -1,176 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.net.protocol.file;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-
-import java.net.URLConnection;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLDecoder;
-
-import java.security.Permission;
-import java.io.FilePermission;
-import java.io.BufferedInputStream;
-
-/**
- * Provides local file access via URL semantics, correctly returning
- * the last modified time of the underlying file.
- *
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:scott.stark at jboss.org">Scott.Stark</a>
- * @version $Revision$
- */
-public class FileURLConnection extends URLConnection
-{
- static boolean decodeFilePaths = true;
- static
- {
- String flag = System.getProperty("org.jboss.net.protocol.file.decodeFilePaths");
- if (flag != null)
- decodeFilePaths = Boolean.valueOf(flag).booleanValue();
- }
-
- protected File file;
-
- public FileURLConnection(final URL url) throws MalformedURLException, IOException
- {
- super(url);
- String path = url.getPath();
- if (decodeFilePaths)
- path = URLDecoder.decode(path, "UTF-8");
-
- // Convert the url '/' to the os file separator
- file = new File(path.replace('/', File.separatorChar).replace('|', ':'));
-
- doOutput = false;
- }
-
- /**
- * Returns the underlying file for this connection.
- * @return the file
- */
- public File getFile()
- {
- return file;
- }
-
- /**
- * Checks if the underlying file for this connection exists.
- *
- * @throws FileNotFoundException
- */
- public void connect() throws IOException
- {
- if (connected)
- return;
-
- if (!file.exists())
- {
- throw new FileNotFoundException(file.getPath());
- }
-
- connected = true;
- }
-
- public InputStream getInputStream() throws IOException
- {
- if (!connected)
- connect();
-
- return new FileInputStream(file);
- }
-
- public OutputStream getOutputStream() throws IOException
- {
- if (!connected)
- connect();
- SecurityManager sm = System.getSecurityManager();
- if( sm != null )
- {
- // Check for write access
- FilePermission p = new FilePermission(file.getPath(), "write");
- sm.checkPermission(p);
- }
- return new FileOutputStream(file);
- }
-
- /**
- * Provides support for returning the value for the
- * <tt>last-modified</tt> header.
- */
- public String getHeaderField(final String name)
- {
- String headerField = null;
- if (name.equalsIgnoreCase("last-modified"))
- headerField = String.valueOf(getLastModified());
- else if (name.equalsIgnoreCase("content-length"))
- headerField = String.valueOf(file.length());
- else if (name.equalsIgnoreCase("content-type"))
- {
- headerField = getFileNameMap().getContentTypeFor(file.getName());
- if( headerField == null )
- {
- try
- {
- InputStream is = getInputStream();
- BufferedInputStream bis = new BufferedInputStream(is);
- headerField = URLConnection.guessContentTypeFromStream(bis);
- bis.close();
- }
- catch(IOException e)
- {
- }
- }
- }
- else if (name.equalsIgnoreCase("date"))
- headerField = String.valueOf(file.lastModified());
- else
- {
- // This always returns null currently
- headerField = super.getHeaderField(name);
- }
- return headerField;
- }
-
- /**
- * Return a permission for reading of the file
- */
- public Permission getPermission() throws IOException
- {
- return new FilePermission(file.getPath(), "read");
- }
-
- /**
- * Returns the last modified time of the underlying file.
- */
- public long getLastModified()
- {
- return file.lastModified();
- }
-}
Deleted: common-core/trunk/src/main/java/org/jboss/net/protocol/file/Handler.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/net/protocol/file/Handler.java 2008-05-23 18:55:59 UTC (rev 2851)
+++ common-core/trunk/src/main/java/org/jboss/net/protocol/file/Handler.java 2008-05-28 01:52:58 UTC (rev 2852)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.net.protocol.file;
-
-import java.io.IOException;
-
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLStreamHandler;
-
-/**
- * A protocol handler for the 'file' protocol.
- *
- * @version <tt>$Revision$</tt>
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- */
-public class Handler
- extends URLStreamHandler
-{
- public URLConnection openConnection(final URL url)
- throws IOException
- {
- return new FileURLConnection(url);
- }
-
- protected void parseURL(final URL url, final String s, final int i, final int j)
- {
- super.parseURL(url, s.replace(java.io.File.separatorChar, '/'), i, j);
- }
-}
Deleted: common-core/trunk/src/main/java/org/jboss/net/protocol/file/package.html
===================================================================
--- common-core/trunk/src/main/java/org/jboss/net/protocol/file/package.html 2008-05-23 18:55:59 UTC (rev 2851)
+++ common-core/trunk/src/main/java/org/jboss/net/protocol/file/package.html 2008-05-28 01:52:58 UTC (rev 2852)
@@ -1,41 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
- <head>
- <!-- $Id$ -->
- <!--
-
- JBoss: The OpenSource J2EE WebOS
-
- Distributable under LGPL license.
- See terms of license at gnu.org.
-
- -->
- </head>
-
- <body bgcolor="white">
- <p>A better implementation of the 'file' protocol.
-
- <h2>Package Specification</h2>
- <ul>
- <li><a href="javascript: alert('not available')">Not Available</a>
- </ul>
-
- <h2>Related Documentation</h2>
- <ul>
- <li><a href="javascript: alert('not available')">Not Available</a>
- </ul>
-
- <h2>Package Status</h2>
- <ul>
- <li><font color="green"><b>STABLE</b></font>
- </ul>
-
- <h2>Todo</h2>
- <ul>
- <li>???
- </ul>
-
- <!-- Put @see and @since tags down here. -->
-
- </body>
-</html>
Added: common-core/trunk/src/test/java/org/jboss/test/util/test/protocol/FileURLConnectionTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/protocol/FileURLConnectionTestCase.java (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/protocol/FileURLConnectionTestCase.java 2008-05-28 01:52:58 UTC (rev 2852)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.test.protocol;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests of the expected jdk file: url connection protocol handler behaviors.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class FileURLConnectionTestCase extends TestCase
+{
+ public void testLastModified()
+ throws Exception
+ {
+ File tmp = File.createTempFile("testLastModified", "test");
+ tmp.deleteOnExit();
+ long lastModified = tmp.lastModified();
+ System.out.println(tmp.getAbsolutePath()+", lastModified:"+lastModified);
+ URL tmpURL = tmp.toURL();
+ URLConnection tmpConn = tmpURL.openConnection();
+ assertEquals(lastModified, tmpConn.getLastModified());
+ long lastModifiedHdr = tmpConn.getHeaderFieldDate("Last-Modified", 0);
+ System.out.println("Last-Modified: "+lastModifiedHdr);
+ assertEquals(lastModified, lastModifiedHdr);
+ }
+
+ public void testLength()
+ throws Exception
+ {
+ File tmp = File.createTempFile("testLastModified", "test");
+ tmp.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(tmp);
+ fos.write("testLength".getBytes());
+ fos.close();
+
+ URL tmpURL = tmp.toURL();
+ URLConnection tmpConn = tmpURL.openConnection();
+ int length = tmpConn.getContentLength();
+ System.out.println(tmp.getAbsolutePath()+", length:"+length);
+ assertEquals(tmp.length(), length);
+ int lengthHdr = tmpConn.getHeaderFieldInt("Content-Length", 0);
+ assertEquals(length, lengthHdr);
+ }
+}
More information about the jboss-svn-commits
mailing list