mirror of https://github.com/apache/openjpa.git
Work around JVMs that don't return a valid value for File.length(). We've
discovered at least one that doesn't. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@431627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26ae2fa31c
commit
0821efea40
|
@ -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 class FileMetaDataIterator implements MetaDataIterator {
|
|||
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue