From 7aa4fa12f2eb73e9e9c3a57d1c96e1215eb180a6 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 26 Aug 2012 15:23:45 -0500 Subject: [PATCH] Modified readBytes() and writeBytes() methods in DiscUtil.java to use older file handling routines which don't require Java 7. The vastly improved file loading speed which came from Olof's recent update to this file has been retained. --- .../factions/zcore/util/DiscUtil.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/com/massivecraft/factions/zcore/util/DiscUtil.java b/src/com/massivecraft/factions/zcore/util/DiscUtil.java index 024e9864..b9ecc0a6 100644 --- a/src/com/massivecraft/factions/zcore/util/DiscUtil.java +++ b/src/com/massivecraft/factions/zcore/util/DiscUtil.java @@ -4,7 +4,6 @@ import java.io.*; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; -import java.nio.file.Files; public class DiscUtil { @@ -20,12 +19,24 @@ public class DiscUtil public static byte[] readBytes(File file) throws IOException { - return Files.readAllBytes(file.toPath()); + int length = (int) file.length(); + byte[] output = new byte[length]; + InputStream in = new FileInputStream(file); + int offset = 0; + // normally it should be able to read the entire file with just a single iteration below, but it depends on the whims of the FileInputStream + while (offset < length) + { + offset += in.read(output, offset, (length - offset)); + } + in.close(); + return output; } public static void writeBytes(File file, byte[] bytes) throws IOException { - Files.write(file.toPath(), bytes); + FileOutputStream out = new FileOutputStream(file); + out.write(bytes); + out.close(); } // -------------------------------------------- // @@ -82,8 +93,8 @@ public class DiscUtil URL url = new URL(urlstring); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); - fos.getChannel().transferFrom(rbc, 0, 1 << 24); - return true; + fos.getChannel().transferFrom(rbc, 0, 1 << 24); + return true; } catch (Exception e) {