Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 34219 invoked from network); 23 Apr 2007 20:37:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Apr 2007 20:37:53 -0000 Received: (qmail 25302 invoked by uid 500); 23 Apr 2007 20:38:00 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 25235 invoked by uid 500); 23 Apr 2007 20:38:00 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 25226 invoked by uid 99); 23 Apr 2007 20:38:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Apr 2007 13:38:00 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Apr 2007 13:37:52 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 974121A9838; Mon, 23 Apr 2007 13:37:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r531591 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java test/java/tests/api/java/net/JarURLConnectionTest.java Date: Mon, 23 Apr 2007 20:37:32 -0000 To: commits@harmony.apache.org From: ayza@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070423203732.974121A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ayza Date: Mon Apr 23 13:37:31 2007 New Revision: 531591 URL: http://svn.apache.org/viewvc?view=rev&rev=531591 Log: The patch from HARMONY-3665 ([classlib][archive][netbeans] JarURLConnection.getContentLength() returns -1 instead of file size) was applied Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java?view=diff&rev=531591&r1=531590&r2=531591 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java Mon Apr 23 13:37:31 2007 @@ -354,39 +354,63 @@ } /** - * Answers the content type of the resource. Test cases reveal that only if - * the URL is refering to a Jar file, that this method answers a non-null - * value - x-java/jar. + * Answers the content type of the resource. + * For jar file itself "x-java/jar" should be returned, + * for jar entries the content type of the entry should be returned. + * Returns non-null results ("content/unknown" for unknown types). * * @return the content type */ @Override public String getContentType() { - // it could also return "x-java/jar" which jdk returns but here, we get - // it from the URLConnection - try { - if (url.getFile().endsWith("!/")) { //$NON-NLS-1$ - return getJarFileURL().openConnection().getContentType(); + if (url.getFile().endsWith("!/")) { //$NON-NLS-1$ + // the type for jar file itself is always "x-java/jar" + return "x-java/jar"; //$NON-NLS-1$ + } else { + String cType = null; + String entryName = getEntryName(); + + if (entryName != null) { + // if there is an Jar Entry, get the content type from the name + cType = guessContentTypeFromName(entryName); + } else { + try { + if (!connected) { + connect(); + } + + cType = jarFileURLConnection.getContentType(); + } catch (IOException ioe) { + // Ignore + } } - } catch (IOException ioe) { - // Ignore + + if (cType == null) { + cType = "content/unknown"; //$NON-NLS-1$ + } + return cType; } - // if there is an Jar Entry, get the content type from the name - return guessContentTypeFromName(url.getFile()); } /** * Answers the content length of the resource. Test cases reveal that if the * URL is refering to a Jar file, this method answers a content-length - * returned by URLConnection. If not, it will return -1. + * returned by URLConnection. For jar entry it should return it's size. + * Otherwise, it will return -1. * * @return the content length */ @Override public int getContentLength() { try { - if (url.getFile().endsWith("!/")) { //$NON-NLS-1$ - return getJarFileURL().openConnection().getContentLength(); + if (!connected) { + connect(); + } + + if (jarEntry == null) { + return jarFileURLConnection.getContentLength(); + } else { + return (int) getJarEntry().getSize(); } } catch (IOException e) { //Ignored Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java?view=diff&rev=531591&r1=531590&r2=531591 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/JarURLConnectionTest.java Mon Apr 23 13:37:31 2007 @@ -272,6 +272,48 @@ assertNull(juc.getCertificates()); } + /** + * @tests java.net.JarURLConnection#getContentLength() + * Regression test for HARMONY-3665 + */ + public void test_getContentLength() throws Exception { + // check length for jar file itself + URL u = new URL("jar:" + + BASE.toString()+"/lf.jar!/"); + assertEquals("Returned incorrect size for jar file", 33095, + u.openConnection().getContentLength()); + + // check length for jar entry + u = new URL("jar:" + + BASE.toString()+"/lf.jar!/plus.bmp"); + assertEquals("Returned incorrect size for the entry", 190, + u.openConnection().getContentLength()); + } + + /** + * @tests java.net.JarURLConnection#getContentType() + * Regression test for HARMONY-3665 + */ + public void test_getContentType() throws Exception { + // check type for jar file itself + URL u = new URL("jar:" + + BASE.toString()+"/lf.jar!/"); + assertEquals("Returned incorrect type for jar file", "x-java/jar", + u.openConnection().getContentType()); + + // check type for jar entry with known type + u = new URL("jar:" + + BASE.toString()+"/lf.jar!/plus.bmp"); + assertEquals("Returned incorrect type for the entry with known type", + "image/bmp", u.openConnection().getContentType()); + + // check type for jar entry with unknown type + u = new URL("jar:" + + BASE.toString()+"/lf.jar!/Manifest.mf"); + assertEquals("Returned incorrect type for the entry with known type", + "content/unknown", u.openConnection().getContentType()); + } + protected void setUp() { }