Java Code Examples for java.nio.Buffer#limit()
The following examples show how to use
java.nio.Buffer#limit() .
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: GLTracer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 2
Source File: LwjglGLExt.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkLimit(Buffer buffer) { if (buffer == null) { return; } if (buffer.limit() == 0) { throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); } if (buffer.remaining() == 0) { throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); } }
Example 3
Source File: IosGL.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkLimit(Buffer buffer) { if (buffer == null) { return; } if (buffer.limit() == 0) { throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); } if (buffer.remaining() == 0) { throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); } }
Example 4
Source File: LwjglGLFboGL3.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkLimit(Buffer buffer) { if (buffer == null) { return; } if (buffer.limit() == 0) { throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); } if (buffer.remaining() == 0) { throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); } }
Example 5
Source File: Basic.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static String toString(Buffer b) { return (b.getClass().getName() + "[pos=" + b.position() + " lim=" + b.limit() + " cap=" + b.capacity() + "]"); }
Example 6
Source File: DefaultDataBuffer.java From java-technology-stack with MIT License | 5 votes |
@Override public ByteBuffer asByteBuffer(int index, int length) { checkIndex(index, length); ByteBuffer duplicate = this.byteBuffer.duplicate(); // Explicit access via Buffer base type for compatibility // with covariant return type on JDK 9's ByteBuffer... Buffer buffer = duplicate; buffer.position(index); buffer.limit(index + length); return duplicate.slice(); }
Example 7
Source File: BufferedFile.java From apm-agent-java with Apache License 2.0 | 5 votes |
/** * Sets the position of the file without reading new data. * * @param pos the new position */ public void position(long pos) { Buffer buffer = this.buffer; long positionDelta = pos - position(); long newBufferPos = buffer.position() + positionDelta; if (0 <= newBufferPos && newBufferPos <= buffer.limit()) { buffer.position((int) newBufferPos); } else { // makes sure that the next ensureRemaining will load from file buffer.position(0); buffer.limit(0); offset = pos; } }
Example 8
Source File: SamplingProfiler.java From apm-agent-java with Apache License 2.0 | 5 votes |
private void readActivationEventsToBuffer(FileChannel activationEventsFileChannel, long eof, ByteBuffer byteBuffer) throws IOException { Buffer buf = byteBuffer; buf.clear(); long remaining = eof - activationEventsFileChannel.position(); activationEventsFileChannel.read(byteBuffer); buf.flip(); if (remaining < buf.capacity()) { buf.limit((int) remaining); } }
Example 9
Source File: SamplingProfiler.java From apm-agent-java with Apache License 2.0 | 5 votes |
long startProcessingActivationEventsFile() throws IOException { Buffer activationEventsBuffer = this.activationEventsBuffer; if (activationEventsFileChannel.position() > 0) { flushActivationEvents(); activationEventsBuffer.limit(0); } else { activationEventsBuffer.flip(); } long eof = activationEventsFileChannel.position(); activationEventsFileChannel.position(0); return eof; }
Example 10
Source File: MboxIterator.java From SnowGraph with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: Basic.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static String toString(Buffer b) { return (b.getClass().getName() + "[pos=" + b.position() + " lim=" + b.limit() + " cap=" + b.capacity() + "]"); }
Example 12
Source File: Basic.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static String toString(Buffer b) { return (b.getClass().getName() + "[pos=" + b.position() + " lim=" + b.limit() + " cap=" + b.capacity() + "]"); }
Example 13
Source File: AndroidGL.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void checkLimit(Buffer buffer) { if (buffer == null) { return; } if (buffer.limit() == 0) { throw new RendererException("Attempting to upload empty buffer (limit = 0), that's an error"); } if (buffer.remaining() == 0) { throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error"); } }
Example 14
Source File: ReaderInputStream.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the number of elements between the limit and capacity. */ private static int availableCapacity(Buffer buffer) { return buffer.capacity() - buffer.limit(); }
Example 15
Source File: IosGL.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static int getLimitCount(Buffer buffer, int elementSize) { checkLimit(buffer); return buffer.limit() / elementSize; }
Example 16
Source File: ReaderInputStream.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
/** 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 |
/** * 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: ByteWriter.java From sis with Apache License 2.0 | 4 votes |
/** * Prepares the given source and target buffers to a new transfer. */ private static void reset(final Buffer source, final Buffer target) { target.clear(); source.limit(Math.min(source.capacity(), source.position() + target.capacity())); }
Example 19
Source File: OutputBuffer.java From Tomcat8-Source-Read with MIT License | 4 votes |
private boolean isFull(Buffer buffer) { return buffer.limit() == buffer.capacity(); }
Example 20
Source File: ReaderInputStream.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
/** Returns the number of elements between the limit and capacity. */ private static int availableCapacity(Buffer buffer) { return buffer.capacity() - buffer.limit(); }