< prev index next >

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

Print this page
rev 52907 : 8234841: Enhance buffering of byte buffers
Reviewed-by: alanb, ahgross, rhalade, psandoz


  62                                      long addr)
  63     {
  64 #if[rw]
  65         super(mark, pos, lim, cap);
  66         this.bb = bb;
  67         address = addr;
  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(),




  62                                      long addr)
  63     {
  64 #if[rw]
  65         super(mark, pos, lim, cap);
  66         this.bb = bb;
  67         address = addr;
  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         int rem = (pos <= lim ? lim - pos : 0);
  83         long addr = byteOffset(pos);
  84         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb, -1, 0, rem, rem, addr);
  85     }
  86 
  87     public $Type$Buffer duplicate() {
  88         return new ByteBufferAs$Type$Buffer$RW$$BO$(bb,
  89                                                     this.markValue(),
  90                                                     this.position(),
  91                                                     this.limit(),
  92                                                     this.capacity(),
  93                                                     address);
  94     }
  95 
  96     public $Type$Buffer asReadOnlyBuffer() {
  97 #if[rw]
  98         return new ByteBufferAs$Type$BufferR$BO$(bb,
  99                                                  this.markValue(),
 100                                                  this.position(),
 101                                                  this.limit(),


< prev index next >