From 51c69eb031448810ed249fc0149c5158f8f21f98 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 11 Dec 2017 10:00:02 -0600 Subject: [PATCH 1/3] Revert "Make sure setLength is not called on a closed or read-only file" This reverts commit c2eebbdc06dbd67e056b1331bd313ae575da7bd9. --- src/main/java/loci/common/NIOFileHandle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/loci/common/NIOFileHandle.java b/src/main/java/loci/common/NIOFileHandle.java index bf291b8b..99f527ab 100644 --- a/src/main/java/loci/common/NIOFileHandle.java +++ b/src/main/java/loci/common/NIOFileHandle.java @@ -214,7 +214,7 @@ public void setLength(long length) throws IOException { /* @see IRandomAccess.close() */ @Override public void close() throws IOException { - if (isReadWrite && channel.isOpen() && raf.length() != length()) { + if (raf.length() != length()) { raf.setLength(length()); } raf.close(); From 5440f56a5550eadf4b933ad63a588fdcb9d9504c Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 11 Dec 2017 10:00:21 -0600 Subject: [PATCH 2/3] Revert "NIOFileHandle: reduce calls to RandomAccessFile.setLength" This reverts commit 4b947ea90c4cffe9e396afe7f14449c5508bf191. --- src/main/java/loci/common/NIOFileHandle.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/loci/common/NIOFileHandle.java b/src/main/java/loci/common/NIOFileHandle.java index 99f527ab..d370e588 100644 --- a/src/main/java/loci/common/NIOFileHandle.java +++ b/src/main/java/loci/common/NIOFileHandle.java @@ -105,8 +105,6 @@ public class NIOFileHandle extends AbstractNIOHandle { /** The original length of the file. */ private Long defaultLength; - private long effectiveLength; - // -- Constructors -- /** @@ -123,7 +121,6 @@ public NIOFileHandle(File file, String mode, int bufferSize) mapMode = FileChannel.MapMode.READ_WRITE; } raf = new RandomAccessFile(file, mode); - effectiveLength = raf.length(); channel = raf.getChannel(); byteBufferProvider = new NIOByteBufferProvider(channel, mapMode); buffer(position, 0); @@ -202,9 +199,8 @@ public int getBufferSize() { @Override public void setLength(long length) throws IOException { if (raf.length() < length) { - raf.setLength(length + getBufferSize()); + raf.setLength(length); } - effectiveLength = length; raf.seek(length - 1); buffer = null; } @@ -214,9 +210,6 @@ public void setLength(long length) throws IOException { /* @see IRandomAccess.close() */ @Override public void close() throws IOException { - if (raf.length() != length()) { - raf.setLength(length()); - } raf.close(); } @@ -232,7 +225,7 @@ public long length() throws IOException { if (defaultLength != null) { return defaultLength; } - return effectiveLength; + return raf.length(); } /* @see IRandomAccess.getOrder() */ From 409e34c73b9638a690bd3e0aec55fe12b3a568d1 Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Thu, 4 Jan 2018 15:59:58 +0000 Subject: [PATCH 3/3] Add entry to NEWS file for NIOFileHandle changes --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index 36f43f9c..7317e997 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +5.3.4 (2018-01-04) +------------------ + +- Revert 5.3.3 changes to RandomAccessFile.setLength in NIOFileHandle ([#21](https://github.com/ome/ome-common-java/pull/21)) + 5.3.3 (2017-10-20) ------------------