< prev index next >

src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template

Print this page


   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   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 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 

  30 import jdk.internal.misc.Unsafe;
  31 
  32 
  33 class ByteBufferAs$Type$Buffer$RW$$BO$                  // package-private
  34     extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
  35 {
  36 
  37 #if[rw]
  38 
  39     protected final ByteBuffer bb;
  40 
  41 #end[rw]
  42 
  43     ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) {   // package-private
  44 #if[rw]
  45         super(-1, 0,
  46               bb.remaining() >> $LG_BYTES_PER_VALUE$,
  47               bb.remaining() >> $LG_BYTES_PER_VALUE$);
  48         this.bb = bb;
  49         // enforce limit == capacity
  50         int cap = this.capacity();
  51         this.limit(cap);
  52         int pos = this.position();


  68         assert address >= bb.address;
  69 #else[rw]
  70         super(bb, mark, pos, lim, cap, addr);
  71 #end[rw]
  72     }
  73 
  74     @Override
  75     Object base() {
  76         return bb.hb;
  77     }
  78 
  79     public $Type$Buffer slice() {
  80         int pos = this.position();
  81         int lim = this.limit();
  82         assert (pos <= lim);
  83         int rem = (pos <= lim ? lim - pos : 0);
  84         long addr = byteOffset(pos);
  85         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
  86     }
  87 











  88     public $Type$Buffer duplicate() {
  89         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
  90                                                     this.markValue(),
  91                                                     this.position(),
  92                                                     this.limit(),
  93                                                     this.capacity(),
  94                                                     address);
  95     }
  96 
  97     public $Type$Buffer asReadOnlyBuffer() {
  98 #if[rw]
  99         return new ByteBufferAs$Type$BufferR$BO$(bb,
 100                                                  this.markValue(),
 101                                                  this.position(),
 102                                                  this.limit(),
 103                                                  this.capacity(),
 104                                                  address);
 105 #else[rw]
 106         return duplicate();
 107 #end[rw]


   1 /*
   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.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   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 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 
  30 import java.util.Objects;
  31 import jdk.internal.misc.Unsafe;
  32 

  33 class ByteBufferAs$Type$Buffer$RW$$BO$                  // package-private
  34     extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
  35 {
  36 
  37 #if[rw]
  38 
  39     protected final ByteBuffer bb;
  40 
  41 #end[rw]
  42 
  43     ByteBufferAs$Type$Buffer$RW$$BO$(ByteBuffer bb) {   // package-private
  44 #if[rw]
  45         super(-1, 0,
  46               bb.remaining() >> $LG_BYTES_PER_VALUE$,
  47               bb.remaining() >> $LG_BYTES_PER_VALUE$);
  48         this.bb = bb;
  49         // enforce limit == capacity
  50         int cap = this.capacity();
  51         this.limit(cap);
  52         int pos = this.position();


  68         assert address >= bb.address;
  69 #else[rw]
  70         super(bb, mark, pos, lim, cap, addr);
  71 #end[rw]
  72     }
  73 
  74     @Override
  75     Object base() {
  76         return bb.hb;
  77     }
  78 
  79     public $Type$Buffer slice() {
  80         int pos = this.position();
  81         int lim = this.limit();
  82         assert (pos <= lim);
  83         int rem = (pos <= lim ? lim - pos : 0);
  84         long addr = byteOffset(pos);
  85         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
  86     }
  87 
  88     @Override
  89     public $Type$Buffer slice(int index, int length) {
  90         Objects.checkFromIndexSize(index, length, limit());
  91         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
  92                                                     -1,
  93                                                     0,
  94                                                     length,
  95                                                     length,
  96                                                     byteOffset(index));
  97     }
  98 
  99     public $Type$Buffer duplicate() {
 100         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
 101                                                     this.markValue(),
 102                                                     this.position(),
 103                                                     this.limit(),
 104                                                     this.capacity(),
 105                                                     address);
 106     }
 107 
 108     public $Type$Buffer asReadOnlyBuffer() {
 109 #if[rw]
 110         return new ByteBufferAs$Type$BufferR$BO$(bb,
 111                                                  this.markValue(),
 112                                                  this.position(),
 113                                                  this.limit(),
 114                                                  this.capacity(),
 115                                                  address);
 116 #else[rw]
 117         return duplicate();
 118 #end[rw]


< prev index next >