File: cg-common-CustomJavaCode.java

package info (click to toggle)
libjogl-java 1.1.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: lenny
  • size: 9,916 kB
  • ctags: 24,946
  • sloc: java: 87,017; ansic: 12,156; xml: 1,625; cpp: 302; objc: 91; sh: 35; makefile: 21
file content (29 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
static {
  com.sun.opengl.impl.NativeLibLoader.loadCgImpl();
}

/** A convenience method which reads all available data from the InputStream and then calls cgCreateProgram. */
public static CGprogram cgCreateProgramFromStream(CGcontext ctx, int program_type, java.io.InputStream stream, int profile, java.lang.String entry, java.lang.String[] args) throws java.io.IOException {
  if (stream == null) {
    throw new java.io.IOException("null stream");
  }
  stream = new java.io.BufferedInputStream(stream);
  int avail = stream.available();
  byte[] data = new byte[avail];
  int numRead = 0;
  int pos = 0;
  do {
    if (pos + avail > data.length) {
      byte[] newData = new byte[pos + avail];
      System.arraycopy(data, 0, newData, 0, pos);
      data = newData;
    }
    numRead = stream.read(data, pos, avail);
    if (numRead >= 0) {
      pos += numRead;
    }
    avail = stream.available();
  } while (avail > 0 && numRead >= 0);
  String program = new String(data, 0, pos, "US-ASCII");
  return cgCreateProgram(ctx, program_type, program, profile, entry, args);
}