LWJGLInstaller: Exceptions should propagate to ease debugging

This commit is contained in:
Elias Naur 2006-07-04 12:20:17 +00:00
parent a2f398e507
commit e0268732b0
1 changed files with 15 additions and 22 deletions

View File

@ -172,8 +172,8 @@ public class LWJGLInstaller {
HashMap files = new HashMap(); HashMap files = new HashMap();
JarInputStream jis = new JarInputStream(is); JarInputStream jis = new JarInputStream(is);
JarEntry native_entry = null; JarEntry native_entry;
while((native_entry = jis.getNextJarEntry()) != null) { while ((native_entry = jis.getNextJarEntry()) != null) {
// skip directories and anything in directories // skip directories and anything in directories
// conveniently ignores the manifest // conveniently ignores the manifest
if(native_entry.isDirectory() || native_entry.getName().indexOf('/') != -1) { if(native_entry.isDirectory() || native_entry.getName().indexOf('/') != -1) {
@ -183,7 +183,7 @@ public class LWJGLInstaller {
// need to read the file, before the certificate is retrievable // need to read the file, before the certificate is retrievable
// since we dont want to do two reads, we store it in memory for later use // since we dont want to do two reads, we store it in memory for later use
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
copyFile(jis, baos, false); copyFile(jis, baos);
files.put(native_entry.getName(), baos.toByteArray()); files.put(native_entry.getName(), baos.toByteArray());
// now check the chain of an actual file // now check the chain of an actual file
@ -219,21 +219,17 @@ public class LWJGLInstaller {
* @param file File to extract * @param file File to extract
* @param path Path to extract to * @param path Path to extract to
*/ */
private static void writeFiles(final HashMap files, final String path) { private static void writeFiles(final HashMap files, final String path) throws Exception {
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() { public Object run() throws IOException {
try { for(Iterator i = files.keySet().iterator(); i.hasNext();) {
for(Iterator i = files.keySet().iterator(); i.hasNext();) { String key = (String) i.next();
String key = (String) i.next(); File out = new File(path + File.separator + key);
File out = new File(path + File.separator + key); out.createNewFile();
out.createNewFile(); InputStream is = new ByteArrayInputStream((byte[]) files.get(key));
InputStream is = new ByteArrayInputStream((byte[]) files.get(key)); OutputStream os = new BufferedOutputStream(new FileOutputStream(out));
OutputStream os = new BufferedOutputStream(new FileOutputStream(out)); copyFile(is, os);
copyFile(is, os, true); is.close();
}
} catch (IOException ioe) {
LWJGLUtil.log("Exception while extracting: " + ioe.getMessage());
return null;
} }
return null; return null;
} }
@ -246,15 +242,12 @@ public class LWJGLInstaller {
* @param os OutputStream to write to * @param os OutputStream to write to
* @throws IOException if the copy process fail in any way * @throws IOException if the copy process fail in any way
*/ */
private static void copyFile(InputStream is, OutputStream os, boolean closeInput) throws IOException { private static void copyFile(InputStream is, OutputStream os) throws IOException {
int len; int len;
while ((len = is.read(COPY_BUFFER)) > 0) { while ((len = is.read(COPY_BUFFER)) > 0) {
os.write(COPY_BUFFER, 0, len); os.write(COPY_BUFFER, 0, len);
} }
if(closeInput) {
is.close();
}
os.close(); os.close();
} }