summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2018-01-15 06:21:23 +0100
committerSven Gothel <[email protected]>2018-01-15 06:21:23 +0100
commit99b357956e4fd516ddd051d8a0f478c47faa40b1 (patch)
treec7b17177fb0d423213fd29379343455e573a0e8d /src/java/com/jogamp/common
parentf357ff4b1be9088c9e9cf6aa891204fc3cd4040a (diff)
MappedByteBufferInputStream: Add flushSlices() to release mapped slices to save mapped ByteBuffer memory
Also: - fix dbgDump(..) FileChannel access, test if openend. - add DEBUG dumps on CTOR, Close and notifyLengthChangeImpl
Diffstat (limited to 'src/java/com/jogamp/common')
-rw-r--r--src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java b/src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java
index dbd3941..6a56d6e 100644
--- a/src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java
+++ b/src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java
@@ -184,10 +184,12 @@ public class MappedByteBufferInputStream extends InputStream {
}
}
long fcSz = 0, pos = 0, rem = 0;
- try {
- fcSz = fc.size();
- } catch (final IOException e) {
- e.printStackTrace();
+ if( fc.isOpen() ) {
+ try {
+ fcSz = fc.size();
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
}
if( 0 < refCount ) {
try {
@@ -228,6 +230,10 @@ public class MappedByteBufferInputStream extends InputStream {
this.mark = -1;
currentSlice().position(0);
+
+ if( MappedByteBufferInputStream.DEBUG ) {
+ this.dbgDump("CTOR", System.err);
+ }
}
/**
@@ -321,6 +327,9 @@ public class MappedByteBufferInputStream extends InputStream {
}
}
}
+ if( MappedByteBufferInputStream.DEBUG ) {
+ this.dbgDump("Close", System.err);
+ }
}
final FileChannel.MapMode getMapMode() { return mmode; }
@@ -432,10 +441,9 @@ public class MappedByteBufferInputStream extends InputStream {
}
position2( Math.min(prePosition, newTotalSize) ); // -> clipped position (set currSlice and re-map/-pos buffer)
}
- /* if( DEBUG ) {
- System.err.println("notifyLengthChange.X: "+slices[currSlice]);
- dbgDump("notifyLengthChange.X:", System.err);
- } */
+ if( MappedByteBufferInputStream.DEBUG ) {
+ this.dbgDump("NotifyLengthChange", System.err);
+ }
}
/**
@@ -542,6 +550,21 @@ public class MappedByteBufferInputStream extends InputStream {
}
}
+ /**
+ * Releases the mapped {@link ByteBuffer} slices.
+ * @throws IOException if a buffer slice operation failed.
+ */
+ public final synchronized void flushSlices() throws IOException {
+ if( null != slices ) {
+ for(int i=0; i<sliceCount; i++) {
+ flushSlice(i, synchronous);
+ }
+ }
+ if( MappedByteBufferInputStream.DEBUG ) {
+ this.dbgDump("FlushSlices", System.err);
+ }
+ }
+
synchronized void syncSlice(final ByteBuffer s) throws IOException {
syncSlice(s, synchronous);
}