Skip to content

Instantly share code, notes, and snippets.

@xranby
Created January 18, 2013 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xranby/7e326db34a4ed6aa7a72 to your computer and use it in GitHub Desktop.
Save xranby/7e326db34a4ed6aa7a72 to your computer and use it in GitHub Desktop.
/* Modified version of http://www.roseindia.net/tutorial/java/corejava/nio/IntBufferIsDirect.html * Testcase below throws exception using gij and gnu classpath javac IntIsDirect.java # gcj gij + classpath Output: gij IntIsDirect Exception in thread "main" java.lang.NoSuchMethodError: method java.nio.Buffer.isDirect with signature ()Z was not fou…
/* Modified version of http://www.roseindia.net/tutorial/java/corejava/nio/IntBufferIsDirect.html
* Testcase below throws exception using gij and gnu classpath
gcj gij + classpath Output:
gij IntIsDirect
Exception in thread "main" java.lang.NoSuchMethodError: method java.nio.Buffer.isDirect with signature ()Z was not found.
at IntIsDirect.main(IntIsDirect.java:12)
OpenJDK output:
java IntIsDirect
((Buffer)int buffer) is direct.
int buffer is direct.
((Buffer)int buffer) is not direct.
int buffer is not direct.
*/
import java.nio.*;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class IntIsDirect {
public static void main(String[] argv){
ByteBuffer b = ByteBuffer.allocateDirect(512);
IntBuffer i = b.asIntBuffer();
// Type cast of IntBuffer to Buffer throws exception using gij + classpath
// when calling .isDirect
if (((Buffer)i).isDirect()) {
System.out.println("((Buffer)int buffer) is direct.");
} else {
System.out.println("((Buffer)int buffer) is not direct.");
}
if (i.isDirect()) {
System.out.println("int buffer is direct.");
} else {
System.out.println("int buffer is not direct.");
}
int[] array = new int[] {1,2,3,4,5};
IntBuffer intBuf = IntBuffer.wrap(array);
// Type cast of IntBuffer to Buffer throws exception using gij + classpath
// when calling .isDirect
if (((Buffer)intBuf).isDirect()) {
System.out.println("((Buffer)int buffer) is direct.");
} else {
System.out.println("((Buffer)int buffer) is not direct.");
}
if (intBuf.isDirect()) {
System.out.println("int buffer is direct.");
} else {
System.out.println("int buffer is not direct.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment