src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
changeset 53855 7c362992527a
parent 48356 29e165bdf669
child 53901 0448cb38c418
equal deleted inserted replaced
53854:792c8a5fbb29 53855:7c362992527a
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    36  * ReadOnlyBufferException} and overriding the view-buffer methods to return an
    36  * ReadOnlyBufferException} and overriding the view-buffer methods to return an
    37  * instance of this class rather than of the superclass.
    37  * instance of this class rather than of the superclass.
    38 #end[rw]
    38 #end[rw]
    39  */
    39  */
    40 
    40 
       
    41 import java.util.Objects;
       
    42 
    41 class Heap$Type$Buffer$RW$
    43 class Heap$Type$Buffer$RW$
    42     extends {#if[ro]?Heap}$Type$Buffer
    44     extends {#if[ro]?Heap}$Type$Buffer
    43 {
    45 {
    44     // Cached array base offset
    46     // Cached array base offset
    45     private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
    47     private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
   176         checkBounds(offset, length, dst.length);
   178         checkBounds(offset, length, dst.length);
   177         if (length > remaining())
   179         if (length > remaining())
   178             throw new BufferUnderflowException();
   180             throw new BufferUnderflowException();
   179         System.arraycopy(hb, ix(position()), dst, offset, length);
   181         System.arraycopy(hb, ix(position()), dst, offset, length);
   180         position(position() + length);
   182         position(position() + length);
       
   183         return this;
       
   184     }
       
   185 
       
   186     public $Type$Buffer get(int index, $type$[] dst, int offset, int length) {
       
   187         Objects.checkFromIndexSize(index, length, limit());
       
   188         Objects.checkFromIndexSize(offset, length, dst.length);
       
   189         System.arraycopy(hb, ix(index), dst, offset, length);
   181         return this;
   190         return this;
   182     }
   191     }
   183 
   192 
   184     public boolean isDirect() {
   193     public boolean isDirect() {
   185         return false;
   194         return false;
   248 #else[rw]
   257 #else[rw]
   249         throw new ReadOnlyBufferException();
   258         throw new ReadOnlyBufferException();
   250 #end[rw]
   259 #end[rw]
   251     }
   260     }
   252 
   261 
       
   262     public $Type$Buffer put(int index, $type$[] src, int offset, int length) {
       
   263 #if[rw]
       
   264         Objects.checkFromIndexSize(index, length, limit());
       
   265         Objects.checkFromIndexSize(offset, length, src.length);
       
   266         System.arraycopy(src, offset, hb, ix(index), length);
       
   267         return this;
       
   268 #else[rw]
       
   269         throw new ReadOnlyBufferException();
       
   270 #end[rw]
       
   271     }
       
   272 
   253     public $Type$Buffer compact() {
   273     public $Type$Buffer compact() {
   254 #if[rw]
   274 #if[rw]
   255         System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
   275         System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
   256         position(remaining());
   276         position(remaining());
   257         limit(capacity());
   277         limit(capacity());