harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r440814 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file: FileURLConnection.java Handler.java
Date Wed, 06 Sep 2006 18:11:39 GMT
Author: ndbeyer
Date: Wed Sep  6 11:11:38 2006
New Revision: 440814

URL: http://svn.apache.org/viewvc?view=rev&rev=440814
Log:
Code cleanup; remove warning, etc

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java?view=diff&rev=440814&r1=440813&r2=440814
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
Wed Sep  6 11:11:38 2006
@@ -15,7 +15,6 @@
 
 package org.apache.harmony.luni.internal.net.www.protocol.file;
 
-
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -29,7 +28,7 @@
 import java.net.URLConnection;
 
 import org.apache.harmony.luni.internal.net.www.MimeTable;
-
+import org.apache.harmony.luni.util.Util;
 
 /**
  * This subclass extends <code>URLConnection</code>.
@@ -39,147 +38,159 @@
  */
 public class FileURLConnection extends URLConnection {
 
-	String fileName;
+    String fileName;
 
-	private InputStream is;
+    private InputStream is;
 
-	private int length = -1;
+    private int length = -1;
 
-	private boolean isDir = false;
+    private boolean isDir;
 
-	private FilePermission permission;
-
-	/**
-	 * Creates an instance of <code>FileURLConnection</code> for establishing
-	 * a connection to the file pointed by this <code>URL<code>
-	 *
-	 * @param 		url 		The URL this connection is connected to
-	 */
-	public FileURLConnection(URL url) {
-		super(url);
-		if ((fileName = url.getFile()) == null)
-			fileName = "";
-		String host = url.getHost();
-		if (host != null && host.length() > 0)
-			fileName = "//" + host + fileName;
-		fileName = org.apache.harmony.luni.util.Util.decode(fileName, false);
-	}
-
-	/**
-	 * This methods will attempt to obtain the input stream of the file pointed
-	 * by this <code>URL</code>. If the file is a directory, it will return
-	 * that directory listing as an input stream.
-	 * 
-	 * @throws IOException
-	 *             if an IO error occurs while connecting
-	 */
-	public void connect() throws IOException {
-		File f = new File(fileName);
-		if (f.isDirectory()) {
-			isDir = true;
-			is = getDirectoryListing(f);
-			// use -1 for the contentLength
-		} else {
-			is = new BufferedInputStream(new FileInputStream(f));
-			length = is.available();
-		}
-		connected = true;
-	}
-
-	/**
-	 * Answers the length of the file in bytes.
-	 * 
-	 * @return the length of the file
-	 * 
-	 * @see #getContentType()
-	 */
-	public int getContentLength() {
-		try {
-			if (!connected)
-				connect();
-		} catch (IOException e) {
-			// default is -1
-		}
-		return length;
-	}
-
-	/**
-	 * Answers the content type of the resource. Just takes a guess based on the
-	 * name.
-	 * 
-	 * @return the content type
-	 */
-	public String getContentType() {
-		try {
-			if (!connected)
-				connect();
-		} catch (IOException e) {
-			return MimeTable.UNKNOWN;
-		}
-		if (isDir)
-			return "text/html";
-		String result = guessContentTypeFromName(url.getFile());
-		if (result == null)
-			return MimeTable.UNKNOWN;
-		return result;
-	}
-
-	/**
-	 * Answers the directory listing of the file component as an input stream.
-	 * 
-	 * @return the input stream of the directory listing
-	 */
-	private InputStream getDirectoryListing(File f) {
-		String fileList[] = f.list();
-		ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
-		PrintStream out = new PrintStream(bytes);
-		out.print("<title>Directory Listing</title>\n");
-		out.print("<base href=\"file:");
-		out.print(f.getPath().replace('\\', '/') + "/\"><h1>" + f.getPath()
-				+ "</h1>\n<hr>\n");
-		int i;
-		for (i = 0; i < fileList.length; i++)
-			out.print(fileList[i] + "<br>\n");
-		out.close();
-		return new ByteArrayInputStream(bytes.toByteArray());
-	}
-
-	/**
-	 * Answers the input stream of the object refered to by this
-	 * <code>URLConnection</code>
-	 * 
-	 * File Sample : "/ZIP211/+/ibm/tools/javac/resources/javac.properties"
-	 * Invalid File Sample: "/ZIP/+/ibm/tools/javac/resources/javac.properties"
-	 * "ZIP211/+/ibm/tools/javac/resources/javac.properties"
-	 * 
-	 * @return input stream of the object
-	 * 
-	 * @throws IOException
-	 *             if an IO error occurs
-	 */
-	public InputStream getInputStream() throws IOException {
-		if (!connected)
-			connect();
-		return is;
-	}
-
-	/**
-	 * Answers the permission, in this case the subclass, FilePermission object
-	 * which represents the permission necessary for this URLConnection to
-	 * establish the connection.
-	 * 
-	 * @return the permission required for this URLConnection.
-	 * 
-	 * @exception IOException
-	 *                if an IO exception occurs while creating the permission.
-	 */
-	public java.security.Permission getPermission() throws IOException {
-		if (permission == null) {
-			String path = fileName;
-			if (File.separatorChar != '/')
-				path = path.replace('/', File.separatorChar);
-			permission = new FilePermission(path, new String("read"));
-		}
-		return permission;
-	}
+    private FilePermission permission;
+
+    /**
+     * Creates an instance of <code>FileURLConnection</code> for establishing
+     * a connection to the file pointed by this <code>URL<code>
+     *
+     * @param url The URL this connection is connected to
+     */
+    public FileURLConnection(URL url) {
+        super(url);
+        if ((fileName = url.getFile()) == null) {
+            fileName = "";
+        }
+        String host = url.getHost();
+        if (host != null && host.length() > 0) {
+            fileName = "//" + host + fileName;
+        }
+        fileName = Util.decode(fileName, false);
+    }
+
+    /**
+     * This methods will attempt to obtain the input stream of the file pointed
+     * by this <code>URL</code>. If the file is a directory, it will return
+     * that directory listing as an input stream.
+     * 
+     * @throws IOException if an IO error occurs while connecting
+     */
+    @Override
+    public void connect() throws IOException {
+        File f = new File(fileName);
+        if (f.isDirectory()) {
+            isDir = true;
+            is = getDirectoryListing(f);
+            // use -1 for the contentLength
+        } else {
+            is = new BufferedInputStream(new FileInputStream(f));
+            length = is.available();
+        }
+        connected = true;
+    }
+
+    /**
+     * Answers the length of the file in bytes.
+     * 
+     * @return the length of the file
+     * 
+     * @see #getContentType()
+     */
+    @Override
+    public int getContentLength() {
+        try {
+            if (!connected) {
+                connect();
+            }
+        } catch (IOException e) {
+            // default is -1
+        }
+        return length;
+    }
+
+    /**
+     * Answers the content type of the resource. Just takes a guess based on the
+     * name.
+     * 
+     * @return the content type
+     */
+    @Override
+    public String getContentType() {
+        try {
+            if (!connected) {
+                connect();
+            }
+        } catch (IOException e) {
+            return MimeTable.UNKNOWN;
+        }
+        if (isDir) {
+            return "text/html";
+        }
+        String result = guessContentTypeFromName(url.getFile());
+        if (result == null) {
+            return MimeTable.UNKNOWN;
+        }
+        return result;
+    }
+
+    /**
+     * Answers the directory listing of the file component as an input stream.
+     * 
+     * @return the input stream of the directory listing
+     */
+    private InputStream getDirectoryListing(File f) {
+        String fileList[] = f.list();
+        ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
+        PrintStream out = new PrintStream(bytes);
+        out.print("<title>Directory Listing</title>\n");
+        out.print("<base href=\"file:");
+        out.print(f.getPath().replace('\\', '/') + "/\"><h1>" + f.getPath() + "</h1>\n<hr>\n");
+        int i;
+        for (i = 0; i < fileList.length; i++) {
+            out.print(fileList[i] + "<br>\n");
+        }
+        out.close();
+        return new ByteArrayInputStream(bytes.toByteArray());
+    }
+
+    /**
+     * Answers the input stream of the object referred to by this
+     * <code>URLConnection</code>
+     * 
+     * File Sample : "/ZIP211/+/harmony/tools/javac/resources/javac.properties"
+     * Invalid File Sample:
+     * "/ZIP/+/harmony/tools/javac/resources/javac.properties"
+     * "ZIP211/+/harmony/tools/javac/resources/javac.properties"
+     * 
+     * @return input stream of the object
+     * 
+     * @throws IOException if an IO error occurs
+     */
+    @Override
+    public InputStream getInputStream() throws IOException {
+        if (!connected) {
+            connect();
+        }
+        return is;
+    }
+
+    /**
+     * Answers the permission, in this case the subclass, FilePermission object
+     * which represents the permission necessary for this URLConnection to
+     * establish the connection.
+     * 
+     * @return the permission required for this URLConnection.
+     * 
+     * @throws IOException if an IO exception occurs while creating the
+     *         permission.
+     */
+    @Override
+    public java.security.Permission getPermission() throws IOException {
+        if (permission == null) {
+            String path = fileName;
+            if (File.separatorChar != '/') {
+                path = path.replace('/', File.separatorChar);
+            }
+            permission = new FilePermission(path, new String("read"));
+        }
+        return permission;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java?view=diff&rev=440814&r1=440813&r2=440814
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
Wed Sep  6 11:11:38 2006
@@ -15,11 +15,11 @@
 
 package org.apache.harmony.luni.internal.net.www.protocol.file;
 
-
 import java.io.IOException;
 import java.net.Proxy;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.URLStreamHandler;
 
 import org.apache.harmony.luni.util.Msg;
 
@@ -27,75 +27,65 @@
  * This is the handler that is responsible for reading files from the file
  * system.
  */
+public class Handler extends URLStreamHandler {
 
-public class Handler extends java.net.URLStreamHandler {
-
-	/**
-	 * Answers a connection to the a file pointed by this <code>URL</code> in
-	 * the file system
-	 * 
-	 * @return java.net.URLConnection A connection to the resource pointed by
-	 *         this url.
-	 * @param url
-	 *            java.net.URL The URL to which the connection is pointing to
-	 * 
-	 */
-	public URLConnection openConnection(URL url) {
-		return new FileURLConnection(url);
-	}
-	
-	/**
-	 * The behaviour of this method is the same as openConnection(URL).
-	 * <code>proxy</code> is not used in FileURLConnection.
-	 * 
-	 * @param u
-	 *            the URL which the connection is pointing to
-	 * @param proxy
-	 *            java.net.Proxy
-	 * @return a connection to the resource pointed by this url.
-	 * 
-	 * @throws IOException
-	 *             if this handler fails to establish a connection.
-	 * @throws IllegalArgumentException
-	 *             if any argument is null or of an invalid type.
-	 * @throws UnsupportedOperationException
-	 *             if the protocol handler doesn't support this method.
-	 */
-
-	public URLConnection openConnection(URL url, Proxy proxy)
-			throws IOException {
-		if (null == url || null == proxy) {
-			throw new IllegalArgumentException(Msg.getString("K034b"));
-		}
-		return new FileURLConnection(url);
-	}
-
-	/**
-	 * Parse the <code>string</code>str into <code>URL</code> u which
-	 * already have the context properties. The string generally have the
-	 * following format: <code><center>/c:/windows/win.ini</center></code>.
-	 * 
-	 * @param u
-	 *            java.net.URL The URL object that's parsed into
-	 * @param str
-	 *            java.lang.String The string equivalent of the specification
-	 *            URL
-	 * @param start
-	 *            int The index in the spec string from which to begin parsing
-	 * @param end
-	 *            int The index to stop parsing
-	 * 
-	 * @see java.net.URLStreamHandler#toExternalForm(URL)
-	 * @see java.net.URL
-	 */
-	protected void parseURL(URL u, String str, int start, int end) {
-		if (end < start) {
-			return;
-		}
-		String parseString = "";
-		if (start < end) {
-			parseString = str.substring(start, end).replace('\\', '/');
-		}
-		super.parseURL(u, parseString, 0, parseString.length());
-	}
+    /**
+     * Answers a connection to the a file pointed by this <code>URL</code> in
+     * the file system
+     * 
+     * @return A connection to the resource pointed by this url.
+     * @param url URL The URL to which the connection is pointing to
+     * 
+     */
+    @Override
+    public URLConnection openConnection(URL url) {
+        return new FileURLConnection(url);
+    }
+
+    /**
+     * The behaviour of this method is the same as openConnection(URL).
+     * <code>proxy</code> is not used in FileURLConnection.
+     * 
+     * @param u the URL which the connection is pointing to
+     * @param proxy Proxy
+     * @return a connection to the resource pointed by this url.
+     * 
+     * @throws IOException if this handler fails to establish a connection.
+     * @throws IllegalArgumentException if any argument is null or of an invalid
+     *         type.
+     * @throws UnsupportedOperationException if the protocol handler doesn't
+     *         support this method.
+     */
+    @Override
+    public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
+        if (null == url || null == proxy) {
+            throw new IllegalArgumentException(Msg.getString("K034b"));
+        }
+        return new FileURLConnection(url);
+    }
+
+    /**
+     * Parse the <code>string</code>str into <code>URL</code> u which
+     * already have the context properties. The string generally have the
+     * following format: <code><center>/c:/windows/win.ini</center></code>.
+     * 
+     * @param u The URL object that's parsed into
+     * @param str The string equivalent of the specification URL
+     * @param start The index in the spec string from which to begin parsing
+     * @param end The index to stop parsing
+     * 
+     * @see java.net.URLStreamHandler#toExternalForm(URL)
+     * @see java.net.URL
+     */
+    @Override
+    protected void parseURL(URL u, String str, int start, int end) {
+        if (end < start) {
+            return;
+        }
+        String parseString = "";
+        if (start < end) {
+            parseString = str.substring(start, end).replace('\\', '/');
+        }
+        super.parseURL(u, parseString, 0, parseString.length());
+    }
 }



Mime
View raw message