Java Code Examples for java.nio.Buffer#clear()
The following examples show how to use
java.nio.Buffer#clear() .
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: BufferedFile.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Override public void resetState() { if (fileChannel == null) { throw new IllegalStateException("setFile has not been called yet"); } Buffer buffer = this.buffer; buffer.clear(); offset = 0; wholeFileInBuffer = false; try { fileChannel.close(); } catch (IOException ignore) { } fileChannel = null; this.buffer = null; }
Example 2
Source File: Util.java From feign with Apache License 2.0 | 6 votes |
/** * Adapted from {@code com.google.common.io.CharStreams.toString()}. */ public static String toString(Reader reader) throws IOException { if (reader == null) { return null; } try { StringBuilder to = new StringBuilder(); CharBuffer charBuf = CharBuffer.allocate(BUF_SIZE); // must cast to super class Buffer otherwise break when running with java 11 Buffer buf = charBuf; while (reader.read(charBuf) != -1) { buf.flip(); to.append(charBuf); buf.clear(); } return to.toString(); } finally { ensureClosed(reader); } }
Example 3
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 4
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) { Mesh.Mode mode = mesh.getMode(); Buffer indexData = indexBuf.getData(); indexData.clear(); if (mesh.getMode() == Mode.Hybrid) { int[] modeStart = mesh.getModeStart(); int[] elementLengths = mesh.getElementLengths(); int elMode = convertElementMode(Mode.Triangles); int fmt = convertVertexFormat(indexBuf.getFormat()); // int elSize = indexBuf.getFormat().getComponentSize(); // int listStart = modeStart[0]; int stripStart = modeStart[1]; int fanStart = modeStart[2]; int curOffset = 0; for (int i = 0; i < elementLengths.length; i++) { if (i == stripStart) { elMode = convertElementMode(Mode.TriangleStrip); } else if (i == fanStart) { elMode = convertElementMode(Mode.TriangleStrip); } int elementLength = elementLengths[i]; indexData.position(curOffset); gl.glDrawElements(elMode, elementLength, fmt, indexData); curOffset += elementLength; } } else { gl.glDrawElements(convertElementMode(mode), indexData.capacity(), convertVertexFormat(indexBuf.getFormat()), indexData); } }
Example 5
Source File: AbstractRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) { Mesh.Mode mode = mesh.getMode(); Buffer indexData = indexBuf.getData(); indexData.clear(); if (mesh.getMode() == Mode.Hybrid) { int[] modeStart = mesh.getModeStart(); int[] elementLengths = mesh.getElementLengths(); Mode elMode = Mode.Triangles; // int elSize = indexBuf.getFormat().getComponentSize(); // int listStart = modeStart[0]; int stripStart = modeStart[1]; int fanStart = modeStart[2]; int curOffset = 0; for (int i = 0; i < elementLengths.length; i++) { if (i == stripStart) { elMode = Mode.TriangleStrip; } else if (i == fanStart) { elMode = Mode.TriangleStrip; } int elementLength = elementLengths[i]; indexData.position(curOffset); drawElements(elMode, elementLength, indexBuf.getFormat(), indexData); curOffset += elementLength; } } else { drawElements(mode, indexData.capacity(), indexBuf.getFormat(), indexData); } }
Example 6
Source File: TensorTest.java From java with Apache License 2.0 | 4 votes |
private static void clearBuffer(Buffer buf) { buf.clear(); }
Example 7
Source File: LodGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
private VertexBuffer makeLod(Mesh mesh) { VertexBuffer indexBuffer = mesh.getBuffer(VertexBuffer.Type.Index); boolean isShortBuffer = indexBuffer.getFormat() == VertexBuffer.Format.UnsignedShort; // Create buffers. VertexBuffer lodBuffer = new VertexBuffer(VertexBuffer.Type.Index); int bufsize = indexCount == 0 ? 3 : indexCount; if (isShortBuffer) { lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(bufsize)); } else { lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedInt, BufferUtils.createIntBuffer(bufsize)); } lodBuffer.getData().rewind(); //Check if we should fill it with a "dummy" triangle. if (indexCount == 0) { if (isShortBuffer) { for (int m = 0; m < 3; m++) { ((ShortBuffer) lodBuffer.getData()).put((short) 0); } } else { for (int m = 0; m < 3; m++) { ((IntBuffer) lodBuffer.getData()).put(0); } } } // Fill buffers. Buffer buf = lodBuffer.getData(); buf.rewind(); for (Triangle triangle : triangleList) { if (!triangle.isRemoved) { // assert (indexCount != 0); if (isShortBuffer) { for (int m = 0; m < 3; m++) { ((ShortBuffer) buf).put((short) triangle.vertexId[m]); } } else { for (int m = 0; m < 3; m++) { ((IntBuffer) buf).put(triangle.vertexId[m]); } } } } buf.clear(); lodBuffer.updateData(buf); return lodBuffer; }
Example 8
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 9
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) { int arrayType = convertArrayType(vb.getBufferType()); if (arrayType == -1) { return; // unsupported } gl.glEnableClientState(arrayType); context.boundAttribs[vb.getBufferType().ordinal()] = vb; if (vb.getBufferType() == Type.Normal) { // normalize if requested if (vb.isNormalized() && !context.normalizeEnabled) { gl.glEnable(gl.GL_NORMALIZE); context.normalizeEnabled = true; } else if (!vb.isNormalized() && context.normalizeEnabled) { gl.glDisable(gl.GL_NORMALIZE); context.normalizeEnabled = false; } } // NOTE: Use data from interleaved buffer if specified Buffer data = idb != null ? idb.getData() : vb.getData(); int comps = vb.getNumComponents(); int type = convertVertexFormat(vb.getFormat()); data.clear(); data.position(vb.getOffset()); switch (vb.getBufferType()) { case Position: gl.glVertexPointer(comps, type, vb.getStride(), data); break; case Normal: gl.glNormalPointer(type, vb.getStride(), data); break; case Color: gl.glColorPointer(comps, type, vb.getStride(), data); break; case TexCoord: gl.glTexCoordPointer(comps, type, vb.getStride(), data); break; } }