Java Code Examples for java.nio.Buffer

The following are top voted examples for showing how to use java.nio.Buffer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: googles-monorepo-demo   File: ArbitraryInstancesTest.java   Source Code and License 6 votes vote down vote up
public void testGet_io() throws IOException {
  assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
  assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
  assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
  assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
  ArbitraryInstances.get(PrintStream.class).println("test");
  ArbitraryInstances.get(PrintWriter.class).println("test");
  assertNotNull(ArbitraryInstances.get(File.class));
  assertFreshInstanceReturned(
      ByteArrayOutputStream.class, OutputStream.class,
      Writer.class, StringWriter.class,
      PrintStream.class, PrintWriter.class);
  assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
  assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
  assertNotNull(ArbitraryInstances.get(ByteSink.class));
  assertNotNull(ArbitraryInstances.get(CharSink.class));
}
 
Example 2
Project: Maxine-VM   File: JniFunctions.java   Source Code and License 6 votes vote down vote up
@VM_ENTRY_POINT
private static long GetDirectBufferCapacity(Pointer env, JniHandle buffer) {
    // Source: JniFunctionsSource.java:1766
    Pointer anchor = prologue(env);
    if (logger.enabled()) {
        logger.log(LogOperations.GetDirectBufferCapacity.ordinal(), UPCALL_ENTRY, anchor, env, buffer);
    }

    try {
        Object buf = buffer.unhand();
        if (DirectByteBuffer.isInstance(buf)) {
            return ((Buffer) buf).capacity();
        }
        return -1;
    } catch (Throwable t) {
        VmThread.fromJniEnv(env).setJniException(t);
        return JNI_ERR;
    } finally {
        epilogue(anchor);
        if (logger.enabled()) {
            logger.log(LogOperations.GetDirectBufferCapacity.ordinal(), UPCALL_EXIT);
        }

    }
}
 
Example 3
Project: guava-mock   File: ArbitraryInstancesTest.java   Source Code and License 6 votes vote down vote up
public void testGet_io() throws IOException {
  assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
  assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
  assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
  assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
  ArbitraryInstances.get(PrintStream.class).println("test");
  ArbitraryInstances.get(PrintWriter.class).println("test");
  assertNotNull(ArbitraryInstances.get(File.class));
  assertFreshInstanceReturned(
      ByteArrayOutputStream.class, OutputStream.class,
      Writer.class, StringWriter.class,
      PrintStream.class, PrintWriter.class);
  assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
  assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
  assertNotNull(ArbitraryInstances.get(ByteSink.class));
  assertNotNull(ArbitraryInstances.get(CharSink.class));
}
 
Example 4
Project: Fatigue-Detection   File: OpenGlUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(Buffer paramBuffer, int paramInt1, int paramInt2, int paramInt3)
{
    int[] arrayOfInt = new int[1];
    if (paramInt3 == -1)
    {
        GLES20.glGenTextures(1, arrayOfInt, 0);
        GLES20.glBindTexture(3553, arrayOfInt[0]);
        GLES20.glTexParameterf(3553, 10240, 9729.0F);

        GLES20.glTexParameterf(3553, 10241, 9729.0F);

        GLES20.glTexParameterf(3553, 10242, 33071.0F);

        GLES20.glTexParameterf(3553, 10243, 33071.0F);

        GLES20.glTexImage2D(3553, 0, 6408, paramInt1, paramInt2, 0, 6408, 5121, paramBuffer);
    }
    else
    {
        GLES20.glBindTexture(3553, paramInt3);
        GLES20.glTexSubImage2D(3553, 0, 0, 0, paramInt1, paramInt2, 6408, 5121, paramBuffer);

        arrayOfInt[0] = paramInt3;
    }
    return arrayOfInt[0];
}
 
Example 5
Project: PaoMovie   File: OpenGLUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId) {
if(data == null)
	return NO_TEXTURE;
   int textures[] = new int[1];
   if (usedTexId == NO_TEXTURE) {
       GLES20.glGenTextures(1, textures, 0);
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 6
Project: PaoMovie   File: OpenGLUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId,final int type) {
if(data == null)
	return NO_TEXTURE;
   int textures[] = new int[1];
   if (usedTexId == NO_TEXTURE) {
       GLES20.glGenTextures(1, textures, 0);
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, type, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, type, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 7
Project: debug   File: EXTDirectStateAccess.java   Source Code and License 6 votes vote down vote up
private static void glTextureImage3DEXT_trace(int texture, int target, int level, int internalformat, int width, int height, int depth, int border, int format, int type, Buffer pixels,
        MethodCall mc) {
    mc.param(texture);
    mc.paramEnum(GLmetadata.TextureTarget().get(target));
    mc.param(level);
    if (internalformat >= 1 && internalformat <= 4)
        mc.param(internalformat);
    else
        mc.paramEnum(GLmetadata.InternalFormat().get(internalformat));
    mc.param(width);
    mc.param(height);
    mc.param(depth);
    mc.param(border);
    mc.paramEnum(GLmetadata.PixelFormat().get(format));
    mc.paramEnum(GLmetadata.PixelType().get(type));
    mc.param(pixels);
}
 
Example 8
Project: Ultraino   File: BufferUtils.java   Source Code and License 6 votes vote down vote up
private static boolean isDirect(Buffer buf) {
    if (buf instanceof FloatBuffer) {
        return ((FloatBuffer) buf).isDirect();
    }
    if (buf instanceof IntBuffer) {
        return ((IntBuffer) buf).isDirect();
    }
    if (buf instanceof ShortBuffer) {
        return ((ShortBuffer) buf).isDirect();
    }
    if (buf instanceof ByteBuffer) {
        return ((ByteBuffer) buf).isDirect();
    }
    if (buf instanceof DoubleBuffer) {
        return ((DoubleBuffer) buf).isDirect();
    }
    if (buf instanceof LongBuffer) {
        return ((LongBuffer) buf).isDirect();
    }
    throw new UnsupportedOperationException(" BufferAux.isDirect was called on " + buf.getClass().getName());
}
 
Example 9
Project: FilterPlayer   File: OpenGlUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId,final int type) {
    if(data == null)
        return NO_TEXTURE;
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
                0, GLES20.GL_RGBA, type, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
                height, GLES20.GL_RGBA, type, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 10
Project: Ultraino   File: BufferUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a clone of the given buffer. The clone's capacity is 
 * equal to the given buffer's limit.
 * 
 * @param buf The buffer to clone
 * @return The cloned buffer
 */
public static Buffer clone(Buffer buf) {
    if (buf instanceof FloatBuffer) {
        return clone((FloatBuffer) buf);
    } else if (buf instanceof ShortBuffer) {
        return clone((ShortBuffer) buf);
    } else if (buf instanceof ByteBuffer) {
        return clone((ByteBuffer) buf);
    } else if (buf instanceof IntBuffer) {
        return clone((IntBuffer) buf);
    } else if (buf instanceof DoubleBuffer) {
        return clone((DoubleBuffer) buf);
    } else {
        throw new UnsupportedOperationException();
    }
}
 
Example 11
Project: openjdk-jdk10   File: SingleByte.java   Source Code and License 5 votes vote down vote up
private static final CoderResult withResult(CoderResult cr,
                                            Buffer src, int sp,
                                            Buffer dst, int dp)
{
    src.position(sp - src.arrayOffset());
    dst.position(dp - dst.arrayOffset());
    return cr;
}
 
Example 12
Project: hadoop-oss   File: ZlibDecompressor.java   Source Code and License 5 votes vote down vote up
int inflateDirect(ByteBuffer src, ByteBuffer dst) throws IOException {
  assert (this instanceof ZlibDirectDecompressor);
  
  ByteBuffer presliced = dst;
  if (dst.position() > 0) {
    presliced = dst;
    dst = dst.slice();
  }

  Buffer originalCompressed = compressedDirectBuf;
  Buffer originalUncompressed = uncompressedDirectBuf;
  int originalBufferSize = directBufferSize;
  compressedDirectBuf = src;
  compressedDirectBufOff = src.position();
  compressedDirectBufLen = src.remaining();
  uncompressedDirectBuf = dst;
  directBufferSize = dst.remaining();
  int n = 0;
  try {
    n = inflateBytesDirect();
    presliced.position(presliced.position() + n);
    if (compressedDirectBufLen > 0) {
      src.position(compressedDirectBufOff);
    } else {
      src.position(src.limit());
    }
  } finally {
    compressedDirectBuf = originalCompressed;
    uncompressedDirectBuf = originalUncompressed;
    compressedDirectBufOff = 0;
    compressedDirectBufLen = 0;
    directBufferSize = originalBufferSize;
  }
  return n;
}
 
Example 13
Project: TriMeshKit   File: TriMesh.java   Source Code and License 5 votes vote down vote up
public Buffer getFacesIndices()
  {
if(mDirty)
{
	mFacesIndices = BufferUtility.getIntBuffer(getInternalFacesIndices());
	mDirty = false;
}
return mFacesIndices;
  }
 
Example 14
Project: ftljson   File: Unsafe.java   Source Code and License 5 votes vote down vote up
private static long findBufferAddress() {
	try {
		return UNSAFE.objectFieldOffset(getDeclaredField(Buffer.class, "address"));
	} catch (Exception e) {
		throw new UnsupportedOperationException("Could not detect ByteBuffer.address offset", e);
	}
}
 
Example 15
Project: guava-mock   File: FreshValueGeneratorTest.java   Source Code and License 5 votes vote down vote up
@AndroidIncompatible // problem with equality of Type objects?
public void testFreshInstance() {
  assertFreshInstances(
      String.class, CharSequence.class,
      Appendable.class, StringBuffer.class, StringBuilder.class,
      Pattern.class, MatchResult.class,
      Number.class, int.class, Integer.class,
      long.class, Long.class,
      short.class, Short.class,
      byte.class, Byte.class,
      boolean.class, Boolean.class,
      char.class, Character.class,
      int[].class, Object[].class,
      UnsignedInteger.class, UnsignedLong.class,
      BigInteger.class, BigDecimal.class,
      Throwable.class, Error.class, Exception.class, RuntimeException.class,
      Charset.class, Locale.class, Currency.class,
      List.class, Map.Entry.class,
      Object.class,
      Equivalence.class, Predicate.class, Function.class,
      Comparable.class, Comparator.class, Ordering.class,
      Class.class, Type.class, TypeToken.class,
      TimeUnit.class, Ticker.class,
      Joiner.class, Splitter.class, CharMatcher.class,
      InputStream.class, ByteArrayInputStream.class,
      Reader.class, Readable.class, StringReader.class,
      OutputStream.class, ByteArrayOutputStream.class,
      Writer.class, StringWriter.class, File.class,
      Buffer.class, ByteBuffer.class, CharBuffer.class,
      ShortBuffer.class, IntBuffer.class, LongBuffer.class,
      FloatBuffer.class, DoubleBuffer.class,
      String[].class, Object[].class, int[].class);
}
 
Example 16
Project: jdk8u-jdk   File: Basic.java   Source Code and License 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 17
Project: TriMeshKit   File: TriMesh.java   Source Code and License 5 votes vote down vote up
public Buffer getVerticesPoints()
  {
if(mDirty)
{
	mPositions = BufferUtility.getFloatBuffer(getInternalVerticesPoints());
}

return mPositions;
  }
 
Example 18
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static boolean checkNativeByteOrder(Buffer buf) {
    if (buf == null) {
        return true;
    }
    throwIfNotNativeEndianness(bufferEndiannessWritten.get(buf));
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        throwIfNotNativeEndianness(bufferEndiannessWritten.get(viewedBuffer));
    }
    return true;
}
 
Example 19
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
private static void writeByteBuffer(ByteBuffer buf) {
    ByteOrder order = bufferEndiannessWritten.get(buf);
    if (order == null) {
        Buffer viewedBuffer = bufferViews.get(buf);
        if (viewedBuffer != null) {
            bufferEndiannessWritten.put(viewedBuffer, buf.order());
        } else {
            bufferEndiannessWritten.put(buf, buf.order());
        }
    }
}
 
Example 20
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
private static void writeShortBuffer(ShortBuffer buf) {
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferEndiannessWritten.put(viewedBuffer, buf.order());
    } else {
        /* We don't know how that typed view was created. Just assume it is correct. */
    }
}
 
Example 21
Project: openjdk-jdk10   File: ByteBufferTest.java   Source Code and License 5 votes vote down vote up
Buffer asView(ByteBuffer b, PrimitiveType t) {
    switch (t) {
        case BYTE: return b;
        case CHAR: return b.asCharBuffer();
        case SHORT: return b.asShortBuffer();
        case INT: return b.asIntBuffer();
        case LONG: return b.asLongBuffer();
        case FLOAT: return b.asFloatBuffer();
        case DOUBLE: return b.asDoubleBuffer();
    }
    throw new InternalError("Should not reach here");
}
 
Example 22
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
private static void writeDoubleBuffer(DoubleBuffer buf) {
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferEndiannessWritten.put(viewedBuffer, buf.order());
    } else {
        throw new AssertionError();
    }
}
 
Example 23
Project: bloom   File: Platform.java   Source Code and License 5 votes vote down vote up
public static long getByteBufferAddress(ByteBuffer buffer) {
  try {
    return getField(Buffer.class, "address").getLong(buffer);
  } catch (IllegalAccessException e) {
    throw new IllegalStateException(e);
  }
}
 
Example 24
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static IntBuffer slice(IntBuffer buf) {
    IntBuffer buffer = buf.slice();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    }
    return buffer;
}
 
Example 25
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static LongBuffer slice(LongBuffer buf) {
    LongBuffer buffer = buf.slice();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    }
    return buffer;
}
 
Example 26
Project: openjdk-jdk10   File: ByteBufferTest.java   Source Code and License 5 votes vote down vote up
void asViewGetOne(Buffer v, PrimitiveType t, int index) {
    switch (t) {
        case BYTE: ((ByteBuffer) v).get(index); break;
        case CHAR: ((CharBuffer) v).get(index); break;
        case SHORT: ((ShortBuffer) v).get(index); break;
        case INT: ((IntBuffer) v).get(index); break;
        case LONG: ((LongBuffer) v).get(index); break;
        case FLOAT: ((FloatBuffer) v).get(index); break;
        case DOUBLE: ((DoubleBuffer) v).get(index); break;
    }
}
 
Example 27
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static ShortBuffer asShortBuffer(ByteBuffer buf) {
    ShortBuffer buffer = buf.asShortBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
Example 28
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static IntBuffer asIntBuffer(ByteBuffer buf) {
    IntBuffer buffer = buf.asIntBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
Example 29
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static LongBuffer asLongBuffer(ByteBuffer buf) {
    LongBuffer buffer = buf.asLongBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
Example 30
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
public static FloatBuffer asFloatBuffer(ByteBuffer buf) {
    FloatBuffer buffer = buf.asFloatBuffer();
    Buffer viewedBuffer = bufferViews.get(buf);
    if (viewedBuffer != null) {
        bufferViews.put(buffer, viewedBuffer);
    } else {
        bufferViews.put(buffer, buf);
    }
    return buffer;
}
 
Example 31
Project: debug   File: RT.java   Source Code and License 5 votes vote down vote up
private static void checkBufferDirect(Buffer buffer, String type) {
    if (buffer == null) {
        return;
    }
    if (!buffer.isDirect()) {
        throwIAEOrLogError("buffer is not direct. Buffers created via " + type + ".allocate() or " + type + ".wrap() are not supported. " + "Use BufferUtils.create" + type + "() instead.");
    } else if (buffer.remaining() == 0) {
        throwIAEOrLogError("buffer has no remaining elements. Did you forget to flip()/rewind() it?");
    }
}
 
Example 32
Project: debug   File: GL11.java   Source Code and License 5 votes vote down vote up
private static void glTexImage1D_trace(int target, int level, int internalformat, int width, int border, int format, int type, Buffer pixels, MethodCall mc) {
    mc.paramEnum(GLmetadata.TextureTarget().get(target));
    mc.param(level);
    if (internalformat >= 1 && internalformat <= 4)
        mc.param(internalformat);
    else
        mc.paramEnum(RT.glEnumFor(internalformat, GLmetadata.InternalFormat()));
    mc.param(width);
    mc.param(border);
    mc.paramEnum(RT.glEnumFor(format, GLmetadata.PixelFormat()));
    mc.paramEnum(RT.glEnumFor(type, GLmetadata.PixelType()));
    mc.param(pixels);
}
 
Example 33
Project: debug   File: EXTDirectStateAccess.java   Source Code and License 5 votes vote down vote up
private static void glMultiTexImage1DEXT_trace(int texunit, int target, int level, int internalformat, int width, int border, int format, int type, Buffer pixels, MethodCall mc) {
    mc.paramEnum(GLmetadata._null_().get(texunit));
    mc.paramEnum(GLmetadata.TextureTarget().get(target));
    mc.param(level);
    if (internalformat >= 1 && internalformat <= 4)
        mc.param(internalformat);
    else
        mc.paramEnum(GLmetadata.InternalFormat().get(internalformat));
    mc.param(width);
    mc.param(border);
    mc.paramEnum(GLmetadata.PixelFormat().get(format));
    mc.paramEnum(GLmetadata.PixelType().get(type));
    mc.param(pixels);
}
 
Example 34
Project: debug   File: EXTDirectStateAccess.java   Source Code and License 5 votes vote down vote up
private static void glTextureImage1DEXT_trace(int texture, int target, int level, int internalformat, int width, int border, int format, int type, Buffer pixels, MethodCall mc) {
    mc.param(texture);
    mc.paramEnum(GLmetadata.TextureTarget().get(target));
    mc.param(level);
    if (internalformat >= 1 && internalformat <= 4)
        mc.param(internalformat);
    else
        mc.paramEnum(GLmetadata.InternalFormat().get(internalformat));
    mc.param(width);
    mc.param(border);
    mc.paramEnum(GLmetadata.PixelFormat().get(format));
    mc.paramEnum(GLmetadata.PixelType().get(type));
    mc.param(pixels);
}
 
Example 35
Project: debug   File: EXTDirectStateAccess.java   Source Code and License 5 votes vote down vote up
private static void glTextureImage2DEXT_trace(int texture, int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels, MethodCall mc) {
    mc.param(texture);
    mc.paramEnum(GLmetadata.TextureTarget().get(target));
    mc.param(level);
    if (internalformat >= 1 && internalformat <= 4)
        mc.param(internalformat);
    else
        mc.paramEnum(GLmetadata.InternalFormat().get(internalformat));
    mc.param(width);
    mc.param(height);
    mc.param(border);
    mc.paramEnum(GLmetadata.PixelFormat().get(format));
    mc.paramEnum(GLmetadata.PixelType().get(type));
    mc.param(pixels);
}
 
Example 36
Project: VideoRecorder-master   File: FFmpegRecorderActivity.java   Source Code and License 5 votes vote down vote up
/**
 * shortBuffer包含了音频的数据和起始位置
 *
 * @param shortBuffer
 */
private void record(ShortBuffer shortBuffer) {
    try {
        if (videoRecorder != null) {
            this.mCount += shortBuffer.limit();
            videoRecorder.record(0, new Buffer[]{shortBuffer});
        }
    } catch (FrameRecorder.Exception localException) {

    }
    return;
}
 
Example 37
Project: Ultraino   File: BufferUtils.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {
    try {
        while (true) {
            Reference<? extends Buffer> toclean = BufferUtils.removeCollected.remove();
            BufferUtils.trackedBuffers.remove(toclean);
        }

    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 38
Project: accelerator-core-android   File: ScreenSharingCapturer.java   Source Code and License 5 votes vote down vote up
@Override
public void onImageAvailable(ImageReader reader) {
        Image mImage = null;
        FileOutputStream fos = null;

        try {
            mImage = mImageReader.acquireLatestImage();

            if (mImage != null) {
                int imgWidth = mImage.getWidth();
                int imgHeight = mImage.getHeight();

                Image.Plane[] planes = mImage.getPlanes();
                ByteBuffer buffer = planes[0].getBuffer();
                int pixelStride = planes[0].getPixelStride();
                int rowStride = planes[0].getRowStride();
                int rowPadding = rowStride - pixelStride * imgWidth;

                Buffer buffer2 = planes[0].getBuffer().rewind();
                bmp = Bitmap.createBitmap(imgWidth + rowPadding / pixelStride, imgHeight, Bitmap.Config.ARGB_8888);

                bmp.copyPixelsFromBuffer(buffer2);
                lastBmp = bmp.copy(bmp.getConfig(), true);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bmp != null) {
                bmp.recycle();
            }

            if (mImage != null) {
                mImage.close();
            }
        }
}
 
Example 39
Project: FlickLauncher   File: GLES20Canvas.java   Source Code and License 5 votes vote down vote up
private int uploadBuffer(Buffer buffer, int elementSize) {
    mGLId.glGenBuffers(1, mTempIntArray, 0);
    checkError();
    int bufferId = mTempIntArray[0];
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferId);
    checkError();
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, buffer.capacity() * elementSize, buffer,
            GLES20.GL_STATIC_DRAW);
    checkError();
    return bufferId;
}
 
Example 40
Project: jdk8u-jdk   File: CESU_8.java   Source Code and License 4 votes vote down vote up
private static final void updatePositions(Buffer src, int sp,
                                          Buffer dst, int dp) {
    src.position(sp - src.arrayOffset());
    dst.position(dp - dst.arrayOffset());
}