01: /*
02: * *****************************************************************************
03: * Copyright (C) 2006, International Business Machines Corporation and others.
04: * All Rights Reserved.
05: * *****************************************************************************
06: */
07: // dlf13 internal 1.3 compatibility only
08: package com.ibm.icu.impl;
09:
10: /**
11: * @internal
12: */
13: public final class ByteBuffer {
14: private byte[] data;
15:
16: private int pos;
17:
18: private int limit;
19:
20: private ByteBuffer() {
21: }
22:
23: public byte[] array() {
24: byte[] result = new byte[limit];
25: for (int i = 0; i < limit; ++i) {
26: result[i] = data[i];
27: }
28: return result;
29: }
30:
31: public static ByteBuffer wrap(byte[] data) {
32: if (data == null)
33: throw new NullPointerException();
34: ByteBuffer result = new ByteBuffer();
35: result.data = data;
36: result.pos = 0;
37: result.limit = data.length;
38: return result;
39: }
40:
41: public int limit() {
42: return limit;
43: }
44:
45: public int remaining() {
46: return limit - pos;
47: }
48:
49: public byte get() {
50: if (pos < limit)
51: return data[pos++];
52: throw new IndexOutOfBoundsException();
53: }
54:
55: public void get(byte[] dst, int offset, int length) {
56: if (offset < 0 || offset + length > dst.length
57: || pos + length > limit) {
58: throw new IndexOutOfBoundsException();
59: }
60: for (int i = 0; i < length; ++i) {
61: dst[offset++] = data[pos++];
62: }
63: }
64:
65: public static final ByteBuffer allocate(int size) {
66: ByteBuffer ret = new ByteBuffer();
67: ret.data = new byte[size];
68: return ret;
69: }
70: }
|