From c34b2ea222f9405c43769fe221f65ae25bf28bf1 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 28 Sep 2014 17:24:45 +0200 Subject: [PATCH] Fixed Long.Max_Value wrap around bug --- Dorkbox-Util/src/dorkbox/util/storage/StorageBase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dorkbox-Util/src/dorkbox/util/storage/StorageBase.java b/Dorkbox-Util/src/dorkbox/util/storage/StorageBase.java index b64e027..9264eb2 100644 --- a/Dorkbox-Util/src/dorkbox/util/storage/StorageBase.java +++ b/Dorkbox-Util/src/dorkbox/util/storage/StorageBase.java @@ -258,7 +258,7 @@ public class StorageBase { } return readRecordData; - } catch (IOException e) { + } catch (Exception e) { this.logger.error("Error while geting data from disk", e); return null; } @@ -345,7 +345,7 @@ public class StorageBase { if (this.memoryIndex.size() == 1) { // if we are the ONLY one, then we can do things differently. // just dump the data agian to disk. - FileLock lock = this.file.getChannel().lock(this.dataPosition, Long.MAX_VALUE, false); // don't know how big it is, so max value it + FileLock lock = this.file.getChannel().lock(this.dataPosition, Long.MAX_VALUE-this.dataPosition, false); // don't know how big it is, so max value it this.file.seek(this.dataPosition); // this is the end of the file, we know this ahead-of-time metaData.writeDataFast(this.kryo, object, fileOutputStream); lock.release(); @@ -435,7 +435,7 @@ public class StorageBase { private void deleteRecordData(Metadata deletedRecord) throws IOException { if (this.file.length() == deletedRecord.dataPointer + deletedRecord.dataCapacity) { // shrink file since this is the last record in the file - FileLock lock = this.file.getChannel().lock(deletedRecord.dataPointer, Long.MAX_VALUE, false); + FileLock lock = this.file.getChannel().lock(deletedRecord.dataPointer, Long.MAX_VALUE-deletedRecord.dataPointer, false); this.file.setLength(deletedRecord.dataPointer); lock.release(); } else {