com.github.andyshao.lang.ByteCharWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.lang;
import java.math.BigInteger;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Apr 5, 2015
* Encoding:UNIX UTF-8
*
* @author Andy.Shao
*
*/
public class ByteCharWrapper implements CharWrapper {
private static final int BASE = 1;
@Override
public char getChar(byte[] array , BigInteger position) {
char result = 0x00;
for (int i = 0 , index = position.intValue() << ByteCharWrapper.BASE ; i < 2 ; i++ , index++)
if (index < array.length) result = CharOperation.setByte(result , i , array[index]);
else if (i == 0) throw new ArrayIndexOutOfBoundsException(index);
else break;
return result;
}
@Override
public void setChar(byte[] array , BigInteger position , char c) {
for (int i = 0 , index = position.intValue() << ByteCharWrapper.BASE ; i < 2 ; i++ , index++)
if (index < array.length) array[index] = CharOperation.getByte(c , i);
else if (i == 0) throw new ArrayIndexOutOfBoundsException(index);
else break;
}
@Override
public BigInteger size(byte[] array) {
return array.length - (array.length >> ByteCharWrapper.BASE) > 0 ? BigInteger.valueOf((array.length >> ByteCharWrapper.BASE) + 1) : BigInteger.valueOf(array.length >> ByteCharWrapper.BASE);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy