User: user57
Date: 02/04/04 14:20:23
Added: src/main/org/jboss/net/protocol/file FileURLConnection.java
Handler.java package.html
Log:
o A file protocol handler which correctly returns File.lastModified() for
URLConnection.getLastModified()
Revision Changes Path
1.1
jboss-common/src/main/org/jboss/net/protocol/file/FileURLConnection.java
Index: FileURLConnection.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.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.security.Permission;
import java.io.FilePermission;
/**
* Provides local file access via URL semantics, correctly returning
* lastModified.
*
* @version <tt>$Revision: 1.1 $</tt>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
*/
public class FileURLConnection
extends URLConnection
{
protected File file;
public FileURLConnection(final URL url)
throws MalformedURLException, IOException
{
super(url);
file = new File(url.getFile());
doOutput = false;
}
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();
return new FileOutputStream(file);
}
public String getHeaderField(final String name) {
if (name.equalsIgnoreCase("last-modified")) {
return String.valueOf(getLastModified());
}
return super.getHeaderField(name);
}
public Permission getPermission() throws IOException {
// should probably return a FilePermission here...
// but I don't understand that crap, so just return the default
return super.getPermission();
}
public long getLastModified() {
return file.lastModified();
}
}
1.1 jboss-common/src/main/org/jboss/net/protocol/file/Handler.java
Index: Handler.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.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: 1.1 $</tt>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
*/
public class Handler
extends URLStreamHandler
{
public URLConnection openConnection(final URL url)
throws IOException
{
return new FileURLConnection(url);
}
}
1.1 jboss-common/src/main/org/jboss/net/protocol/file/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!-- $Id: package.html,v 1.1 2002/04/04 22:20:22 user57 Exp $ -->
<!--
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>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development