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


Java ByteBuffer.wrap方法代码示例

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


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

示例1: inPacket

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public InboundPacket inPacket() {
    ONOSLLDP lldp = ONOSLLDP.onosLLDP(deviceService.getDevice(DID1).id().toString(),
                                      device.chassisId(),
                                      (int) pd1.number().toLong());

    Ethernet ethPacket = new Ethernet();
    ethPacket.setEtherType(Ethernet.TYPE_LLDP);
    ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
    ethPacket.setPayload(lldp);
    ethPacket.setPad(true);

    ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11");

    ConnectPoint cp = new ConnectPoint(device.id(), pd3.number());

    return new DefaultInboundPacket(cp, ethPacket,
                                    ByteBuffer.wrap(ethPacket.serialize()));

}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:LldpLinkProviderTest.java

示例2: decode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Decodes all bytes from the input byte buffer using the {@link Base64}
 * encoding scheme, writing the results into a newly-allocated ByteBuffer.
 *
 * <p> Upon return, the source buffer's position will be updated to
 * its limit; its limit will not have been changed. The returned
 * output buffer's position will be zero and its limit will be the
 * number of resulting decoded bytes
 *
 * <p> {@code IllegalArgumentException} is thrown if the input buffer
 * is not in valid Base64 encoding scheme. The position of the input
 * buffer will not be advanced in this case.
 *
 * @param   buffer
 *          the ByteBuffer to decode
 *
 * @return  A newly-allocated byte buffer containing the decoded bytes
 *
 * @throws  IllegalArgumentException
 *          if {@code src} is not in valid Base64 scheme.
 */
public ByteBuffer decode(ByteBuffer buffer) {
    int pos0 = buffer.position();
    try {
        byte[] src;
        int sp, sl;
        if (buffer.hasArray()) {
            src = buffer.array();
            sp = buffer.arrayOffset() + buffer.position();
            sl = buffer.arrayOffset() + buffer.limit();
            buffer.position(buffer.limit());
        } else {
            src = new byte[buffer.remaining()];
            buffer.get(src);
            sp = 0;
            sl = src.length;
        }
        byte[] dst = new byte[outLength(src, sp, sl)];
        return ByteBuffer.wrap(dst, 0, decode0(src, sp, sl, dst));
    } catch (IllegalArgumentException iae) {
        buffer.position(pos0);
        throw iae;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:Base64.java

示例3: checkBufferOverflowOnWrap

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void checkBufferOverflowOnWrap(SSLEngine engine)
        throws SSLException {
    String mode = engine.getUseClientMode() ? "client"
            : "server";
    System.out.println("================================================="
            + "===========");
    System.out.println("Testing SSLEngine buffer overflow"
            + " on wrap by " + mode);
    ByteBuffer app = ByteBuffer.wrap(MESSAGE.getBytes());
    //Making net buffer size less than required by 1 byte.
    ByteBuffer net = ByteBuffer
            .allocate(engine.getSession().getPacketBufferSize() - 1);
    SSLEngineResult r = engine.wrap(app, net);
    checkResult(r, SSLEngineResult.Status.BUFFER_OVERFLOW);
    System.out.println("Passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BufferOverflowUnderflowTest.java

示例4: testEncodeAndDecode_FilledBody

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testEncodeAndDecode_FilledBody() {
    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, "2333");

    int code = 103; //org.apache.rocketmq.common.protocol.RequestCode.REGISTER_BROKER
    CommandCustomHeader header = new SampleCommandCustomHeader();
    RemotingCommand cmd = RemotingCommand.createRequestCommand(code, header);
    cmd.setBody(new byte[] { 0, 1, 2, 3, 4});

    ByteBuffer buffer = cmd.encode();

    //Simulate buffer being read in NettyDecoder
    buffer.getInt();
    byte[] bytes = new byte[buffer.limit() - 4];
    buffer.get(bytes, 0, buffer.limit() - 4);
    buffer = ByteBuffer.wrap(bytes);

    RemotingCommand decodedCommand = RemotingCommand.decode(buffer);

    assertThat(decodedCommand.getSerializeTypeCurrentRPC()).isEqualTo(SerializeType.JSON);
    assertThat(decodedCommand.getBody()).isEqualTo(new byte[]{ 0, 1, 2, 3, 4});
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:23,代码来源:RemotingCommandTest.java

示例5: cacheKey

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void cacheKey() throws Exception {
    final long segmentId = TIMESTAMP / SEGMENT_INTERVAL;

    final Bytes actualCacheKey = cacheFunction.cacheKey(THE_KEY);
    final ByteBuffer buffer = ByteBuffer.wrap(actualCacheKey.get());

    assertThat(buffer.getLong(), equalTo(segmentId));

    byte[] actualKey = new byte[buffer.remaining()];
    buffer.get(actualKey);
    assertThat(Bytes.wrap(actualKey), equalTo(THE_KEY));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:SegmentedCacheFunctionTest.java

示例6: toAvro

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Convert a Sqoop's Java representation to Avro representation.
 */
public static Object toAvro(Object o, boolean bigDecimalFormatString) {
  if (o instanceof BigDecimal) {
    if (bigDecimalFormatString) {
      // Returns a string representation of this without an exponent field.
      return ((BigDecimal) o).toPlainString();
    } else {
      return o.toString();
    }
  } else if (o instanceof Date) {
    return ((Date) o).getTime();
  } else if (o instanceof Time) {
    return ((Time) o).getTime();
  } else if (o instanceof Timestamp) {
    return ((Timestamp) o).getTime();
  } else if (o instanceof BytesWritable) {
    BytesWritable bw = (BytesWritable) o;
    return ByteBuffer.wrap(bw.getBytes(), 0, bw.getLength());
  } else if (o instanceof BlobRef) {
    BlobRef br = (BlobRef) o;
    // If blob data is stored in an external .lob file, save the ref file
    // as Avro bytes. If materialized inline, save blob data as Avro bytes.
    byte[] bytes = br.isExternal() ? br.toString().getBytes() : br.getData();
    return ByteBuffer.wrap(bytes);
  } else if (o instanceof ClobRef) {
    throw new UnsupportedOperationException("ClobRef not supported");
  }
  // primitive types (Integer, etc) are left unchanged
  return o;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:33,代码来源:AvroUtil.java

示例7: EncapsInputStream

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public EncapsInputStream(org.omg.CORBA.ORB orb, byte[] buf,
                         int size, boolean littleEndian,
                         GIOPVersion version) {
    super(orb, ByteBuffer.wrap(buf), size, littleEndian,
          version, Message.CDR_ENC_VERSION,
          BufferManagerFactory.newBufferManagerRead(
                                  BufferManagerFactory.GROW,
                                  Message.CDR_ENC_VERSION,
                                  (ORB)orb));

    wrapper = ORBUtilSystemException.get( (ORB)orb,
        CORBALogDomains.RPC_ENCODING ) ;

    performORBVersionSpecificInit();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:EncapsInputStream.java

示例8: testLittleEndianWrappedByteBufferOffset

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static void testLittleEndianWrappedByteBufferOffset(Checksum checksum, long expected) {
    byte[] unaligned_bytes_123456789 = new byte[BYTES_123456789.length + 64];
    for (int i = 0; i < unaligned_bytes_123456789.length - BYTES_123456789.length; i++) {
        checksum.reset();
        System.arraycopy(BYTES_123456789, 0, unaligned_bytes_123456789, i, BYTES_123456789.length);
        ByteBuffer bb = ByteBuffer.wrap(unaligned_bytes_123456789);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        bb.position(i);
        bb.limit(i + BYTES_123456789.length);
        checksum.update(bb);
        checkChecksumOffset(checksum, expected, i);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ChecksumBase.java

示例9: testProcedureId

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * testProcedureId
 */
public void testProcedureId() throws Exception {
    Procedure catalog_proc = this.getProcedure(TARGET_PROCEDURE);
    StoredProcedureInvocation invocation = new StoredProcedureInvocation(CLIENT_HANDLE, "@DatabaseDump", PARAMS);
    invocation.setProcedureId(catalog_proc.getId());
    byte[] invocation_bytes = FastSerializer.serialize(invocation);
    assertNotNull(invocation_bytes);
    
    ByteBuffer buffer = ByteBuffer.wrap(invocation_bytes);
    assertEquals(catalog_proc.getId(), StoredProcedureInvocation.getProcedureId(buffer));
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:14,代码来源:TestStoredProcedureInvocation.java

示例10: decode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Decode a PDU which must contain a PwdModifyRequest extended operation.
 * Note that the stream of bytes much contain a full PDU, not a partial one.
 * 
 * @param stream The bytes to be decoded
 * @return a PwdModifyRequest object
 * @throws org.apache.directory.api.asn1.DecoderException If the decoding failed
 */
public PasswordModifyRequest decode( byte[] stream ) throws DecoderException
{
    ByteBuffer bb = ByteBuffer.wrap( stream );
    PasswordModifyRequestContainer container = new PasswordModifyRequestContainer();
    DECODER.decode( bb, container );
    PasswordModifyRequestDecorator passwordModifyRequest = container.getPwdModifyRequest();

    // Clean the container for the next decoding
    container.clean();

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

示例11: getByteBuffer

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public ByteBuffer getByteBuffer(long offset, int size) throws IOException {
    checkChunkValid(offset, size);
    // checkChunkValid combined with the way instances of this class are constructed ensures
    // that mSliceOffset + offset does not overflow.
    return ByteBuffer.wrap(mArray, (int) (mSliceOffset + offset), size);
}
 
开发者ID:nukc,项目名称:ApkMultiChannelPlugin,代码行数:8,代码来源:ByteArrayDataSink.java

示例12: gen0x11Message

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void gen0x11Message(ClientMessage cm, ArrayList<ServerMessage> smList) throws Exception{
	if(message0x11 == 0){
		return;
	}
	byte[] data = new byte[Constant.SERVER_MESSAGE_MIN_LENGTH+8];//13 bytes
	ByteBuffer bb = ByteBuffer.wrap(data);
	bb.put((byte)1);//version
	bb.put(cm.getData()[1]);//app id
	bb.put((byte)ClientStatMachine.CMD_0x11);//cmd
	bb.putShort((short)8);//length 8
	bb.putLong(message0x11);
	bb.flip();
	ServerMessage sm = new ServerMessage(cm.getSocketAddress(), data);
	smList.add(sm);
}
 
开发者ID:ahhblss,项目名称:ddpush,代码行数:16,代码来源:ClientStatMachine.java

示例13: isValidSnapshot

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Verifies that the file is a valid snapshot. Snapshot may be invalid if 
 * it's incomplete as in a situation when the server dies while in the process
 * of storing a snapshot. Any file that is not a snapshot is also 
 * an invalid snapshot. 
 * 
 * @param f file to verify
 * @return true if the snapshot is valid
 * @throws IOException
 */
public static boolean isValidSnapshot(File f) throws IOException {
    if (f==null || Util.getZxidFromName(f.getName(), "snapshot") == -1)
        return false;

    // Check for a valid snapshot
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    try {
        // including the header and the last / bytes
        // the snapshot should be atleast 10 bytes
        if (raf.length() < 10) {
            return false;
        }
        raf.seek(raf.length() - 5);
        byte bytes[] = new byte[5];
        int readlen = 0;
        int l;
        while(readlen < 5 &&
              (l = raf.read(bytes, readlen, bytes.length - readlen)) >= 0) {
            readlen += l;
        }
        if (readlen != bytes.length) {
            LOG.info("Invalid snapshot " + f
                    + " too short, len = " + readlen);
            return false;
        }
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        int len = bb.getInt();
        byte b = bb.get();
        if (len != 1 || b != '/') {
            LOG.info("Invalid snapshot " + f + " len = " + len
                    + " byte = " + (b & 0xff));
            return false;
        }
    } finally {
        raf.close();
    }

    return true;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:50,代码来源:Util.java

示例14: write

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void write(CoordinatorLogEntry coordinatorLogEntry,
                   boolean flushImmediately) throws IOException {
    String str = Serializer.toJson(coordinatorLogEntry);
    byte[] buffer = str.getBytes();
    ByteBuffer buff = ByteBuffer.wrap(buffer);
    writeToFile(buff, flushImmediately);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:8,代码来源:FileSystemRepository.java

示例15: create

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void create( final List<PrimitiveObject> objList , final byte[] buffer , final int start , final int length ) throws IOException{
  ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer , start , length );
  for( PrimitiveObject obj : objList ){
    wrapBuffer.putInt( (int)( obj.getLong() - min ) );
  }
}
 
开发者ID:yahoojapan,项目名称:multiple-dimension-spread,代码行数:8,代码来源:OptimizeLongColumnBinaryMaker.java


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