From c7b90f61f7653c7cf99a51c342604d04490aff8e Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 5 Aug 2012 19:41:06 +0200 Subject: Try to fix interrupt problem. --- .../com/earth2me/essentials/EssentialsConf.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index b2cb1fd12..97f4182cb 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -5,6 +5,7 @@ import com.google.common.io.Files; import java.io.*; import java.nio.ByteBuffer; import java.nio.CharBuffer; +import java.nio.channels.ClosedByInterruptException; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; @@ -117,7 +118,30 @@ public class EssentialsConf extends YamlConfiguration { final FileChannel channel = inputStream.getChannel(); final ByteBuffer buffer = ByteBuffer.allocate((int)configFile.length()); - channel.read(buffer); + boolean retry; + do + { + try + { + int BUFFERSIZE = 1024; + long left = configFile.length() % BUFFERSIZE; + for (long i = 0; i < configFile.length() - left; i += BUFFERSIZE) + { + channel.read(buffer, BUFFERSIZE); + } + if (left > 0) + { + channel.read(buffer, left); + } + retry = false; + } + catch (ClosedByInterruptException ex) + { + buffer.rewind(); + retry = true; + } + } + while (retry); buffer.rewind(); final CharBuffer data = CharBuffer.allocate((int)configFile.length()); CharsetDecoder decoder = UTF8.newDecoder(); -- cgit v1.2.3