src/jdk/nashorn/internal/objects/NativeArrayBuffer.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 

  28 import java.util.Arrays;
  29 import jdk.nashorn.internal.objects.annotations.Attribute;
  30 import jdk.nashorn.internal.objects.annotations.Constructor;
  31 import jdk.nashorn.internal.objects.annotations.Function;
  32 import jdk.nashorn.internal.objects.annotations.Getter;
  33 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  34 import jdk.nashorn.internal.runtime.JSType;
  35 import jdk.nashorn.internal.runtime.PropertyMap;
  36 import jdk.nashorn.internal.runtime.ScriptObject;
  37 import jdk.nashorn.internal.runtime.ScriptRuntime;
  38 
  39 @ScriptClass("ArrayBuffer")
  40 final class NativeArrayBuffer extends ScriptObject {
  41     private final byte[] buffer;
  42 
  43     // initialized by nasgen
  44     private static PropertyMap $nasgenmap$;
  45 
  46     static PropertyMap getInitialMap() {
  47         return $nasgenmap$;


 110     }
 111 
 112     /**
 113      * Clamp index into the range [0, length).
 114      */
 115     private static int clamp(final int index, final int length) {
 116         if (index < 0) {
 117             return 0;
 118         } else if (index > length) {
 119             return length;
 120         }
 121         return index;
 122     }
 123 
 124     public byte[] getByteArray() {
 125         return buffer;
 126     }
 127 
 128     public int getByteLength() {
 129         return buffer.length;












 130     }
 131 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.objects;
  27 
  28 import java.nio.ByteBuffer;
  29 import java.util.Arrays;
  30 import jdk.nashorn.internal.objects.annotations.Attribute;
  31 import jdk.nashorn.internal.objects.annotations.Constructor;
  32 import jdk.nashorn.internal.objects.annotations.Function;
  33 import jdk.nashorn.internal.objects.annotations.Getter;
  34 import jdk.nashorn.internal.objects.annotations.ScriptClass;
  35 import jdk.nashorn.internal.runtime.JSType;
  36 import jdk.nashorn.internal.runtime.PropertyMap;
  37 import jdk.nashorn.internal.runtime.ScriptObject;
  38 import jdk.nashorn.internal.runtime.ScriptRuntime;
  39 
  40 @ScriptClass("ArrayBuffer")
  41 final class NativeArrayBuffer extends ScriptObject {
  42     private final byte[] buffer;
  43 
  44     // initialized by nasgen
  45     private static PropertyMap $nasgenmap$;
  46 
  47     static PropertyMap getInitialMap() {
  48         return $nasgenmap$;


 111     }
 112 
 113     /**
 114      * Clamp index into the range [0, length).
 115      */
 116     private static int clamp(final int index, final int length) {
 117         if (index < 0) {
 118             return 0;
 119         } else if (index > length) {
 120             return length;
 121         }
 122         return index;
 123     }
 124 
 125     public byte[] getByteArray() {
 126         return buffer;
 127     }
 128 
 129     public int getByteLength() {
 130         return buffer.length;
 131     }
 132 
 133     ByteBuffer getBuffer() {
 134        return ByteBuffer.wrap(buffer);
 135     }
 136 
 137     ByteBuffer getBuffer(final int offset) {
 138         return ByteBuffer.wrap(buffer, offset, buffer.length - offset);
 139     }
 140 
 141     ByteBuffer getBuffer(final int offset, final int length) {
 142         return ByteBuffer.wrap(buffer, offset, length);
 143     }
 144 }