本文整理汇总了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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
}
示例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);
}
示例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--;
}
}
示例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;
}
示例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);
}
示例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 );
}
}
示例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;
}
}
示例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();
}
示例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() );
}
示例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)");
}