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

The following examples show how to use java.nio.Buffer#remaining() . 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: TfNDManager.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public TfNDArray create(Buffer data, Shape shape, DataType dataType) {
    int size = data.remaining();
    // int8, uint8, boolean use ByteBuffer, so need to explicitly input DataType
    DataType inputType = DataType.fromBuffer(data);

    int numOfBytes = inputType.getNumOfBytes();
    ByteBuffer buf = allocateDirect(size * numOfBytes);

    switch (inputType) {
        case FLOAT32:
            buf.asFloatBuffer().put((FloatBuffer) data);
            break;
        case FLOAT64:
            buf.asDoubleBuffer().put((DoubleBuffer) data);
            break;
        case UINT8:
        case INT8:
        case BOOLEAN:
            buf.put((ByteBuffer) data);
            break;
        case INT32:
            buf.asIntBuffer().put((IntBuffer) data);
            break;
        case INT64:
            buf.asLongBuffer().put((LongBuffer) data);
            break;
        case FLOAT16:
        default:
            throw new AssertionError("Show never happen");
    }
    buf.rewind();

    ByteDataBuffer db = DataBuffers.of(buf);
    Tensor<?> tensor = Tensor.of(TfDataType.toTf(dataType), TfNDArray.toTfShape(shape), db);
    return new TfNDArray(this, tensor);
}
 
Example 2
Source File: DwGLTexture3D.java    From PixelFlow with MIT License 5 votes vote down vote up
public void getData_GL2GL3(Buffer buffer){
  int data_len = w * h * num_channel;
  
  if(buffer.remaining() < data_len){
    System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len);
    return;
  }

  GL2GL3 gl23 = gl.getGL2GL3();
  gl23.glBindTexture(target, HANDLE[0]);
  gl23.glGetTexImage(target, 0, format, type, buffer);
  gl23.glBindTexture(target, 0);
  
  DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3");
}
 
Example 3
Source File: IosGL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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: MockNDArray.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void set(Buffer data) {
    int size = data.remaining();
    // int8, uint8, boolean use ByteBuffer, so need to explicitly input DataType
    DataType inputType = DataType.fromBuffer(data);

    int numOfBytes = inputType.getNumOfBytes();
    this.data = ByteBuffer.allocate(size * numOfBytes);

    switch (inputType) {
        case FLOAT32:
            this.data.asFloatBuffer().put((FloatBuffer) data);
            break;
        case FLOAT64:
            this.data.asDoubleBuffer().put((DoubleBuffer) data);
            break;
        case INT8:
            this.data.put((ByteBuffer) data);
            break;
        case INT32:
            this.data.asIntBuffer().put((IntBuffer) data);
            break;
        case INT64:
            this.data.asLongBuffer().put((LongBuffer) data);
            break;
        case UINT8:
        case FLOAT16:
        default:
            throw new AssertionError("Show never happen");
    }
}
 
Example 5
Source File: UTF_8.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 6
Source File: CESU_8.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 7
Source File: CESU_8.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 8
Source File: CESU_8.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 9
Source File: UTF_8.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 10
Source File: CESU_8.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 11
Source File: UTF_8.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 12
Source File: CESU_8.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 13
Source File: CESU_8.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 14
Source File: CESU_8.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 15
Source File: UTF_8.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 16
Source File: CESU_8.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 17
Source File: UTF_8.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 18
Source File: UTF_8.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 19
Source File: UTF_8.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}
 
Example 20
Source File: CESU_8.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static CoderResult xflow(Buffer src, int mark, int nb) {
    src.position(mark);
    return (nb == 0 || src.remaining() < nb)
           ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW;
}