本文整理汇总了Java中java.nio.ByteBuffer.order方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.order方法的具体用法?Java ByteBuffer.order怎么用?Java ByteBuffer.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.order方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check_HASH160_A_with_B
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public long check_HASH160_A_with_B( AT_Machine_State state ) {
if ( state.getHeight() >= Constants.AT_FIX_BLOCK_3 ) {
ByteBuffer b = ByteBuffer.allocate( 32 );
b.order( ByteOrder.LITTLE_ENDIAN );
b.put( state.get_A1() );
b.put( state.get_A2() );
b.put( state.get_A3() );
b.put( state.get_A4() );
RIPEMD160 ripemd160 = new RIPEMD160();
ByteBuffer ripemdb = ByteBuffer.wrap( ripemd160.digest( b.array() ) );
ripemdb.order( ByteOrder.LITTLE_ENDIAN );
return ( ripemdb.getLong(0) == AT_API_Helper.getLong( state.get_B1() ) &&
ripemdb.getLong(8) == AT_API_Helper.getLong( state.get_B2() ) &&
ripemdb.getInt(16) == ((int)(AT_API_Helper.getLong( state.get_B3() ) & 0x00000000FFFFFFFFL ))
) ? 1 : 0;
}
else {
return(Arrays.equals(state.get_A1(), state.get_B1()) &&
Arrays.equals(state.get_A2(), state.get_B2()) &&
(AT_API_Helper.getLong(state.get_A3()) & 0x00000000FFFFFFFFL) == (AT_API_Helper.getLong(state.get_B3()) & 0x00000000FFFFFFFFL)) ? 1 : 0;
}
}
示例2: getLongTimestamp
import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected static long getLongTimestamp(int height, int numOfTx){
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(4, height);
buffer.putInt(0,numOfTx);
return buffer.getLong(0);
}
示例3: schnorrSign
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static byte[] schnorrSign(byte[] data, byte[] sec) throws AssertFailException {
Preconditions.checkArgument(data.length == 32 && sec.length <= 32);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null) {
byteBuff = ByteBuffer.allocateDirect(32 + 32);
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();
byteBuff.put(data);
byteBuff.put(sec);
byte[][] retByteArray;
r.lock();
try {
retByteArray = secp256k1_schnorr_sign(byteBuff, Secp256k1Context.getContext());
} finally {
r.unlock();
}
byte[] sigArr = retByteArray[0];
int retVal = new BigInteger(new byte[] { retByteArray[1][0] }).intValue();
assertEquals(sigArr.length, 64, "Got bad signature length.");
return retVal == 0 ? new byte[0] : sigArr;
}
示例4: checkByteBufWrongOrder
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void checkByteBufWrongOrder() {
int n = 1024; //longs
ByteBuffer bb = ByteBuffer.allocate(n * 8);
bb.order(ByteOrder.BIG_ENDIAN);
Memory mem = Memory.wrap(bb);
assertTrue(mem.swapBytes());
assertEquals(mem.getResourceOrder(), ByteOrder.BIG_ENDIAN);
}
示例5: saveWord2VecfToBinary
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/** Save the word2vecf model as binary file */
public static void saveWord2VecfToBinary (String wordToPath, String contextToPath, Word2Vecf w2vf) {
final Charset cs = StandardCharsets.UTF_8;
try {
final OutputStream wos = new FileOutputStream(new File(wordToPath));
final String wheader = String.format("%d %d\n", w2vf.wordVocabSize(), w2vf.getLayerSize());
wos.write(wheader.getBytes(cs));
final ByteBuffer wbuffer = ByteBuffer.allocate(4 * w2vf.getLayerSize());
wbuffer.order(byteOrder);
for (int i = 0; i < w2vf.wordVocabSize(); ++i) {
wos.write(String.format("%s ", w2vf.getWordVocab().get(i)).getBytes(cs));
wbuffer.clear();
for (int j = 0; j < w2vf.getLayerSize(); ++j) wbuffer.putFloat(w2vf.getWordVectors().getFloat(i, j));
wos.write(wbuffer.array());
wos.write('\n');
}
wos.flush();
wos.close();
final OutputStream cos = new FileOutputStream(new File(contextToPath));
final String cheader = String.format("%d %d\n", w2vf.contextVocabSize(), w2vf.getLayerSize());
cos.write(cheader.getBytes(cs));
final ByteBuffer cbuffer = ByteBuffer.allocate(4 * w2vf.getLayerSize());
cbuffer.order(byteOrder);
for (int i = 0; i < w2vf.contextVocabSize(); ++i) {
cos.write(String.format("%s ", w2vf.getContextVocab().get(i)).getBytes(cs));
cbuffer.clear();
for (int j = 0; j < w2vf.getLayerSize(); ++j) cbuffer.putFloat(w2vf.getContextVectors().getFloat(i, j));
cos.write(cbuffer.array());
cos.write('\n');
}
cos.flush();
cos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: computePubkey
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* libsecp256k1 Compute Pubkey - computes public key from secret key
*
* @param seckey ECDSA Secret key, 32 bytes
* @return pubkey ECDSA Public key, 33 or 65 bytes
*/
// TODO add a 'compressed' arg
public static byte[] computePubkey(byte[] seckey) throws AssertFailException {
Preconditions.checkArgument(seckey.length == 32);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null || byteBuff.capacity() < seckey.length) {
byteBuff = ByteBuffer.allocateDirect(seckey.length);
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();
byteBuff.put(seckey);
byte[][] retByteArray;
r.lock();
try {
retByteArray = secp256k1_ec_pubkey_create(byteBuff, Secp256k1Context.getContext());
} finally {
r.unlock();
}
byte[] pubArr = retByteArray[0];
int pubLen = new BigInteger(new byte[] { retByteArray[1][0] }).intValue();
int retVal = new BigInteger(new byte[] { retByteArray[1][1] }).intValue();
assertEquals(pubArr.length, pubLen, "Got bad pubkey length.");
return retVal == 0 ? new byte[0] : pubArr;
}
示例7: getByteArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static byte[] getByteArray( long l ){
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
buffer.putLong( l );
return buffer.array();
}
示例8: short2Stream
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* 字节数组转换成short(小端序)
* @param stream
* @param offset
* @return
*/
private static byte[] short2Stream(short data) {
ByteBuffer buffer = ByteBuffer.allocate(2);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort(data);
buffer.flip();
return buffer.array();
}
示例9: allocateBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer allocateBuffer() {
ByteBuffer buffer = emptyBuffers.pollLast();
if (buffer == null) {
buffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
if (!bigEndian) {
buffer.order(ByteOrder.nativeOrder());
}
}
return buffer;
}
示例10: loadClock
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void loadClock(long[] clockData, InputStream is) throws IOException {
byte[] byteBuff = new byte[4 * clockData.length];
IOUtils.read(is, byteBuff);
ByteBuffer buff = ByteBuffer.wrap(byteBuff);
buff.order(ByteOrder.LITTLE_ENDIAN);
int i = 0;
while (buff.hasRemaining()) {
clockData[i++] = buff.getInt() & 0xffffffff;
}
}
示例11: pubKeyTweakMul
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* libsecp256k1 PubKey Tweak-Mul - Tweak pubkey by multiplying to it
*
* @param tweak some bytes to tweak with
* @param pubkey 32-byte seckey
*/
public static byte[] pubKeyTweakMul(byte[] pubkey, byte[] tweak) throws AssertFailException {
Preconditions.checkArgument(pubkey.length == 33 || pubkey.length == 65);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null || byteBuff.capacity() < pubkey.length + tweak.length) {
byteBuff = ByteBuffer.allocateDirect(pubkey.length + tweak.length);
byteBuff.order(ByteOrder.nativeOrder());
nativeECDSABuffer.set(byteBuff);
}
byteBuff.rewind();
byteBuff.put(pubkey);
byteBuff.put(tweak);
byte[][] retByteArray;
r.lock();
try {
retByteArray = secp256k1_pubkey_tweak_mul(byteBuff, Secp256k1Context.getContext(), pubkey.length);
} finally {
r.unlock();
}
byte[] pubArr = retByteArray[0];
int pubLen = (byte) new BigInteger(new byte[] { retByteArray[1][0] }).intValue() & 0xFF;
int retVal = new BigInteger(new byte[] { retByteArray[1][1] }).intValue();
assertEquals(pubArr.length, pubLen, "Got bad pubkey length.");
assertEquals(retVal, 1, "Failed return value check.");
return pubArr;
}
示例12: initVertexData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void initVertexData() {
vCount = 5;
//顶点数据处理
float[] vertices = new float[]{0, 0, 0,
Constant.UNIT_SIZE, Constant.UNIT_SIZE, 0,
-Constant.UNIT_SIZE, Constant.UNIT_SIZE, 0,
-Constant.UNIT_SIZE, -Constant.UNIT_SIZE, 0,
Constant.UNIT_SIZE, -Constant.UNIT_SIZE, 0};
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asFloatBuffer();
mVertexBuffer.put(vertices)
.position(0);
//颜色数据处理
float[] colors = new float[]{
//每个顶点的颜色RGBA
1, 1, 0, 0,
1, 1, 1, 0,
0, 1, 0, 0,
1, 1, 1, 0,
1, 1, 0, 0};
ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length * 4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asFloatBuffer();
mColorBuffer.put(colors)
.position(0);
}
示例13: parseZipCentralDirectory
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static List<CentralDirectoryRecord> parseZipCentralDirectory(
DataSource apk,
ApkUtils.ZipSections apkSections)
throws IOException, ApkFormatException {
// Read the ZIP Central Directory
long cdSizeBytes = apkSections.getZipCentralDirectorySizeBytes();
if (cdSizeBytes > Integer.MAX_VALUE) {
throw new ApkFormatException("ZIP Central Directory too large: " + cdSizeBytes);
}
long cdOffset = apkSections.getZipCentralDirectoryOffset();
ByteBuffer cd = apk.getByteBuffer(cdOffset, (int) cdSizeBytes);
cd.order(ByteOrder.LITTLE_ENDIAN);
// Parse the ZIP Central Directory
int expectedCdRecordCount = apkSections.getZipCentralDirectoryRecordCount();
List<CentralDirectoryRecord> cdRecords = new ArrayList<>(expectedCdRecordCount);
for (int i = 0; i < expectedCdRecordCount; i++) {
CentralDirectoryRecord cdRecord;
int offsetInsideCd = cd.position();
try {
cdRecord = CentralDirectoryRecord.getRecord(cd);
} catch (ZipFormatException e) {
throw new ApkFormatException(
"Malformed ZIP Central Directory record #" + (i + 1)
+ " at file offset " + (cdOffset + offsetInsideCd),
e);
}
String entryName = cdRecord.getName();
if (entryName.endsWith("/")) {
// Ignore directory entries
continue;
}
cdRecords.add(cdRecord);
}
// There may be more data in Central Directory, but we don't warn or throw because Android
// ignores unused CD data.
return cdRecords;
}
示例14: read
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void read(SelectionKey key) throws IOException {
SocketChannel channel = (SocketChannel) key.channel();
ByteBuffer buffer = ByteBuffer.allocate(4096);
buffer.order(ByteOrder.LITTLE_ENDIAN);
int bytesRead;
try {
bytesRead = channel.read(buffer);
} catch (IOException exception) {
key.cancel();
channel.close();
if (this.rconSessions.contains(channel)) {
this.rconSessions.remove(channel);
}
if (this.sendQueues.containsKey(channel)) {
this.sendQueues.remove(channel);
}
return;
}
if (bytesRead == -1) {
key.cancel();
channel.close();
if (this.rconSessions.contains(channel)) {
this.rconSessions.remove(channel);
}
if (this.sendQueues.containsKey(channel)) {
this.sendQueues.remove(channel);
}
return;
}
buffer.flip();
this.handle(channel, new RCONPacket(buffer));
}
示例15: SockFProg
import java.nio.ByteBuffer; //导入方法依赖的package包/类
SockFProg(SockFilter filters[]) {
len = (short) filters.length;
// serialize struct sock_filter * explicitly, its less confusing than the JNA magic we would need
Memory filter = new Memory(len * 8);
ByteBuffer bbuf = filter.getByteBuffer(0, len * 8);
bbuf.order(ByteOrder.nativeOrder()); // little endian
for (SockFilter f : filters) {
bbuf.putShort(f.code);
bbuf.put(f.jt);
bbuf.put(f.jf);
bbuf.putInt(f.k);
}
this.filter = filter;
}