本文整理汇总了Java中org.andengine.util.adt.data.constants.DataConstants.BYTES_PER_LONG属性的典型用法代码示例。如果您正苦于以下问题:Java DataConstants.BYTES_PER_LONG属性的具体用法?Java DataConstants.BYTES_PER_LONG怎么用?Java DataConstants.BYTES_PER_LONG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.andengine.util.adt.data.constants.DataConstants
的用法示例。
在下文中一共展示了DataConstants.BYTES_PER_LONG属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LongBackedBitVector
public LongBackedBitVector(final byte[] pData) throws IllegalArgumentException, NullPointerException {
this(pData.length * DataConstants.BITS_PER_BYTE);
final long[] data = this.mData;
/* Check if bytes perfectly fit into the data fields or if there are some overflow bytes that need special treatment. */
final boolean perfectDataFit = (pData.length % DataConstants.BYTES_PER_LONG) == 0;
final int dataLength = data.length;
final int lastCompleteDataIndex = (perfectDataFit) ? dataLength - 1 : dataLength - 2;
for (int i = lastCompleteDataIndex; i >= 0; i--) {
final int bytesOffset = i * DataConstants.BYTES_PER_LONG;
data[i] = ((((long)pData[bytesOffset + 0]) << 56) & 0xFF00000000000000L)
| ((((long)pData[bytesOffset + 1]) << 48) & 0xFF000000000000L)
| ((((long)pData[bytesOffset + 2]) << 40) & 0xFF0000000000L)
| ((((long)pData[bytesOffset + 3]) << 32) & 0xFF00000000L)
| ((((long)pData[bytesOffset + 4]) << 24) & 0xFF000000L)
| ((((long)pData[bytesOffset + 5]) << 16) & 0xFF0000L)
| ((((long)pData[bytesOffset + 6]) << 8) & 0xFF00L)
| ((((long)pData[bytesOffset + 7]) << 0) & 0xFFL);
}
/* Put overflow bytes into last data field. */
if (!perfectDataFit) {
long overflowData = 0;
final int overflowDataIndex = dataLength - 1;
final int overflowBytesOffset = overflowDataIndex * DataConstants.BYTES_PER_LONG;
final int overflowByteCount = pData.length - overflowBytesOffset;
switch (overflowByteCount) {
case 7:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 6]) << 8) & 0xFF00L);
case 6:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 5]) << 16) & 0xFF0000L);
case 5:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 4]) << 24) & 0xFF000000L);
case 4:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 3]) << 32) & 0xFF00000000L);
case 3:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 2]) << 40) & 0xFF0000000000L);
case 2:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 1]) << 48) & 0xFF000000000000L);
case 1:
overflowData = overflowData | ((((long)pData[overflowBytesOffset + 0]) << 56) & 0xFF00000000000000L);
}
data[overflowDataIndex] = overflowData;
}
}
示例2: toByteArray
@Override
public byte[] toByteArray() {
final int byteArrayLength;
if ((this.mSize % DataConstants.BITS_PER_BYTE) == 0) {
byteArrayLength = this.mSize / DataConstants.BITS_PER_BYTE;
} else {
byteArrayLength = (this.mSize / DataConstants.BITS_PER_BYTE) + 1;
}
final byte[] bytes = new byte[byteArrayLength];
/* Check if bytes perfectly fit into the data fields or if there are some overflow bytes that need special treatment. */
final boolean perfectDataFit = (this.mSize % DataConstants.BITS_PER_LONG) == 0;
final long[] data = this.mData;
final int dataLength = data.length;
final int lastCompleteDataIndex = (perfectDataFit) ? dataLength - 1 : dataLength - 2;
int bytesOffset = (lastCompleteDataIndex * DataConstants.BYTES_PER_LONG) + (DataConstants.BYTES_PER_LONG - 1);
for (int i = lastCompleteDataIndex; i >= 0; i--) {
final long dataField = data[i];
bytes[bytesOffset--] = (byte) ((dataField >> 0) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 8) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 16) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 24) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 32) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 40) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 48) & 0xFF);
bytes[bytesOffset--] = (byte) ((dataField >> 56) & 0xFF);
}
/* Put overflow bytes into last data field. */
if (!perfectDataFit) {
final int overflowDataIndex = dataLength - 1;
final long overflowDataField = data[overflowDataIndex];
final int overflowBytesOffset = overflowDataIndex * DataConstants.BYTES_PER_LONG;
final int overflowByteCount = bytes.length % DataConstants.BYTES_PER_LONG;
switch (overflowByteCount) {
case 7:
bytes[overflowBytesOffset + 6] = (byte) ((overflowDataField >> 8) & 0xFF);
case 6:
bytes[overflowBytesOffset + 5] = (byte) ((overflowDataField >> 16) & 0xFF);
case 5:
bytes[overflowBytesOffset + 4] = (byte) ((overflowDataField >> 24) & 0xFF);
case 4:
bytes[overflowBytesOffset + 3] = (byte) ((overflowDataField >> 32) & 0xFF);
case 3:
bytes[overflowBytesOffset + 2] = (byte) ((overflowDataField >> 40) & 0xFF);
case 2:
bytes[overflowBytesOffset + 1] = (byte) ((overflowDataField >> 48) & 0xFF);
case 1:
bytes[overflowBytesOffset + 0] = (byte) ((overflowDataField >> 56) & 0xFF);
}
}
return bytes;
}