harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r620461 - /harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Date Mon, 11 Feb 2008 11:14:15 GMT
Author: apetrenko
Date: Mon Feb 11 03:14:08 2008
New Revision: 620461

URL: http://svn.apache.org/viewvc?rev=620461&view=rev
Log:
Patch for HARMONY-5473 "[classlib][archive] Manifest file with empty 
line proves IOException"

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?rev=620461&r1=620460&r2=620461&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Mon Feb 11 03:14:08 2008
@@ -67,7 +67,7 @@
         mainAttributesChunk = nextChunk(is, list);
 
         Iterator<String> it = list.iterator();
-        while (it.hasNext()) {
+        while (it.hasNext()) {             
             addAttribute(it.next(), current);
         }
 
@@ -109,7 +109,7 @@
         return mainAttributesChunk;
     }
 
-    private void addLine(int length, List<String> lines) throws IOException {
+    private void addLine(int length, List<String> lines) throws IOException {     
  
         if (encoding != null) {
             lines.add(new String(buffer, 0, length, encoding));
         } else {
@@ -118,7 +118,8 @@
                     if (charbuf.length < length) {
                         charbuf = new char[length];
                     }
-                    lines.add(Util.convertUTF8WithBuf(buffer, charbuf, 0,
+                    int start = skipFirstEmptyLines(0, buffer);
+                    lines.add(Util.convertUTF8WithBuf(buffer, charbuf, Math.min(Math.max(length
- 1, 0), start),
                             length));
                 } catch (UTFDataFormatException e) {
                     usingUTF8 = false;
@@ -135,9 +136,36 @@
                 for (int i = length; --i >= 0;) {
                     charbuf[charOffset++] = (char) (buffer[offset++] & 0xff);
                 }
-                lines.add(new String(charbuf, 0, length));
+                int start = skipFirstEmptyLines(0, buffer);
+                lines.add(new String(charbuf, Math.min(Math.max(length - 1, 0), start), length));
             }
         }
+    }
+
+    private int skipFirstEmptyLines(int start, byte[] buf) {
+        int res = start;
+        if (buf.length > start) {
+           if ((char)buf[res] == '\r') {
+              res ++;
+              if (res < buf.length) {     
+               if ((char)buf[res] == '\n') {
+                   res ++;  
+                   return skipFirstEmptyLines(res, buf);   
+               } else {
+                  return res; 
+               
+               } 
+              }
+              return res;
+           } else if ((char)buf[res] == '\n') {
+              res ++;  
+              return skipFirstEmptyLines(res, buf);   
+           } else {
+             return res;    
+           }                     
+            
+        }
+        return res;
     }
 
     private byte[] nextChunk(InputStream in, List<String> lines)



Mime
View raw message