From a7a3d5ab98ee0ad33fdef50bf081afeb8295ebe4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 3 Oct 2014 03:12:42 +0200 Subject: MappedByteBuffer*Stream: - Validate active and GC'ed mapped-buffer count in cleanAllSlices() via close() .. - Fix missing unmapping last buffer in notifyLengthChangeImpl(), branch criteria was off by one. - cleanSlice(..) now also issues cleanBuffer(..) on the GC'ed entry, hence if WeakReference is still alive, enforce it's release. - cleanBuffer(..) reverts FLUSH_PRE_HARD -> FLUSH_PRE_SOFT in case of an error. - flush() -> flush(boolean metaData) to expose FileChannel.force(metaData). - Add synchronous mode, flushing/syncing the mapped buffers when in READ_WRITE mapping mode and issue FileChannel.force() if not READ_ONLY. Above is implemented via flush()/flushImpl(..) for buffers and FileChannel, as well as in syncSlice(..) for buffers only. flush*()/syncSlice() is covered by: - setLength() - notifyLengthChange*(..) - nextSlice() Always issue flushImpl() in close(). - Windows: Clean all buffers in setLength(), otherwise Windows will report: - Windows: Catch MappedByteBuffer.force() IOException - Optimization of position(..) position(..) is now standalone to allow issuing flushSlice(..) before gathering the new mapped buffer. This shall avoid one extra cache miss. Hence rename positionImpl(..) -> position2(..). - All MappedByteBufferOutputStream.write(..) methods issue syncSlice(..) on the last written current slice to ensure new 'synchronous' mode is honored. +++ Unit tests: - Ensure test files are being deleted - TestByteBufferCopyStream: Reduced test file size to more sensible values. - --- src/junit/com/jogamp/common/util/TestIOUtil01.java | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/junit/com/jogamp/common/util/TestIOUtil01.java') diff --git a/src/junit/com/jogamp/common/util/TestIOUtil01.java b/src/junit/com/jogamp/common/util/TestIOUtil01.java index 2a9c857..68f472f 100644 --- a/src/junit/com/jogamp/common/util/TestIOUtil01.java +++ b/src/junit/com/jogamp/common/util/TestIOUtil01.java @@ -38,6 +38,7 @@ import java.io.OutputStream; import java.net.URLConnection; import java.nio.ByteBuffer; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -60,6 +61,7 @@ public class TestIOUtil01 extends JunitTracer { @BeforeClass public static void setup() throws IOException { final File tfile = new File(tfilename); + tfile.deleteOnExit(); final OutputStream tout = new BufferedOutputStream(new FileOutputStream(tfile)); for(int i=0; i=0 && orig[i]==bb.get(i); i--) ; + Assert.assertTrue("Bytes not equal orig vs array", 0>i); } finally { - IOUtil.close(bis, false); + file2.delete(); } - Assert.assertEquals("Byte number not equal orig vs buffer", orig.length, bb.limit()); - int i; - for(i=tsz-1; i>=0 && orig[i]==bb.get(i); i--) ; - Assert.assertTrue("Bytes not equal orig vs array", 0>i); } public static void main(final String args[]) throws IOException { -- cgit v1.2.3