< prev index next >

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

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


  26 package java.nio;
  27 
  28 
  29 // ## If the sequence is a string, use reflection to share its array
  30 
  31 class StringCharBuffer                                  // package-private
  32     extends CharBuffer
  33 {
  34     CharSequence str;
  35 
  36     StringCharBuffer(CharSequence s, int start, int end) { // package-private
  37         super(-1, start, end, s.length());
  38         int n = s.length();
  39         if ((start < 0) || (start > n) || (end < start) || (end > n))
  40             throw new IndexOutOfBoundsException();
  41         str = s;
  42         this.isReadOnly = true;
  43     }
  44 
  45     public CharBuffer slice() {



  46         return new StringCharBuffer(str,
  47                                     -1,
  48                                     0,
  49                                     this.remaining(),
  50                                     this.remaining(),
  51                                     offset + this.position());
  52     }
  53 
  54     private StringCharBuffer(CharSequence s,
  55                              int mark,
  56                              int pos,
  57                              int limit,
  58                              int cap,
  59                              int offset) {
  60         super(mark, pos, limit, cap, null, offset);
  61         str = s;
  62         this.isReadOnly = true;
  63     }
  64 
  65     public CharBuffer duplicate() {
  66         return new StringCharBuffer(str, markValue(),
  67                                     position(), limit(), capacity(), offset);
  68     }
  69 
  70     public CharBuffer asReadOnlyBuffer() {
  71         return duplicate();




  26 package java.nio;
  27 
  28 
  29 // ## If the sequence is a string, use reflection to share its array
  30 
  31 class StringCharBuffer                                  // package-private
  32     extends CharBuffer
  33 {
  34     CharSequence str;
  35 
  36     StringCharBuffer(CharSequence s, int start, int end) { // package-private
  37         super(-1, start, end, s.length());
  38         int n = s.length();
  39         if ((start < 0) || (start > n) || (end < start) || (end > n))
  40             throw new IndexOutOfBoundsException();
  41         str = s;
  42         this.isReadOnly = true;
  43     }
  44 
  45     public CharBuffer slice() {
  46         int pos = this.position();
  47         int lim = this.limit();
  48         int rem = (pos <= lim ? lim - pos : 0);
  49         return new StringCharBuffer(str,
  50                                     -1,
  51                                     0,
  52                                     rem,
  53                                     rem,
  54                                     offset + pos);
  55     }
  56 
  57     private StringCharBuffer(CharSequence s,
  58                              int mark,
  59                              int pos,
  60                              int limit,
  61                              int cap,
  62                              int offset) {
  63         super(mark, pos, limit, cap, null, offset);
  64         str = s;
  65         this.isReadOnly = true;
  66     }
  67 
  68     public CharBuffer duplicate() {
  69         return new StringCharBuffer(str, markValue(),
  70                                     position(), limit(), capacity(), offset);
  71     }
  72 
  73     public CharBuffer asReadOnlyBuffer() {
  74         return duplicate();


< prev index next >