當前位置: 首頁>>代碼示例>>Java>>正文


Java DataConstants.BYTES_PER_LONG屬性代碼示例

本文整理匯總了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;
	}
}
 
開發者ID:ArturVasilov,項目名稱:AndroidCourses,代碼行數:52,代碼來源:LongBackedBitVector.java

示例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;
}
 
開發者ID:ArturVasilov,項目名稱:AndroidCourses,代碼行數:59,代碼來源:LongBackedBitVector.java


注:本文中的org.andengine.util.adt.data.constants.DataConstants.BYTES_PER_LONG屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。