harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r935857 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/file/ test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/
Date Tue, 20 Apr 2010 10:09:25 GMT
Author: hindessm
Date: Tue Apr 20 10:09:25 2010
New Revision: 935857

URL: http://svn.apache.org/viewvc?rev=935857&view=rev
Log:
Reverting bad commit r935847.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java?rev=935857&r1=935856&r2=935857&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
Tue Apr 20 10:09:25 2010
@@ -28,9 +28,6 @@ import java.io.InputStream;
 import java.io.PrintStream;
 import java.net.URL;
 import java.net.URLConnection;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.LinkedHashMap;
 
 import org.apache.harmony.luni.internal.net.www.MimeTable;
 import org.apache.harmony.luni.util.Util;
@@ -51,12 +48,8 @@ public class FileURLConnection extends U
 
     private boolean isDir;
 
-    private long lastModified = 0;
-
     private FilePermission permission;
 
-    private LinkedHashMap<String, String> header;
-
     /**
      * Creates an instance of <code>FileURLConnection</code> for establishing
      * a connection to the file pointed by this <code>URL<code>
@@ -70,7 +63,6 @@ public class FileURLConnection extends U
             fileName = ""; //$NON-NLS-1$
         }
         fileName = Util.decode(fileName, false);
-        header = new LinkedHashMap<String, String>();
     }
 
     /**
@@ -84,90 +76,15 @@ public class FileURLConnection extends U
     @Override
     public void connect() throws IOException {
         File f = new File(fileName);
-        if (isDir = f.isDirectory()) {
+        if (f.isDirectory()) {
+            isDir = true;
             is = getDirectoryListing(f);
+            // use -1 for the contentLength
         } else {
             is = new BufferedInputStream(new FileInputStream(f));
             length = is.available();
-            lastModified = f.lastModified();
         }
         connected = true;
-        // updaetHeader must be after "connected = true", for updateHeader
-        // invokes getContentType which back invokes connect causing
-        // StackOverflow
-        updateHeader();
-    }
-
-    /**
-     * Function updates the header fields of a file.
-     */
-    private void updateHeader() {
-        String contentType = getContentType();
-        if (contentType != null) {
-            header.put("content-type", contentType); //$NON-NLS-1$
-        }
-        if (length >= 0) {
-            header.put("content-length", Integer.toString(length)); //$NON-NLS-1$
-        }
-        if (lastModified != 0) {
-            SimpleDateFormat dateFormat = new SimpleDateFormat(
-                    "EEE, dd MMM yyyy HH:mm:ss 'GMT'"); //$NON-NLS-1$
-            header.put("last-modified", dateFormat.format(new Date( //$NON-NLS-1$
-                    lastModified)));
-        }
-    }
-
-    @Override
-    public String getHeaderField(String key) {
-        try {
-            if (!connected) {
-                connect();
-            }
-        } catch (IOException e) {
-            // Ignored
-        }
-        return header.get(key);
-    }
-
-    @Override
-    public String getHeaderField(int index) {
-        try {
-            if (!connected) {
-                connect();
-            }
-        } catch (IOException e) {
-            // Ignored
-        }
-        if (index > -1 && index < header.size()) {
-            return header.values().toArray(new String[0])[index];
-        }
-        return null;
-    }
-
-    @Override
-    public String getHeaderFieldKey(int index) {
-        try {
-            if (!connected) {
-                connect();
-            }
-        } catch (IOException e) {
-            // Ignored
-        }
-        if (index > -1 && index < header.size()) {
-            return header.keySet().toArray(new String[0])[index];
-        }
-        return null;
-    }
-
-    public long getLastModified() {
-        try {
-            if (!connected) {
-                connect();
-            }
-        } catch (IOException e) {
-            // default is -1
-        }
-        return lastModified;
     }
 
     /**

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java?rev=935857&r1=935856&r2=935857&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/file/FileURLConnectionTest.java
Tue Apr 20 10:09:25 2010
@@ -18,7 +18,6 @@ package org.apache.harmony.luni.tests.in
 
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLConnection;
 
 import junit.framework.TestCase;
 
@@ -64,41 +63,4 @@ public class FileURLConnectionTest exten
         assertNotNull(conn.getInputStream());
         assertEquals("file",conn.getURL().getProtocol());
     }
-
-    public void testHeaderFunctions() throws IOException {
-        String resourceName = "org/apache/harmony/luni/tests/"; // folder name
-        URL url = ClassLoader.getSystemClassLoader().getResource(resourceName);
-        FileURLConnection conn = new FileURLConnection(url);
-        assertNotNull(conn.getInputStream());
-        assertEquals(conn.getContentType(), conn.getHeaderField("content-type"));
-
-        resourceName = "org/apache/harmony/luni/tests/" + "test.rtf";
-        ; // folder name
-        url = ClassLoader.getSystemClassLoader().getResource(resourceName);
-        conn = new FileURLConnection(url);
-        assertNotNull(conn.getInputStream());
-        assertEquals(conn.getContentType(), conn.getHeaderField("content-type"));
-        assertEquals(Integer.toString(conn.getContentLength()), conn
-                .getHeaderField("content-length"));
-        assertEquals(conn.getHeaderField(0), conn
-                .getHeaderField("content-type"));
-        assertEquals(conn.getHeaderField(1), conn
-                .getHeaderField("content-length"));
-        assertEquals(conn.getHeaderField(2), conn
-                .getHeaderField("last-modified"));
-        assertEquals("last-modified", conn.getHeaderFieldKey(2));
-        assertEquals("content-length", conn.getHeaderFieldKey(1));
-        assertEquals("content-type", conn.getHeaderFieldKey(0));
-    }
-
-    public void testHeader_BoundaryCheck() throws IOException {
-        String resourceName = "org/apache/harmony/luni/tests/";
-        URL url = ClassLoader.getSystemClassLoader().getResource(resourceName);
-        URLConnection urlConnection = url.openConnection();
-        assertNull(urlConnection.getHeaderField(Integer.MIN_VALUE));
-        assertNull(urlConnection.getHeaderField(Integer.MAX_VALUE));
-        assertNull(urlConnection.getHeaderFieldKey(Integer.MIN_VALUE));
-        assertNull(urlConnection.getHeaderFieldKey(Integer.MAX_VALUE));
-        assertNull(urlConnection.getHeaderField(null));
-    }
 }



Mime
View raw message