01: /*
02: * @(#)ByteArrayCharSequence.java 1.2 04/12/06
03: *
04: * Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.nio;
10:
11: public class ByteArrayCharSequence implements CharSequence {
12: private byte[] bytes;
13: private int offset;
14: private int size;
15:
16: public ByteArrayCharSequence(byte[] b, int offset, int size) {
17: this .bytes = b;
18: this .offset = offset;
19: this .size = size;
20: }
21:
22: public int length() {
23: return this .size;
24: }
25:
26: public char charAt(int index) {
27: return (char) bytes[offset + index];
28: }
29:
30: public CharSequence subSequence(int start, int end) {
31: return new ByteArrayCharSequence(bytes, offset + start, end
32: - start);
33: }
34:
35: public String toString() {
36: return new String(bytes, offset, size);
37: }
38: }
|