From 8f428d9d451833592d317271beac4f9315c6c202 Mon Sep 17 00:00:00 2001 From: Frotty Date: Mon, 5 Jun 2017 15:04:30 +0200 Subject: [PATCH] ok really this time --- .../java/systems/crigges/jmpq3/JMpqEditor.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/systems/crigges/jmpq3/JMpqEditor.java b/src/main/java/systems/crigges/jmpq3/JMpqEditor.java index 7548c2b..eab89b6 100644 --- a/src/main/java/systems/crigges/jmpq3/JMpqEditor.java +++ b/src/main/java/systems/crigges/jmpq3/JMpqEditor.java @@ -4,7 +4,6 @@ import systems.crigges.jmpq3.BlockTable.Block; import java.io.*; -import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.MappedByteBuffer; @@ -253,13 +252,19 @@ private void setupTempDir() throws JMpqException { * Makes the archive readonly. */ private void loadDefaultListFile() throws IOException { - URL resource = getClass().getClassLoader().getResource("DefaultListfile.txt"); + InputStream resource = getClass().getClassLoader().getResourceAsStream("DefaultListfile.txt"); if (resource != null) { - Path defaultListfile = Paths.get("listfile"); - try (InputStream is = resource.openStream()) { - Files.copy(is, defaultListfile); + File tempFile = File.createTempFile("jmpq", "lf", tempDir); + tempFile.deleteOnExit(); + try (FileOutputStream out = new FileOutputStream(tempFile)) { + //copy stream + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = resource.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } } - listFile = new Listfile(Files.readAllBytes(defaultListfile)); + listFile = new Listfile(Files.readAllBytes(tempFile.toPath())); canWrite = false; } }