下面列出了java.nio.Buffer#limit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
}
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");
}
}
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");
}
}
static String toString(Buffer b) {
return (b.getClass().getName()
+ "[pos=" + b.position()
+ " lim=" + b.limit()
+ " cap=" + b.capacity()
+ "]");
}
@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();
}
/**
* 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;
}
}
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);
}
}
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;
}
static String toString(Buffer b) {
return (b.getClass().getName()
+ "[pos=" + b.position()
+ " lim=" + b.limit()
+ " cap=" + b.capacity()
+ "]");
}
static String toString(Buffer b) {
return (b.getClass().getName()
+ "[pos=" + b.position()
+ " lim=" + b.limit()
+ " cap=" + b.capacity()
+ "]");
}
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");
}
}
/**
* 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();
}
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());
}
private boolean isFull(Buffer buffer) {
return buffer.limit() == buffer.capacity();
}
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
/**
* 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()));
}
/**
* Returns the number of elements between the limit and capacity.
*/
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
private static int getLimitCount(Buffer buffer, int elementSize) {
checkLimit(buffer);
return buffer.limit() / elementSize;
}