mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-5407 Readd code for JDK 1.3 compatibility.
X-SVN-Rev: 20488
This commit is contained in:
parent
2c72117792
commit
802e3c73a3
1 changed files with 68 additions and 0 deletions
68
icu4j/src/com/ibm/icu/impl/ByteBuffer.java
Normal file
68
icu4j/src/com/ibm/icu/impl/ByteBuffer.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2006, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
* *****************************************************************************
|
||||
*/
|
||||
// dlf13 internal 1.3 compatibility only
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public final class ByteBuffer {
|
||||
private byte[] data;
|
||||
|
||||
private int pos;
|
||||
|
||||
private int limit;
|
||||
|
||||
private ByteBuffer() {
|
||||
}
|
||||
|
||||
public byte[] array() {
|
||||
byte[] result = new byte[limit];
|
||||
for (int i = 0; i < limit; ++i) {
|
||||
result[i] = data[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ByteBuffer wrap(byte[] data) {
|
||||
if (data == null)
|
||||
throw new NullPointerException();
|
||||
ByteBuffer result = new ByteBuffer();
|
||||
result.data = data;
|
||||
result.pos = 0;
|
||||
result.limit = data.length;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int limit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public int remaining() {
|
||||
return limit - pos;
|
||||
}
|
||||
|
||||
public byte get() {
|
||||
if (pos < limit)
|
||||
return data[pos++];
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
public void get(byte[] dst, int offset, int length) {
|
||||
if (offset < 0 || offset + length > dst.length || pos + length > limit) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
for (int i = 0; i < length; ++i) {
|
||||
dst[offset++] = data[pos++];
|
||||
}
|
||||
}
|
||||
public static final ByteBuffer allocate(int size){
|
||||
ByteBuffer ret = new ByteBuffer();
|
||||
ret.data = new byte[size];
|
||||
return ret;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue