@ -1105,6 +1105,9 @@ public final class BufferUtils {
* the input buffer , not null
* the input buffer , not null
* /
* /
public static FloatBuffer ensureLargeEnough ( FloatBuffer buffer , int required ) {
public static FloatBuffer ensureLargeEnough ( FloatBuffer buffer , int required ) {
if ( buffer ! = null ) {
buffer . limit ( buffer . capacity ( ) ) ;
}
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
FloatBuffer newVerts = createFloatBuffer ( position + required ) ;
FloatBuffer newVerts = createFloatBuffer ( position + required ) ;
@ -1119,6 +1122,9 @@ public final class BufferUtils {
}
}
public static ShortBuffer ensureLargeEnough ( ShortBuffer buffer , int required ) {
public static ShortBuffer ensureLargeEnough ( ShortBuffer buffer , int required ) {
if ( buffer ! = null ) {
buffer . limit ( buffer . capacity ( ) ) ;
}
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
ShortBuffer newVerts = createShortBuffer ( position + required ) ;
ShortBuffer newVerts = createShortBuffer ( position + required ) ;
@ -1133,6 +1139,9 @@ public final class BufferUtils {
}
}
public static ByteBuffer ensureLargeEnough ( ByteBuffer buffer , int required ) {
public static ByteBuffer ensureLargeEnough ( ByteBuffer buffer , int required ) {
if ( buffer ! = null ) {
buffer . limit ( buffer . capacity ( ) ) ;
}
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
if ( buffer = = null | | ( buffer . remaining ( ) < required ) ) {
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
int position = ( buffer ! = null ? buffer . position ( ) : 0 ) ;
ByteBuffer newVerts = createByteBuffer ( position + required ) ;
ByteBuffer newVerts = createByteBuffer ( position + required ) ;
@ -1201,7 +1210,7 @@ public final class BufferUtils {
private static Method viewedBufferMethod = null ;
private static Method viewedBufferMethod = null ;
private static Method freeMethod = null ;
private static Method freeMethod = null ;
private static Method loadMethod ( String className , String methodName ) {
private static Method loadMethod ( String className , String methodName ) {
try {
try {
Method method = Class . forName ( className ) . getMethod ( methodName ) ;
Method method = Class . forName ( className ) . getMethod ( methodName ) ;
method . setAccessible ( true ) ;
method . setAccessible ( true ) ;
@ -1227,7 +1236,7 @@ public final class BufferUtils {
cleanerMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "cleaner" ) ;
cleanerMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "cleaner" ) ;
cleanMethod = loadMethod ( "sun.misc.Cleaner" , "clean" ) ;
cleanMethod = loadMethod ( "sun.misc.Cleaner" , "clean" ) ;
viewedBufferMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "viewedBuffer" ) ;
viewedBufferMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "viewedBuffer" ) ;
if ( viewedBufferMethod = = null ) {
if ( viewedBufferMethod = = null ) {
// They changed the name in Java 7 (???)
// They changed the name in Java 7 (???)
viewedBufferMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "attachment" ) ;
viewedBufferMethod = loadMethod ( "sun.nio.ch.DirectBuffer" , "attachment" ) ;
}
}