本文整理了Java中java.nio.Buffer.hasRemaining()
方法的一些代码示例,展示了Buffer.hasRemaining()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.hasRemaining()
方法的具体详情如下:
包路径:java.nio.Buffer
类名称:Buffer
方法名:hasRemaining
[英]Indicates if there are elements remaining in this buffer, that is if position < limit.
[中]指示此缓冲区中是否还有元素,即位置<限制。
代码示例来源:origin: wildfly/wildfly
/**
* Determine whether any of the buffers has remaining data.
*
* @param buffers the buffers
* @param offs the offset into the buffers array
* @param len the number of buffers to check
* @return {@code true} if any of the selected buffers has remaining data
*/
public static boolean hasRemaining(final Buffer[] buffers, final int offs, final int len) {
for (int i = 0; i < len; i ++) {
if (buffers[i + offs].hasRemaining()) {
return true;
}
}
return false;
}
代码示例来源:origin: stackoverflow.com
ByteBuffer bb = ByteBuffer.wrap(byteArray);
bb.order( ByteOrder.LITTLE_ENDIAN);
while( bb.hasRemaining()) {
short v = bb.getShort();
/* Do something with v... */
}
代码示例来源:origin: Rajawali/Rajawali
public static int[] getIntArrayFromBuffer(Buffer buffer) {
int[] array = new int[0];
if (buffer != null) {
if (buffer.hasArray()) {
array = (int[]) buffer.array();
} else {
buffer.rewind();
array = new int[buffer.capacity()];
if (buffer instanceof IntBuffer) {
((IntBuffer) buffer).get(array);
} else if (buffer instanceof ShortBuffer) {
int count = 0;
while (buffer.hasRemaining()) {
array[count] = (int) (((ShortBuffer) buffer).get());
++count;
}
}
}
}
return array;
}
代码示例来源:origin: Rajawali/Rajawali
/**
* Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}.
*
* @param buffer {@link Buffer} the data source. Should be either a {@link IntBuffer}
* or {@link ShortBuffer}.
* @return int array containing the data of the buffer.
*/
public static int[] getIntArrayFromBuffer(Buffer buffer) {
int[] array = null;
if (buffer.hasArray()) {
array = (int[]) buffer.array();
} else {
buffer.rewind();
array = new int[buffer.capacity()];
if (buffer instanceof IntBuffer) {
((IntBuffer) buffer).get(array);
} else if (buffer instanceof ShortBuffer) {
int count = 0;
while (buffer.hasRemaining()) {
array[count] = (int) (((ShortBuffer) buffer).get());
++count;
}
}
}
return array;
}
}
代码示例来源:origin: wildfly/wildfly
private boolean writeWrappedBuffer(boolean writeFinal) throws IOException {
synchronized (sslEngine.getWrapLock()) {
final ByteBuffer wrapBuffer = sslEngine.getWrappedBuffer();
for (;;) {
try {
if (!wrapBuffer.flip().hasRemaining()) {
if (writeFinal) {
terminateWrites();
}
return true;
}
if(writeFinal) {
if (super.writeFinal(wrapBuffer) == 0) {
return false;
}
} else {
if (super.write(wrapBuffer) == 0) {
return false;
}
}
} finally {
wrapBuffer.compact();
}
}
}
}
代码示例来源:origin: stackoverflow.com
// 4k buffer size.
static final int SIZE = 4 * 1024;
static byte[] buffer = new byte[SIZE];
// Fastest because a FileInputStream has an associated channel.
private static void ScanDataFile(Hunter p, FileInputStream f) throws FileNotFoundException, IOException {
// Use a mapped and buffered stream for best speed.
// See: http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly
final FileChannel ch = f.getChannel();
long red = 0L;
do {
final long read = Math.min(Integer.MAX_VALUE, ch.size() - red);
final MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, red, read);
int nGet;
while (mb.hasRemaining() && p.ok()) {
nGet = Math.min(mb.remaining(), SIZE);
mb.get(buffer, 0, nGet);
for (int i = 0; i < nGet && p.ok(); i++) {
p.check(buffer[i]);
//size += 1;
}
}
red += read;
} while (red < ch.size() && p.ok());
// Finish off.
p.close();
ch.close();
f.close();
}
代码示例来源:origin: stackoverflow.com
final MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, red, read);
int nGet;
while (mb.hasRemaining()) {
nGet = Math.min(mb.remaining(), SIZE);
mb.get(buffer, 0, nGet);
代码示例来源:origin: stackoverflow.com
ByteBuffer buf = ButeBuffer.wrap( bytes );
buf.order( ByteOrder.BIG_ENDIAN );
while ( buf.hasRemaining() ) {
int num = buf.getInt();
// do something with num...
}
代码示例来源:origin: stackoverflow.com
ByteBuffer bb = ... // Byte buffer with your frame or h.264 NAL stream
int marker = 0xffffffff;
while (bb.hasRemaining()) {
int b = bb.get() & 0xff;
if (marker == 1) {
if ((b & 0x1f) == 5)
System.out.println("IDR slice!! " + (bb.position() - 1));
}
marker = (marker << 8) | b;
}
代码示例来源:origin: stackoverflow.com
FileInputStream f = new FileInputStream(fileName);
FileChannel ch = f.getChannel( );
MappedByteBuffer mbb = ch.map( ch.MapMode.READ_ONLY, 0L, ch.size( ) );
while ( mbb.hasRemaining( ) ) {
// Access the data using the mbb
}
代码示例来源:origin: stackoverflow.com
byte[] payload = new byte[]{0x7F,0x1B,0x10,0x11};
ByteBuffer bb = ByteBuffer.wrap(payload).order(ByteOrder.BIG_ENDIAN);
ShortBuffer sb = bb.asShortBuffer();
while(sb.hasRemaining()){
System.out.println(sb.get());
}
代码示例来源:origin: stackoverflow.com
final ByteBuffer orig = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)
.asReadOnlyBuffer();
final ByteBuffer transformed = ByteBuffer.wrap(bytes.length)
.order(ByteOrder.LITTLE_ENDIAN);
while (orig.hasRemaining())
transformed.putShort(orig.getShort() >>> 1);
return transformed.array();
代码示例来源:origin: stackoverflow.com
public static BigInteger parityWordChecksum(BigInteger key) {
LongBuffer buffer = ByteBuffer.wrap(key.toByteArray()).asLongBuffer();
long xor = 0;
while (buffer.hasRemaining()) {
xor ^= buffer.get();
}
ByteBuffer result = ByteBuffer.allocate(8);
result.putLong(xor);
return new BigInteger(1, result.array()); // Signum 1 for unsigned
}
代码示例来源:origin: stackoverflow.com
ByteBuffer buf = ByteBuffer.allocate(BUF_SIZE);
FileChannel fileChannel = fileInputStream.getChannel();
int readCount = 0;
while ( (readCount = fileChannel.read(buf)) > 0) {
buf.flip();
while (buf.hasRemaining()) {
byte b = buf.get();
}
buf.clear();
}
代码示例来源:origin: com.gitee.l0km/common-base
public static final void notEmptyElement(Buffer[] t,String arg){
notEmpty(t,arg);
for(int i=0;i<t.length;i++){
if (null == t[i] || !t[i].hasRemaining()) {
throw new IllegalArgumentException(String.format("%s:%s[%d] is null or empty",getLocation(),arg,i));
}
}
}
public static final void notEmptyElement(Collection<Buffer> t,String arg){
代码示例来源:origin: com.gitee.l0km/common-base
public static final void notEmptyElement(Collection<Buffer> t,String arg){
notEmpty(t,arg);
for(Buffer buffer:t){
if (null == buffer || !buffer.hasRemaining()) {
throw new IllegalArgumentException(String.format("%s:%s have null or empty element",getLocation(),arg));
}
}
}
public static final <T extends Collection<?>>void notEmpty(T t,String arg){
代码示例来源:origin: gov.nasa.gsfc.heasarc/nom-tam-fits
@Override
public void appendToByteBuffer(ByteBuffer byteBuffer, B dataToAppend) {
byte[] temp = new byte[Math.min(COPY_BLOCK_SIZE * this.size, dataToAppend.remaining() * this.size)];
B typedBuffer = asTypedBuffer(ByteBuffer.wrap(temp));
Object array = newArray(Math.min(COPY_BLOCK_SIZE, dataToAppend.remaining()));
while (dataToAppend.hasRemaining()) {
int part = Math.min(COPY_BLOCK_SIZE, dataToAppend.remaining());
getArray(dataToAppend, array, part);
putArray(typedBuffer, array, part);
byteBuffer.put(temp, 0, part * this.size);
}
}
代码示例来源:origin: com.ardor3d/ardor3d-core
@Override
public void put(final IndexBufferData<?> buf) {
if (buf instanceof ShortBufferData) {
_buffer.put((ShortBuffer) buf.getBuffer());
} else {
while (buf.getBuffer().hasRemaining()) {
put(buf.get());
}
}
}
代码示例来源:origin: com.ardor3d/ardor3d-core
@Override
public void put(final IndexBufferData<?> buf) {
if (buf instanceof ByteBufferData) {
_buffer.put((ByteBuffer) buf.getBuffer());
} else {
while (buf.getBuffer().hasRemaining()) {
put(buf.get());
}
}
}
代码示例来源:origin: Renanse/Ardor3D
@Override
public void put(final IndexBufferData<?> buf) {
if (buf instanceof ByteBufferData) {
_buffer.put((ByteBuffer) buf.getBuffer());
} else {
while (buf.getBuffer().hasRemaining()) {
put(buf.get());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!