Package java.nio

Examples of java.nio.ByteBuffer.order()


  public static ByteBuffer copy(ByteBuffer buffer) {

    final int length = buffer.limit() - buffer.position();
    final ByteOrder o = buffer.order();
    final ByteBuffer r = ByteBuffer.allocate(length);
    r.order(o);

    r.put(buffer);
    r.clear(); // Reset position and limit after the put()

    return r;
View Full Code Here


   * @param buffer
   * @return
   */
  public static ByteBuffer duplicate(ByteBuffer buffer) {
    final ByteBuffer r = buffer.duplicate();
    r.order(buffer.order());

    return r;
  }
}
View Full Code Here

  public static ByteBuffer createBuffer(final int length) {

    final ByteBuffer data = ByteBuffer.allocate(SnoopPacketRecord.HEADER_LENGTH
        + length);
    data.order(ByteOrder.BIG_ENDIAN);
    final int included = length;
    final int original = included;
    final int record = included + SnoopPacketRecord.HEADER_LENGTH;
    final int drops = 0;
    final long millis = System.currentTimeMillis();
View Full Code Here

      throw new IllegalArgumentException("Editor is no empty."
          + " Can only add new block record to completely empty file.");
    }

    final ByteBuffer b = ByteBuffer.allocate(SnoopBlockRecord.HEADER_LENGTH);
    b.order(editor.order());

    SnoopBlockRecordImpl.initBuffer(b);

    /*
     * Add our new block record at byte offset 0 to the editor.
View Full Code Here

      final long original, final long seconds, final long nanos)
      throws IOException {
    final int included = data.limit() - data.position();
    final int length = included + SnoopPacketRecord.HEADER_LENGTH;
    final ByteBuffer record = ByteBuffer.allocate(length);
    record.order(this.editor.order());

    PcapPacketRecordImpl.initBuffer(record, included, (int) original, seconds,
        (int) nanos / 1000);

    /*
 
View Full Code Here

    if (element instanceof SnoopPacketImpl) {
      final AFilePacket p = (AFilePacket) element;

      final ByteBuffer old = p.getRecordByteBuffer();
      if (old.order() == this.editor.order()) {
        buffer = BufferUtils.slice(old);
      } else {
        throw new IllegalArgumentException(
            "Supplied packet buffer is not in BIG_ENDIAN order. "
                + "Snoop supports only BIG_ENDIAN.");
View Full Code Here

      return b;
    }

    final int length = b.limit() - b.position();
    final ByteBuffer r = ByteBuffer.allocate(length);
    r.order(order);

    r.putInt(b.getInt());
    r.putInt(b.getInt());
    r.putInt(b.getInt());
    r.putInt(b.getInt());
View Full Code Here

    return 0;
  }
 
  public static ByteBuffer getByteBuffer(long bufferSize) {
    ByteBuffer data = ByteBuffer.allocate(8);
    data.order(ByteOrder.LITTLE_ENDIAN);
    data.putLong(bufferSize);
    return ByteBuffer.allocate(data.getInt(0)).order(
        ByteOrder.LITTLE_ENDIAN);
  }
View Full Code Here

        String[] result = new String[size];
        for (int i = 0; i < size; i++)
          result[i] = headerParser.readHeapString(bb, destPos + i * 16); // 16 byte "heap ids" are in the ByteBuffer

        int index = asbb.addObjectToHeap(result);
        bb.order(ByteOrder.nativeOrder()); // the string index is always written in "native order"
        bb.putInt(destPos, index); // overwrite with the index into the StringHeap
      }
    }
  }

View Full Code Here

        } else
          throw new RuntimeException("Unknown filter type="+f.id);
      }

      ByteBuffer result = ByteBuffer.wrap(data);
      result.order(byteOrder);
      return result;
    }

    /**
     * inflate data
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.