src/org/lwjgl/demo/opengl/util/DemoUtils.java
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
        ByteBuffer buffer;
        URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
        File file = new File(url.getFile());
        if (file.isFile()) {
            FileInputStream fis = new FileInputStream(file);
            FileChannel fc = fis.getChannel();
            buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
            fc.close();
            fis.close();
        } else {
            buffer = BufferUtils.createByteBuffer(bufferSize);
            InputStream source = url.openStream();
            if (source == null)
                throw new FileNotFoundException(resource);
            try {
                ReadableByteChannel rbc = Channels.newChannel(source);
                try {
                    while (true) {
                        int bytes = rbc.read(buffer);
                        if (bytes == -1)
                            break;
                        if (buffer.remaining() == 0)
                            buffer = resizeBuffer(buffer, buffer.capacity() * 2);
                    }
                    buffer.flip();
                } finally {
                    rbc.close();
                }
            } finally {
                source.close();
            }
        }
        return buffer;
    }
/**
	 * Reads the specified resource and returns the raw data as a ByteBuffer.
	 *
	 * @param resource   the resource to read
	 * @param bufferSize the initial buffer size
	 *
	 * @return the resource data
	 *
	 * @throws IOException if an IO error occurs
	 */
Reads the specified resource and returns the raw data as a ByteBuffer.
@param resource   the resource to read
@param bufferSize the initial buffer size

@return the resource data

@throws IOException if an IO error occurs
Reads the specified resource and returns the raw data as a ByteBuffer . @param resource the resource to read @param bufferSize the initial buffer size @return the resource data @throws IOException if an IO error occurs
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
        ByteBuffer buffer;
        URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
        File file = new File(url.getFile());
        if (file.isFile()) {
            FileInputStream fis = new FileInputStream(file);
            FileChannel fc = fis.getChannel();
            buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
            fc.close();
            fis.close();
        } else {
            buffer = BufferUtils.createByteBuffer(bufferSize);
            InputStream source = url.openStream();
            if (source == null)
                throw new FileNotFoundException(resource);
            try {
                ReadableByteChannel rbc = Channels.newChannel(source);
                try {
                    while (true) {
                        int bytes = rbc.read(buffer);
                        if (bytes == -1)
                            break;
                        if (buffer.remaining() == 0)
                            buffer = resizeBuffer(buffer, buffer.capacity() * 2);
                    }
                    buffer.flip();
                } finally {
                    rbc.close();
                }
            } finally {
                source.close();
            }
        }
        return buffer;
    }
public static ByteBuffer ioResourceToByteBuffer ( String resource , int bufferSize ) throws IOException { ByteBuffer buffer ; URL url = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( resource ) ; File file = new File ( url . getFile ( ) ) ; if ( file . isFile ( ) ) { FileInputStream fis = new FileInputStream ( file ) ; FileChannel fc = fis . getChannel ( ) ; buffer = fc . map ( FileChannel . MapMode . READ_ONLY , 0 , fc . size ( ) ) ; fc . close ( ) ; fis . close ( ) ; } else { buffer = BufferUtils . createByteBuffer ( bufferSize ) ; InputStream source = url . openStream ( ) ; if ( source == null ) throw new FileNotFoundException ( resource ) ; try { ReadableByteChannel rbc = Channels . newChannel ( source ) ; try { while ( true ) { int bytes = rbc . read ( buffer ) ; if ( bytes == - 1 ) break ; if ( buffer . remaining ( ) == 0 ) buffer = resizeBuffer ( buffer , buffer . capacity ( ) * 2 ) ; } buffer . flip ( ) ; } finally { rbc . close ( ) ; } } finally { source . close ( ) ; } } return buffer ; }
Reads the specified resource and returns the raw data as a ByteBuffer.
Reads the specified resource and returns the raw data as a ByteBuffer .