private static ByteBuffer extract(
            final String outerResourceName,
            final JarInputStream jarInputStream,
            final SelfContainedJarFile jar,
            final LinkedHashMap<String, Resource> innerResources)
            throws IOException {
        final byte[] buffer = new byte[4096];
        final ByteArrayOutputStream innerResourcesBinaryOutputStream = new ByteArrayOutputStream();

        int index = 0;
        while (true) {
            final JarEntry jarEntry = (JarEntry) jarInputStream.getNextEntry();
            if (jarEntry == null) {
                break;  // End of embedded JAR
            }

            if (jarEntry.isDirectory()) {
                continue;
            }
            final String entryName = jarEntry.getName();
            if (innerResources.containsKey(entryName)) {
                throw new IOException(String.format("Duplicated in embedded JAR: %s/%s", outerResourceName, entryName));
            }

            final int lengthRead = (int) transfer(jarInputStream, innerResourcesBinaryOutputStream, buffer);
            innerResources.put(entryName, new Resource(entryName, jar, index, index + lengthRead, jarEntry.getCodeSigners()));
            index += lengthRead;
        }

        // TODO: Use ByteBuffer.allocateDirect so that it does not affect GC.
        return ByteBuffer.wrap(innerResourcesBinaryOutputStream.toByteArray()).asReadOnlyBuffer();
    }
Returns the resource object.

@return resource if found, null otherwise
embulk-core/src/main/java/org/embulk/cli/SelfContainedJarFile.java