< prev index next >

src/java.base/share/classes/java/nio/MappedByteBuffer.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -88,16 +88,10 @@
     MappedByteBuffer(int mark, int pos, int lim, int cap) { // package-private
         super(mark, pos, lim, cap);
         this.fd = null;
     }
 
-    private void checkMapped() {
-        if (fd == null)
-            // Can only happen if a luser explicitly casts a direct byte buffer
-            throw new UnsupportedOperationException();
-    }
-
     // Returns the distance (in bytes) of the buffer from the page aligned address
     // of the mapping. Computed each time to avoid storing in every direct buffer.
     private long mappingOffset() {
         int ps = Bits.pageSize();
         long offset = address % ps;

@@ -129,11 +123,13 @@
      *
      * @return  {@code true} if it is likely that this buffer's content
      *          is resident in physical memory
      */
     public final boolean isLoaded() {
-        checkMapped();
+        if (fd == null) {
+            return true;
+        }
         if ((address == 0) || (capacity() == 0))
             return true;
         long offset = mappingOffset();
         long length = mappingLength(offset);
         return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length));

@@ -151,11 +147,13 @@
      * occur. </p>
      *
      * @return  This buffer
      */
     public final MappedByteBuffer load() {
-        checkMapped();
+        if (fd == null) {
+            return this;
+        }
         if ((address == 0) || (capacity() == 0))
             return this;
         long offset = mappingOffset();
         long length = mappingLength(offset);
         load0(mappingAddress(offset), length);

@@ -195,11 +193,13 @@
      * method has no effect. </p>
      *
      * @return  This buffer
      */
     public final MappedByteBuffer force() {
-        checkMapped();
+        if (fd == null) {
+            return this;
+        }
         if ((address != 0) && (capacity() != 0)) {
             long offset = mappingOffset();
             force0(fd, mappingAddress(offset), mappingLength(offset));
         }
         return this;
< prev index next >