private void writeData(DataWriter out, Progress progress) throws IOException {
        // write entry list
        List<BundleEntry> entries = bundle.entries();
        long baseOffset = out.position();
        out.writeInt(entries.size());

        List<BundleEntryInfo> entryInfos = new ArrayList<>(entries.size());
        for (BundleEntry entry : entries) {
            BundleEntryInfo entryInfo = new BundleEntryInfo();
            entryInfo.name(entry.name());
            entryInfo.size(entry.size());
            out.writeStruct(entryInfo);
            entryInfos.add(entryInfo);
        }

        // write entry data
        for (int i = 0; i < entries.size(); i++) {
            out.align(4);

            BundleEntry entry = entries.get(i);
            BundleEntryInfo entryInfo = entryInfos.get(i);

            progress.update(Optional.of(entry.name()), i / (double) entries.size());

            entryInfo.offset(out.position() - baseOffset);

            if (i == 0) {
                bundle.header().dataHeaderSize(entryInfo.offset());
            }

            try (
                InputStream is = entry.inputStream();
                OutputStream os = out.stream();
            ) {
                IOUtils.copy(is, os);
            }

            MutablePair<Long, Long> levelOffset = levelOffsetMap.get(entry);
            if (levelOffset != null) {
                long offset = out.position() - baseOffset;
                levelOffset.setLeft(offset);
                levelOffset.setRight(offset);
            }
        }

        // update offsets
        out.position(baseOffset + 4);
        for (BundleEntryInfo entryInfo : entryInfos) {
            out.writeStruct(entryInfo);
        }
    }
@author Nico Bergemann <barracuda415 at yahoo.de>
disunity-core/src/main/java/info/ata4/junity/bundle/BundleWriter.java