]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/impl/ByteBuffer.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / impl / ByteBuffer.java
1 //##header\r
2 //#if defined(FOUNDATION10) || defined(J2SE13) || defined(ECLIPSE_FRAGMENT)\r
3 //##/*\r
4 //## * *****************************************************************************\r
5 //## * Copyright (C) 2006-2009, International Business Machines\r
6 //## * Corporation and others. All Rights Reserved.\r
7 //## * *****************************************************************************\r
8 //## */\r
9 //##// dlf13 internal 1.3 compatibility only\r
10 //##\r
11 //##package com.ibm.icu.impl;\r
12 //##\r
13 //##/**\r
14 //## * @internal\r
15 //## */\r
16 //##public final class ByteBuffer {\r
17 //##    private byte[] data;\r
18 //##\r
19 //##    private int pos;\r
20 //##\r
21 //##    private int limit;\r
22 //##\r
23 //##    private ByteBuffer() {\r
24 //##    }\r
25 //##\r
26 //##    public byte[] array() {\r
27 //##        byte[] result = new byte[limit];\r
28 //##        for (int i = 0; i < limit; ++i) {\r
29 //##            result[i] = data[i];\r
30 //##        }\r
31 //##        return result;\r
32 //##    }\r
33 //##\r
34 //##    public static ByteBuffer wrap(byte[] data) {\r
35 //##        if (data == null)\r
36 //##            throw new NullPointerException();\r
37 //##        ByteBuffer result = new ByteBuffer();\r
38 //##        result.data = data;\r
39 //##        result.pos = 0;\r
40 //##        result.limit = data.length;\r
41 //##        return result;\r
42 //##    }\r
43 //##\r
44 //##    public int limit() {\r
45 //##        return limit;\r
46 //##    }\r
47 //##\r
48 //##    public int position() {\r
49 //##        return pos;\r
50 //##    }\r
51 //##\r
52 //##    public int remaining() {\r
53 //##        return limit - pos;\r
54 //##    }\r
55 //##\r
56 //##    public byte get() {\r
57 //##        if (pos < limit)\r
58 //##            return data[pos++];\r
59 //##        throw new IndexOutOfBoundsException();\r
60 //##    }\r
61 //##\r
62 //##    public void get(byte[] dst, int offset, int length) {\r
63 //##        if (offset < 0 || offset + length > dst.length || pos + length > limit) {\r
64 //##            throw new IndexOutOfBoundsException();\r
65 //##        }\r
66 //##        for (int i = 0; i < length; ++i) {\r
67 //##            dst[offset++] = data[pos++];\r
68 //##        }\r
69 //##    }\r
70 //##\r
71 //##    public void put(byte b) {\r
72 //##        if (pos < limit) {\r
73 //##            data[pos++] = b;\r
74 //##        } else {\r
75 //##            throw new IndexOutOfBoundsException();\r
76 //##        }\r
77 //##    }\r
78 //##\r
79 //##    public void put(byte[] src, int offset, int length) {\r
80 //##        if (offset < 0 || offset + length > src.length || pos + length > limit) {\r
81 //##            throw new IndexOutOfBoundsException();\r
82 //##        }\r
83 //##        for (int i = offset; i < offset + length; i++) {\r
84 //##            put(src[i]);\r
85 //##        }\r
86 //##    }\r
87 //##\r
88 //##    public void put(byte[] src) {\r
89 //##        put(src, 0, src.length);\r
90 //##    }\r
91 //##\r
92 //##    public static final ByteBuffer allocate(int size){\r
93 //##        ByteBuffer ret = new ByteBuffer();\r
94 //##        ret.data = new byte[size];\r
95 //##        ret.pos = 0;\r
96 //##        ret.limit = size;\r
97 //##        return ret;\r
98 //##    }\r
99 //##}\r
100 //#endif\r