diff options
author | Sven Gothel <[email protected]> | 2014-10-03 03:12:42 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-10-03 03:12:42 +0200 |
commit | a7a3d5ab98ee0ad33fdef50bf081afeb8295ebe4 (patch) | |
tree | 8316bb60b02dfa3d1a61aed6640afeaaeab99c13 /src/junit/com/jogamp/common/util/TestIOUtil01.java | |
parent | 00a9ee70054872712017b5a14b19aa92068c8420 (diff) |
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.
-
Diffstat (limited to 'src/junit/com/jogamp/common/util/TestIOUtil01.java')
-rw-r--r-- | src/junit/com/jogamp/common/util/TestIOUtil01.java | 37 |
1 files changed, 25 insertions, 12 deletions
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<tsz; i++) { final byte b = (byte) (i%256); @@ -69,6 +71,12 @@ public class TestIOUtil01 extends JunitTracer { tout.close(); } + @AfterClass + public static void cleanup() { + final File tfile = new File(tfilename); + tfile.delete(); + } + @Test public void testCopyStream01Array() throws IOException { final URLConnection urlConn = IOUtil.getResource(this.getClass(), tfilename); @@ -109,21 +117,26 @@ public class TestIOUtil01 extends JunitTracer { Assert.assertNotNull(urlConn1); final File file2 = new File(tfilename2); - IOUtil.copyURLConn2File(urlConn1, file2); - final URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2); - Assert.assertNotNull(urlConn2); - - final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() ); - final ByteBuffer bb; + file2.deleteOnExit(); try { - bb = IOUtil.copyStream2ByteBuffer( bis ); + IOUtil.copyURLConn2File(urlConn1, file2); + final URLConnection urlConn2 = IOUtil.getResource(this.getClass(), tfilename2); + Assert.assertNotNull(urlConn2); + + final BufferedInputStream bis = new BufferedInputStream( urlConn2.getInputStream() ); + final ByteBuffer bb; + try { + bb = IOUtil.copyStream2ByteBuffer( bis ); + } finally { + IOUtil.close(bis, false); + } + 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); } 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 { |