src/main/java/com/spinyowl/legui/util/IOUtil.java
public static ByteBuffer resourceToByteBuffer(String path) throws IOException {
    byte[] bytes;
    path = path.trim();
    if (path.startsWith("http")) {
      bytes = IOUtils.toByteArray(new URL(path));
    } else {
      InputStream stream;
      File file = new File(path);
      if (file.exists() && file.isFile()) {
        stream = new FileInputStream(file);
      } else {
        stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
      }
      if (stream == null) {
        throw new FileNotFoundException(path);
      }
      bytes = IOUtils.toByteArray(stream);
    }
    ByteBuffer data = ByteBuffer.allocateDirect(bytes.length).order(ByteOrder.nativeOrder())
        .put(bytes);
    data.flip();
    return data;
  }
/**
   * Creates {@link ByteBuffer} from:
   * <ul>
   *     <li>file</li>
   *     <li>resource</li>
   *     <li>url (http/https) protocol</li>
   * </ul>
   *
   * @param path path to file or resource.
   * @return file or resource data or null.
   * @throws IOException in case if any IO exception occurs.
   */
Creates  ByteBuffer from:

file
resource
url  protocol


@param path path to file or resource.
@return file or resource data or null.
@throws IOException in case if any IO exception occurs.
Creates ByteBuffer from : file resource url protocol @param path path to file or resource . @return file or resource data or null . @throws IOException in case if any IO exception occurs .
public static ByteBuffer resourceToByteBuffer(String path) throws IOException {
    byte[] bytes;
    path = path.trim();
    if (path.startsWith("http")) {
      bytes = IOUtils.toByteArray(new URL(path));
    } else {
      InputStream stream;
      File file = new File(path);
      if (file.exists() && file.isFile()) {
        stream = new FileInputStream(file);
      } else {
        stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
      }
      if (stream == null) {
        throw new FileNotFoundException(path);
      }
      bytes = IOUtils.toByteArray(stream);
    }
    ByteBuffer data = ByteBuffer.allocateDirect(bytes.length).order(ByteOrder.nativeOrder())
        .put(bytes);
    data.flip();
    return data;
  }
public static ByteBuffer resourceToByteBuffer ( String path ) throws IOException { byte [ ] bytes ; path = path . trim ( ) ; if ( path . startsWith ( "http" ) ) { bytes = IOUtils . toByteArray ( new URL ( path ) ) ; } else { InputStream stream ; File file = new File ( path ) ; if ( file . exists ( ) && file . isFile ( ) ) { stream = new FileInputStream ( file ) ; } else { stream = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( path ) ; } if ( stream == null ) { throw new FileNotFoundException ( path ) ; } bytes = IOUtils . toByteArray ( stream ) ; } ByteBuffer data = ByteBuffer . allocateDirect ( bytes . length ) . order ( ByteOrder . nativeOrder ( ) ) . put ( bytes ) ; data . flip ( ) ; return data ; }
Creates {@link ByteBuffer} from:
 <ul>
     <li>file</li>
     <li>resource</li>
     <li>url (http/https) protocol</li>
 </ul>
Creates { @link ByteBuffer } from : <ul > <li > file< / li > <li > resource< / li > <li > url ( http / https ) protocol< / li > < / ul >