diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/jogamp/common/nio/MappedByteBufferInputStream.java | 39 |
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); } |