1 7 8 package java.nio; 9 10 11 13 class StringCharBuffer extends CharBuffer 15 { 16 CharSequence str; 17 18 StringCharBuffer(CharSequence s, int start, int end) { super(-1, start, end, s.length()); 20 int n = s.length(); 21 if ((start < 0) || (start > n) || (end < start) || (end > n)) 22 throw new IndexOutOfBoundsException (); 23 str = s; 24 } 25 26 public CharBuffer slice() { 27 return new StringCharBuffer (str, position(), limit()); 28 } 29 30 31 private StringCharBuffer(CharSequence s, int mark, 32 int pos, int limit, int cap) 33 { 34 super(mark, pos, limit, cap); 35 str = s; 36 } 37 38 public CharBuffer duplicate() { 39 return new StringCharBuffer (str, markValue(), 40 position(), limit(), capacity()); 41 } 42 43 public CharBuffer asReadOnlyBuffer() { 44 return duplicate(); 45 } 46 47 public final char get() { 48 return str.charAt(nextGetIndex()); 49 } 50 51 public final char get(int index) { 52 return str.charAt(checkIndex(index)); 53 } 54 55 57 public final CharBuffer put(char c) { 58 throw new ReadOnlyBufferException (); 59 } 60 61 public final CharBuffer put(int index, char c) { 62 throw new ReadOnlyBufferException (); 63 } 64 65 public final CharBuffer compact() { 66 throw new ReadOnlyBufferException (); 67 } 68 69 public final boolean isReadOnly() { 70 return true; 71 } 72 73 final String toString(int start, int end) { 74 return str.toString().substring(start, end); 75 } 76 77 public final CharSequence subSequence(int start, int end) { 78 try { 79 int pos = position(); 80 return new StringCharBuffer (str, 81 pos + checkIndex(start, pos), 82 pos + checkIndex(end, pos)); 83 } catch (IllegalArgumentException x) { 84 throw new IndexOutOfBoundsException (); 85 } 86 } 87 88 public boolean isDirect() { 89 return false; 90 } 91 92 public ByteOrder order() { 93 return ByteOrder.nativeOrder(); 94 } 95 96 } 97 | Popular Tags |