openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r431627 - /incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
Date Tue, 15 Aug 2006 15:57:15 GMT
Author: awhite
Date: Tue Aug 15 08:57:14 2006
New Revision: 431627

URL: http://svn.apache.org/viewvc?rev=431627&view=rev
Log:
Work around JVMs that don't return a valid value for File.length().  We've
discovered at least one that doesn't.


Modified:
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java?rev=431627&r1=431626&r2=431627&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
Tue Aug 15 08:57:14 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.openjpa.lib.meta;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -134,14 +135,24 @@
 
         public byte[] getContent() throws IOException {
             long len = _file.length();
-            if (len <= 0)
-                return new byte[0];
-
-            byte[] content = new byte[(int) len];
             FileInputStream fin = new FileInputStream(_file);
-            fin.read(content);
-            fin.close();
-            return content;
+            try {
+                byte[] content;
+                if (len <= 0 || len > Integer.MAX_VALUE) {
+                    // some JVMs don't return a proper length
+                    ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                    byte[] buf = new byte[1024]; 
+                    for (int r; (r = fin.read(buf)) != -1;)
+                        bout.write(buf, 0, r);
+                    content = bout.toByteArray();
+                } else {
+                    content = new byte[(int) len];
+                    fin.read(content);
+                }
+                return content;
+            } finally {
+                try { fin.close(); } catch (IOException ioe) {}
+            }
         }
     }
 }



Mime
View raw message