当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.put方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.put方法的具体用法?Java ByteBuffer.put怎么用?Java ByteBuffer.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Encode the SyncDoneValue control
 *
 * @param buffer The encoded sink
 * @return A ByteBuffer that contains the encoded PDU
 * @throws EncoderException If anything goes wrong while encoding.
 */
@Override
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
    if ( buffer == null )
    {
        throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
    }

    // Encode the SEQ
    buffer.put( UniversalTag.SEQUENCE.getValue() );
    buffer.put( TLV.getBytes( syncDoneValueLength ) );

    if ( getCookie() != null )
    {
        BerValue.encode( buffer, getCookie() );
    }

    if ( isRefreshDeletes() )
    {
        BerValue.encode( buffer, isRefreshDeletes() );
    }

    return buffer;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:32,代码来源:SyncDoneValueDecorator.java

示例2: testByteBufferPositionPreservation

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testByteBufferPositionPreservation() {
  ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());

  Byte b = 0;
  while (bb.hasRemaining()) {
    bb.put(b);
    b++;
  }
  bb.position(10);

  Buffer buffer = Buffer.wrap(bb);
  while (buffer.hasRemaining()) {
    assertEquals(bb.get(), buffer.getByte());
  }
}
 
开发者ID:DataSketches,项目名称:memory,代码行数:17,代码来源:BufferTest2.java

示例3: encode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
{
    if ( buffer == null )
    {
        throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
    }

    if ( valueLength != 0 )
    {
        buffer.put( getValue() );
    }

    return buffer;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:19,代码来源:BasicControlDecorator.java

示例4: writeToBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] writeToBytes() {
	ByteBuffer buffer = ByteBuffer.allocate(calcPacketSize()+4);
	int size = calcPacketSize();
	BufferUtil.writeUB3(buffer, size);
	buffer.put(packetId);
	buffer.put(fieldCount);
	BufferUtil.writeUB2(buffer, errno);
	buffer.put(mark);
	buffer.put(sqlState);
	if (message != null) {
		buffer.put(message);
	}
	buffer.flip();
	byte[] data = new byte[buffer.limit()];
	buffer.get(data);

	return data;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:19,代码来源:ErrorPacket.java

示例5: getShortQuery

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] getShortQuery() {
    ByteBuffer query = ByteBuffer.allocate(65536);
    query.put(this.serverName.getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    query.put(this.gameType.getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    query.put(this.map.getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    query.put(String.valueOf(this.numPlayers).getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    query.put(String.valueOf(this.maxPlayers).getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    query.put(Binary.writeLShort(this.port));
    query.put(this.ip.getBytes(StandardCharsets.UTF_8));
    query.put((byte) 0x00);
    return Arrays.copyOf(query.array(), query.position());
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:QueryRegenerateEvent.java

示例6: getOutboundData

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private HandshakeStatus getOutboundData(ByteBuffer dstBB) {

        Object msg = outboundList.removeFirst();
        assert(msg instanceof ByteBuffer);

        ByteBuffer bbIn = (ByteBuffer) msg;
        assert(dstBB.remaining() >= bbIn.remaining());

        dstBB.put(bbIn);

        /*
         * If we have more data in the queue, it's either
         * a finished message, or an indication that we need
         * to call wrap again.
         */
        if (hasOutboundDataInternal()) {
            msg = outboundList.getFirst();
            if (msg == HandshakeStatus.FINISHED) {
                outboundList.removeFirst();     // consume the message
                return HandshakeStatus.FINISHED;
            } else {
                return HandshakeStatus.NEED_WRAP;
            }
        } else {
            return null;
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:EngineWriter.java

示例7: combination_16

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void combination_16(List<byte[]> results, int mode, byte[] AAD,
        byte[] plainText, AlgorithmParameters params) throws Exception {
    Cipher c = createCipher(mode, params);

    // prepare ByteBuffer to test
    ByteBuffer buf = ByteBuffer.allocateDirect(AAD.length);
    buf.put(AAD);
    buf.position(0);
    buf.limit(AAD.length);
    c.updateAAD(buf);

    // prepare empty ByteBuffer
    ByteBuffer emptyBuf = ByteBuffer.allocateDirect(0);
    emptyBuf.put(new byte[0]);
    c.updateAAD(emptyBuf);

    // prepare buffers to encrypt/decrypt
    ByteBuffer in = ByteBuffer.allocateDirect(plainText.length);
    in.put(plainText);
    in.position(0);
    in.limit(plainText.length);
    ByteBuffer output = ByteBuffer.allocateDirect(
            c.getOutputSize(in.limit()));
    output.position(0);
    output.limit(c.getOutputSize(in.limit()));

    // process input text with an empty buffer
    c.update(in, output);
    ByteBuffer emptyBuf2 = ByteBuffer.allocate(0);
    emptyBuf2.put(new byte[0]);
    c.doFinal(emptyBuf2, output);
    int resultSize = output.position();
    byte[] result16 = new byte[resultSize];
    output.position(0);
    output.limit(resultSize);
    output.get(result16, 0, resultSize);
    results.add(result16);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:Encrypt.java

示例8: emit

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void emit(ByteBuffer buffer, Patches patches) {
    int rest = getSize();
    while (rest > 8) {
        buffer.putLong(0L);
        rest -= 8;
    }
    while (rest > 0) {
        buffer.put((byte) 0);
        rest--;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:DataSection.java

示例9: encodeObject

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static synchronized byte[] encodeObject(List<Object> lines) throws BufferOverflowException {
	// 粗略分配
	int bufferSize = getSize(lines);
	ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
	
	if (lines.size() > 0) {
		buffer.put((byte) '*');
		buffer.put(ProtoUtils.convertIntToByteArray(lines.size()));
		buffer.put("\r\n".getBytes());

		for (int i = 0; i < lines.size(); i++) {
			Object obj = lines.get(i);
			if (obj instanceof String) {
				byte[] lineBytes = String.valueOf(obj).getBytes();
				buffer.put((byte) '$');
				buffer.put(ProtoUtils.convertIntToByteArray(lineBytes.length));
				buffer.put("\r\n".getBytes());
				buffer.put(lineBytes);
				buffer.put("\r\n".getBytes());
				
			} else if (obj instanceof List) {
				buffer.put( encodeObject( (List<Object>) obj ) );
			}
		}

	} else {
		return "-ERR no data.\r\n".getBytes();
	}

	buffer.flip();
	byte[] data = new byte[buffer.remaining()];
	buffer.get(data);
	return data;
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:36,代码来源:Manage.java

示例10: getContent

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void getContent(ByteBuffer byteBuffer) {
    writeVersionAndFlags(byteBuffer);
    IsoTypeWriter.writeIso639(byteBuffer, language);
    byteBuffer.put(Utf8.convert(contentDistributorId));
    byteBuffer.put((byte) 0);

}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:9,代码来源:ContentDistributorIdBox.java

示例11: testDecodeExtendedResponseEmpty

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Test the decoding of an empty ExtendedResponse
 */
@Test
public void testDecodeExtendedResponseEmpty()
{
    Asn1Decoder ldapDecoder = new Asn1Decoder();

    ByteBuffer stream = ByteBuffer.allocate( 0x07 );

    stream.put( new byte[]
        { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
            0x02,
            0x01,
            0x01, // messageID MessageID
            // CHOICE { ..., extendedResp Response, ...
            0x78,
            0x00 // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
    } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<ExtendedResponseDecorator<?>> container =
        new LdapMessageContainer<ExtendedResponseDecorator<?>>( codec );

    // Decode a DelRequest PDU
    try
    {
        ldapDecoder.decode( stream, container );
        fail( "We should never reach this point !!!" );
    }
    catch ( DecoderException de )
    {
        assertTrue( true );
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:38,代码来源:ExtendedResponseTest.java

示例12: mask

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void mask(ByteBuffer buf, int position, int length) {
    int limit = position + length;
    for (int i = position ; i < limit; ++i) {
        buf.put(i, (byte) (buf.get(i) ^ maskingKey[m++]));
        m %= 4;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:Masker.java

示例13: XfrBlock

import java.nio.ByteBuffer; //导入方法依赖的package包/类
XfrBlock(final byte insCount, final byte[] apdu, final byte[] typeXfr){
	this.instructionCount = insCount;
	final ByteBuffer commandBuffer = ByteBuffer.allocate(UsbCommand.USB_HEADER_BASE_SIZE + apdu.length);
	final byte DEFAULT_BLOCKING_WAIT = (byte) 0x01;
	commandBuffer.put((byte) 0x6F);
	commandBuffer.put(HexUtils.intToByteArray(apdu.length));
	commandBuffer.put(new byte[]{(byte) 0x00, this.instructionCount, DEFAULT_BLOCKING_WAIT});
	commandBuffer.put(typeXfr);
	commandBuffer.put(apdu);
	this.command = commandBuffer.array();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:12,代码来源:XfrBlock.java

示例14: testDecodeEntryChangeControlSuccess

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Test the decoding of a EntryChangeControl
 */
@Test
public void testDecodeEntryChangeControlSuccess() throws Exception
{
    ByteBuffer bb = ByteBuffer.allocate( 0x0D );
    bb.put( new byte[]
        {
            0x30, 0x0B, // EntryChangeNotification ::= SEQUENCE {
            0x0A,
            0x01,
            0x08, //     changeType ENUMERATED {
                  //         modDN (8)
                  //     }
            0x04,
            0x03,
            'a',
            '=',
            'b', //     previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
            0x02,
            0x01,
            0x10 //     changeNumber INTEGER OPTIONAL } -- if supported
    } );
    bb.flip();

    EntryChangeDecorator decorator = new EntryChangeDecorator( codec );

    EntryChange entryChange = ( EntryChange ) decorator.decode( bb.array() );

    assertEquals( ChangeType.MODDN, entryChange.getChangeType() );
    assertEquals( "a=b", entryChange.getPreviousDn().toString() );
    assertEquals( 16, entryChange.getChangeNumber() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:35,代码来源:EntryChangeControlTest.java

示例15: putAllocateDirect

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void putAllocateDirect() {
    ByteBuffer buffer = ByteBuffer.allocateDirect(4096);
    byte[] b = new byte[1024];

    int count = 1000000;
    System.currentTimeMillis();

    long t1 = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        buffer.position(0);
        buffer.put(b);
    }
    long t2 = System.currentTimeMillis();
    System.out.println("take time:" + (t2 - t1) + " ms.(Put:allocateDirect)");
}
 
开发者ID:actiontech,项目名称:dble,代码行数:16,代码来源:BufferPerformanceMain.java


注:本文中的java.nio.ByteBuffer.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。