Java 8 LongBuffer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 LongBuffer class.

This code example shows how to use the following methods:hasRemaining, rewind
    return numInserted;
  } 
 
  public void add(long value) throws IOException
  { 
    if (! endBuffer.hasRemaining()) {
      endBuffer.rewind();
      flattener.write(StupidResourceHolder.create(endBuffer));
      endBuffer = LongBuffer.allocate(sizePer);
      endBuffer.mark();
    } 
 
    endBuffer.put(value);
    ++numInserted;
  } 
 
  public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException
  { 
    endBuffer.limit(endBuffer.position());
    endBuffer.rewind();
8
CodeRank
This code example shows how to use the following methods:position, remaining
	    zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(LongBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(DoubleBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	private static native void zeroBuffer0(Buffer b, long off, long size);
 
	/** 
	 * Returns the memory address of the specified buffer. 
	 * 
	 * @param buffer the buffer 
6
CodeRank
This code example shows how to use the following methods:limit, position, remaining, isDirect, order
			return doNoCopyWrap(buffer);
		return buffer;
	} 
 
	public static LongBuffer wrapNoCopyDirect(LongBuffer buffer) {
		if (!buffer.isDirect())
			return doNoCopyWrap(buffer);
		return buffer;
	} 
 
	public static DoubleBuffer wrapNoCopyDirect(DoubleBuffer buffer) {
		if (!buffer.isDirect())
			return doNoCopyWrap(buffer);
		return buffer;
	} 
 
	public static void copy(ByteBuffer src, ByteBuffer dst) {
		if (dst != null && !dst.isDirect()) {
			int saved_position = dst.position();
			dst.put(src);

6
CodeRank
This code example shows how to use the following methods:capacity, clear, asReadOnlyBuffer, duplicate, hashCode
    public void testHasArray() { 
        assertNotNull(buf.array());
    } 
 
    public void testHashCode() { 
        buf.clear();
        LongBuffer readonly = buf.asReadOnlyBuffer();
        LongBuffer duplicate = buf.duplicate();
        assertTrue(buf.hashCode() == readonly.hashCode());
 
        assertTrue(buf.capacity() > 5);
        duplicate.position(buf.capacity() / 2);
        assertTrue(buf.hashCode() != duplicate.hashCode());
    } 
 
    public void testIsDirect() { 
        assertFalse(buf.isDirect());
    } 
 
    public void testOrder() { 
6
CodeRank
This code example shows how to use the following methods:position, remaining
	    zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(LongBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	public static void zeroBuffer(DoubleBuffer b) {
	    zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
	} 
 
	/** Fill buffer with zeros from position to remaining */ 
	private static native void zeroBuffer0(Buffer b, long off, long size);
 
	/** 
	 * Returns the memory address of the specified buffer. 
	 * 
	 * @param buffer the buffer 
5
CodeRank
This code example shows how to use the following methods:limit, position, array, hasArray
     * 
     * @param buffer the Buffer to reference or copy 
     * @see #put(long[]) 
     */ 
    public LongPointer(LongBuffer buffer) {
        super(buffer);
        if (buffer != null && buffer.hasArray()) {
            long[] array = buffer.array();
            allocateArray(array.length);
            put(array);
            position(buffer.position());
            limit(buffer.limit());
        } 
    } 
    /** 
     * Allocates a native {@code long long} array of the given size. 
     * 
     * @param size the number of {@code long long} elements to allocate 
     */ 
    public LongPointer(int size) {
5
CodeRank
This code example shows how to use the following methods:limit, position, put
		LongBuffer buffer = null;
		if(dst instanceof ByteBuffer) buffer = ((ByteBuffer)dst).asLongBuffer();
		else if(dst instanceof LongBuffer) buffer = (LongBuffer)dst;
		if(buffer == null) throw new GdxRuntimeException("dst must be a ByteBuffer or LongBuffer");
		 
		int oldPosition = buffer.position();
		buffer.put(src, srcOffset, numElements);
		buffer.position(oldPosition);
		buffer.limit(oldPosition + numElements);
	} 
 
	/** Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The {@link Buffer} instance's 
	 * {@link Buffer#position()} is used to define the offset into the Buffer itself. The position will stay the same, the limit 
	 * will be set to position + numElements. <b>The Buffer must be a direct Buffer with native byte order. No error checking is 
	 * performed</b>. 
	 *  
	 * @param src the source array. 
	 * @param srcOffset the offset into the source array. 
	 * @param dst the destination Buffer, its position is used as an offset. 
	 * @param numElements the number of elements to copy. */ 
5
CodeRank
This code example shows how to use the following methods:remaining, get
    @Override 
    public final int availableForReading() { 
        if (_readBuffer == null) { // sanity check...
            throw new IllegalStateException("Method should not be called when _readBuffer is null");
        } 
        return _readBuffer.remaining();
    } 
 
    /* 
    /********************************************************************** 
    /* Package methods, appending data 
    /********************************************************************** 
     */ 
     
    @Override 
    public void append(long[] src, int offset, int length) {
        _buffer.put(src, offset, length);
    } 
 
    @Override 

4
CodeRank
This code example shows how to use the following methods:remaining, get
    } 
 
    @Override 
    public void prepend(LongBuffer vs)
    { 
        prepend(vs, vs.remaining());
    } 
 
    @Override 
    public void prepend(LongBuffer vs, int c)
    { 
        prepForPrepend(c);
        vs.get(a, 0, c);
    } 
 
    /** 
     * Makes room in this array for new values to be prepended. 
     * 
     * When this call returns, the values in <code>this.a</code> on <code>[0,c)</code> 
     * are undefined. Writing meaningful values to these indices is up to the 
4
CodeRank
This code example shows how to use the following methods:put
 
    public static byte[] longToByteArray(long l) {
        byte[] bArray = new byte[8];
        ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
        LongBuffer lBuffer = bBuffer.asLongBuffer();
        lBuffer.put(0, l);
        return bArray;
    } 
 
    public static long byteArrayToLong(byte[] b) {
        long l=0;
        for (int i = 0; i < 8; i++) {
            l <<= 8;
            l ^= (long) b[i] & 0xFF;
        } 
        return l;
    } 
} 
4
CodeRank
See Code Examples for Java 8 LongBuffer Methods: