Package java.nio

Examples of java.nio.ByteBuffer.order()


  /** Sets a new buffer. The position and total are reset, discarding any buffered bytes. */
  public void setBuffer (byte[] bytes) {
    ByteBuffer directBuffer = ByteBuffer.allocateDirect(bytes.length);
    directBuffer.put(bytes);
    directBuffer.position(0);
    directBuffer.order(byteOrder);
    setBuffer(directBuffer, 0, bytes.length);
  }

  /** Sets a new buffer. The position and total are reset, discarding any buffered bytes. */
  public void setBuffer (ByteBuffer bytes, int offset, int count) {
View Full Code Here


      if (capacity < 0) capacity = maxCapacity;
      ByteBuffer newBuffer = ByteBuffer.allocateDirect(capacity);
      // Copy the whole buffer
      niobuffer.position(0);
      newBuffer.put(niobuffer);
      newBuffer.order(byteOrder);
      niobuffer = newBuffer;
    }
    return true;
  }
View Full Code Here

    int data_len = data.length;
   
    full_len = 1 + 4 + 4 + 2 + 1 + 2 + 4 + data_len;
   
    ByteBuffer buff = ByteBuffer.allocate(100);
    buff.order(ByteOrder.LITTLE_ENDIAN);
    buff.put(byte_order);
    buff.putInt(full_len);
    buff.putInt(serial);
    buff.putShort(package_type);
    buff.put(version);
View Full Code Here

        final int COUNT = 100000;
        System.out.println("Checking performance of different access methods (" + COUNT + " iterations)");
        final int SIZE = 8*1024;
        ByteBuffer b = ByteBuffer.allocateDirect(SIZE);
        // Native order is faster
        b.order(ByteOrder.nativeOrder());
        Pointer pb = Native.getDirectBufferPointer(b);

        String mname = Platform.MATH_LIBRARY_NAME;
        MathInterface mlib = (MathInterface)
            Native.loadLibrary(mname, MathInterface.class);
View Full Code Here

        message.setIov(new ByteBuffer[]{nioBuf});

        if (fd >= 0) {
            CmsgHdr control = message.allocateControl(4);
            ByteBuffer fdBuf = ByteBuffer.allocateDirect(4);
            fdBuf.order(ByteOrder.nativeOrder());
            fdBuf.putInt(fd);
            fdBuf.flip();
            control.setData(fdBuf);
            control.setType(0x01);
            control.setLevel(SocketLevel.SOL_SOCKET.intValue());
View Full Code Here

        writer.align();
        annotationDirectorySectionOffset = writer.getPosition();
        HashMap<AnnotationSetKey, Integer> internedItems = Maps.newHashMap();

        ByteBuffer tempBuffer = ByteBuffer.allocate(65536);
        tempBuffer.order(ByteOrder.LITTLE_ENDIAN);

        for (ClassKey key: classSection.getSortedClasses()) {
            // first, we write the field/method/parameter items to a temporary buffer, so that we can get a count
            // of each type, and determine if we even need to write an annotation directory for this class
View Full Code Here

            // this is how much space we'll need if every field and method has annotations.
            int maxSize = fields.size() * 8 + methods.size() * 16;
            if (maxSize > tempBuffer.capacity()) {
                tempBuffer = ByteBuffer.allocate(maxSize);
                tempBuffer.order(ByteOrder.LITTLE_ENDIAN);
            }

            tempBuffer.clear();

            int fieldAnnotations = 0;
View Full Code Here

    // serialize it into buffer
    int newEventSizeEOP = DbusEventFactory.computeEventLength(DbusEventInternalWritable.EOPMarkerKey, eventInfoEOP);
    int totalSize = newEventSize + newEventSizeEOP;
    ByteBuffer serializationBuffer = ByteBuffer.allocate(totalSize);
    serializationBuffer.order(ByteOrder.BIG_ENDIAN);
    // event itself
    int size = DbusEventFactory.serializeEvent(key, serializationBuffer, eventInfo);
    // EOP
    int size1 = _eventFactory.serializeLongKeyEndOfPeriodMarker(serializationBuffer, eventInfoEOP);
    assert totalSize == (size+size1);
View Full Code Here

    }

    // allocate the buffer
    int newEventSize = eventV1Factory.computeEventLength(key, dbusEventInfo);
    ByteBuffer serializationBuffer = ByteBuffer.allocate(newEventSize);
    serializationBuffer.order(_buf.order());
    int size = DbusEventV1.serializeEvent(key, serializationBuffer, dbusEventInfo);

    if(size != newEventSize)
      throw new DatabusRuntimeException("event size doesn't match after conversion from V2 to V1");
    serializationBuffer.limit(size); // set the limit to the end of the event
View Full Code Here

        }

        // LOG.debug("computed size : {}", size);
        ByteBuffer buffer = ByteBuffer.allocate(size);

        buffer.order(ByteOrder.BIG_ENDIAN);

        // encode header
        buffer.put((byte) (((message.getVersion() & 0x03) << 6) | (message.getType().getCode() & 0x03) << 4 | (message
                .getToken().length & 0x0F)));
        buffer.put((byte) message.getCode());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.