Java Code Examples for java.nio.Buffer#capacity()

The following examples show how to use java.nio.Buffer#capacity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Basic.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 2
Source File: Basic.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 3
Source File: Basic.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 4
Source File: Pointer.java    From tapir with MIT License 5 votes vote down vote up
/**
 * Copies the address, position, limit, and capacity of a direct NIO {@link Buffer}.
 * Also keeps a reference to it to prevent its memory from getting deallocated.
 *
 * @param b the Buffer object to reference
 */
public Pointer(final Buffer b) {
    if (b != null) {
        allocate(b);
    }
    if (!isNull()) {
        position = b.position();
        limit = b.limit();
        capacity = b.capacity();
        deallocator = new Deallocator() { Buffer bb = b; public void deallocate() { bb = null; } };
    }
}
 
Example 5
Source File: Basic.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 6
Source File: MboxIterator.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to log important details about buffers.
 */
public static String bufferDetailsToString(final Buffer buffer) {
    return "Buffer details: " + "\ncapacity:\t" + buffer.capacity() +
            "\nlimit:\t" + buffer.limit() +
            "\nremaining:\t" + buffer.remaining() +
            "\nposition:\t" + buffer.position() +
            "\nbuffer:\t" + buffer.isReadOnly() +
            "\nclass:\t" + buffer.getClass();
}
 
Example 7
Source File: Basic.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 8
Source File: Basic.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 9
Source File: Basic.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 10
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 11
Source File: ByteWriter.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new writer for copying bytes from the given source to the given target buffers.
 * Data will be read from the current position of source buffer up to that buffer <em>limit</em>.
 * Data will be written starting at position 0 of target buffer up to that buffer <em>capacity</em>.
 * The position and limit of target buffer are ignored.
 * The position and limit of both buffers may be modified by this method.
 *
 * @param  source  the buffer from which to copy data.
 * @param  target  the buffer where to copy data.
 * @return a writer from given source to target.
 */
public static ByteWriter create(Buffer source, final ByteBuffer target) {
    if (source.limit() != source.capacity()) {
        source = JDK9.slice(source);
    }
    if (source instanceof DoubleBuffer) return new Doubles ((DoubleBuffer) source, target);
    if (source instanceof  FloatBuffer) return new Floats  ( (FloatBuffer) source, target);
    if (source instanceof   LongBuffer) return new Longs   (  (LongBuffer) source, target);
    if (source instanceof    IntBuffer) return new Integers(   (IntBuffer) source, target);
    if (source instanceof  ShortBuffer) return new Shorts  ( (ShortBuffer) source, target);
    if (source instanceof   ByteBuffer) return new Bytes   (  (ByteBuffer) source, target);
    throw new IllegalArgumentException();
}
 
Example 12
Source File: VertexBuffer.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void updateData(Buffer data) {
	if (id != -1) {
		// request to update data is okay
	}

	// will force renderer to call glBufferData again
	if (this.data.capacity() != data.capacity()) {
		dataSizeChanged = true;
	}
	this.data = data;
	setUpdateNeeded();
}
 
Example 13
Source File: Basic.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 14
Source File: GLTracer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void printBuffer(Buffer buffer) {
    StringBuilder sb = new StringBuilder();
    sb.append(ANSI_MAGENTA);
    if (buffer instanceof ByteBuffer) {
        sb.append("byte");
    } else if (buffer instanceof ShortBuffer) {
        sb.append("short");
    } else if (buffer instanceof CharBuffer) { 
        sb.append("char");
    } else if (buffer instanceof FloatBuffer) {
        sb.append("float");
    } else if (buffer instanceof IntBuffer) {
        sb.append("int");
    } else if (buffer instanceof LongBuffer) {
        sb.append("long");
    } else if (buffer instanceof DoubleBuffer) {
        sb.append("double");
    } else {
        throw new UnsupportedOperationException();
    }
    sb.append(ANSI_RESET);
    sb.append("[");
    
    if (buffer.position() == 0
            && buffer.limit() == buffer.capacity()) {
        // Common case. Just print buffer size.
        sb.append(buffer.capacity());
    } else {
        sb.append("pos=").append(buffer.position());
        sb.append(" lim=").append(buffer.limit());
        sb.append(" cap=").append(buffer.capacity());
    }
    
    sb.append("]");
    print(sb.toString());
}
 
Example 15
Source File: Basic.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static String toString(Buffer b) {
    return (b.getClass().getName()
            + "[pos=" + b.position()
            + " lim=" + b.limit()
            + " cap=" + b.capacity()
            + "]");
}
 
Example 16
Source File: ReaderInputStream.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the number of elements between the limit and capacity. */

  private static int availableCapacity(Buffer buffer) {
    return buffer.capacity() - buffer.limit();
  }
 
Example 17
Source File: ReaderInputStream.java    From FastBootWeixin with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the number of elements between the limit and capacity.
 */
private static int availableCapacity(Buffer buffer) {
    return buffer.capacity() - buffer.limit();
}
 
Example 18
Source File: ReaderInputStream.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the number of elements between the limit and capacity. */

  private static int availableCapacity(Buffer buffer) {
    return buffer.capacity() - buffer.limit();
  }
 
Example 19
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void printCurrentDirectMemory(StringBuilder store) {
    long totalHeld = 0;
    // make a new set to hold the keys to prevent concurrency issues.
    ArrayList<Buffer> bufs = new ArrayList<Buffer>(trackingHash.keySet());
    int fBufs = 0, bBufs = 0, iBufs = 0, sBufs = 0, dBufs = 0;
    int fBufsM = 0, bBufsM = 0, iBufsM = 0, sBufsM = 0, dBufsM = 0;
    for (Buffer b : bufs) {
        if (b instanceof ByteBuffer) {
            totalHeld += b.capacity();
            bBufsM += b.capacity();
            bBufs++;
        } else if (b instanceof FloatBuffer) {
            totalHeld += b.capacity() * 4;
            fBufsM += b.capacity() * 4;
            fBufs++;
        } else if (b instanceof IntBuffer) {
            totalHeld += b.capacity() * 4;
            iBufsM += b.capacity() * 4;
            iBufs++;
        } else if (b instanceof ShortBuffer) {
            totalHeld += b.capacity() * 2;
            sBufsM += b.capacity() * 2;
            sBufs++;
        } else if (b instanceof DoubleBuffer) {
            totalHeld += b.capacity() * 8;
            dBufsM += b.capacity() * 8;
            dBufs++;
        }
    }
    long heapMem = Runtime.getRuntime().totalMemory()
            - Runtime.getRuntime().freeMemory();

    boolean printStout = store == null;
    if (store == null) {
        store = new StringBuilder();
    }
    store.append("Existing buffers: ").append(bufs.size()).append("\n");
    store.append("(b: ").append(bBufs).append("  f: ").append(fBufs).append("  i: ").append(iBufs).append("  s: ").append(sBufs).append("  d: ").append(dBufs).append(")").append("\n");
    store.append("Total   heap memory held: ").append(heapMem / 1024).append("kb\n");
    store.append("Total direct memory held: ").append(totalHeld / 1024).append("kb\n");
    store.append("(b: ").append(bBufsM / 1024).append("kb  f: ").append(fBufsM / 1024).append("kb  i: ").append(iBufsM / 1024).append("kb  s: ").append(sBufsM / 1024).append("kb  d: ").append(dBufsM / 1024).append("kb)").append("\n");
    if (printStout) {
        System.out.println(store.toString());
    }
}
 
Example 20
Source File: ReaderInputStream.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the number of elements between the limit and capacity. */

  private static int availableCapacity(Buffer buffer) {
    return buffer.capacity() - buffer.limit();
  }