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


Java ByteBuffer.order方法代碼示例

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

示例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);
}
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:8,代碼來源:AT_API_Helper.java

示例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;
}
 
開發者ID:marvin-we,項目名稱:crypto-core,代碼行數:30,代碼來源:NativeSecp256k1.java

示例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);
}
 
開發者ID:DataSketches,項目名稱:memory,代碼行數:10,代碼來源:MemoryTest.java

示例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();
	}
}
 
開發者ID:IsaacChanghau,項目名稱:Word2VecfJava,代碼行數:37,代碼來源:WordVectorSerializer.java

示例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;
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:37,代碼來源:NativeSecp256k1.java

示例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();
}
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:8,代碼來源:AT_API_Helper.java

示例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();
   }
 
開發者ID:Sherchen,項目名稱:AnimationsDemo,代碼行數:14,代碼來源:MCPTool.java

示例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;
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:11,代碼來源:ByteBufferFifo.java

示例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;
    }
}
 
開發者ID:trekawek,項目名稱:coffee-gb,代碼行數:11,代碼來源:FileBattery.java

示例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;
}
 
開發者ID:marvin-we,項目名稱:crypto-core,代碼行數:39,代碼來源:NativeSecp256k1.java

示例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);

}
 
開發者ID:ynztlxdeai,項目名稱:GLproject,代碼行數:30,代碼來源:PonitOrLines.java

示例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;
}
 
開發者ID:nukc,項目名稱:ApkMultiChannelPlugin,代碼行數:40,代碼來源:V1SchemeVerifier.java

示例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));
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:36,代碼來源:RCONServer.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:SystemCallFilter.java


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