From: Scott M S. <st...@us...> - 2002-06-23 20:36:05
|
User: starksm Date: 02/06/23 13:36:03 Modified: src/main/org/jboss/net/protocol/file FileURLConnection.java Log: The URLConnection implements its getXXX() methods by calling the getHeaderField(String) method so we need to handle those header fields that make sense for files. Added handling of headers: + content-length : file.length() + content-type : getFileNameMap().getContentTypeFor(file.getName()) + date : file.lastModified() Revision Changes Path 1.7 +40 -19 jboss-common/src/main/org/jboss/net/protocol/file/FileURLConnection.java Index: FileURLConnection.java =================================================================== RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/net/protocol/file/FileURLConnection.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- FileURLConnection.java 18 Apr 2002 01:29:54 -0000 1.6 +++ FileURLConnection.java 23 Jun 2002 20:36:03 -0000 1.7 @@ -28,8 +28,9 @@ * Provides local file access via URL semantics, correctly returning * the last modified time of the underlying file. * - * @version <tt>$Revision: 1.6 $</tt> + * @version $Revision: 1.7 $ * @author <a href="mailto:ja...@pl...">Jason Dillon</a> + * @author Sco...@jb... */ public class FileURLConnection extends URLConnection @@ -40,7 +41,7 @@ throws MalformedURLException, IOException { super(url); - + file = new File(url.getPath().replace('/', File.separatorChar).replace('|', ':')); doOutput = false; @@ -49,7 +50,8 @@ /** * Returns the underlying file for this connection. */ - public File getFile() { + public File getFile() + { return file; } @@ -58,25 +60,32 @@ * * @throws FileNotFoundException */ - public void connect() throws IOException { - if (connected) return; + public void connect() throws IOException + { + if (connected) + return; - if (!file.exists()) { + if (!file.exists()) + { throw new FileNotFoundException(file.getPath()); } - + connected = true; } - public InputStream getInputStream() throws IOException { - if (!connected) connect(); + public InputStream getInputStream() throws IOException + { + if (!connected) + connect(); return new FileInputStream(file); } - public OutputStream getOutputStream() throws IOException { - if (!connected) connect(); - + public OutputStream getOutputStream() throws IOException + { + if (!connected) + connect(); + return new FileOutputStream(file); } @@ -84,15 +93,26 @@ * Provides support for returning the value for the * <tt>last-modified</tt> header. */ - public String getHeaderField(final String name) { - if (name.equalsIgnoreCase("last-modified")) { - return String.valueOf(getLastModified()); + 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()); + else if (name.equalsIgnoreCase("date")) + headerField = String.valueOf(file.lastModified()); + else + { + // This always returns null currently + headerField = super.getHeaderField(name); } - - return super.getHeaderField(name); + return headerField; } - /** + /** * Return a permission for both read & write since both * input and output streams are supported. */ @@ -104,7 +124,8 @@ /** * Returns the last modified time of the underlying file. */ - public long getLastModified() { + public long getLastModified() + { return file.lastModified(); } } |