private static long cloneZipEntry(final FeedKey defaultFeedKey,
                                      final FeedKeyInterner feedKeyInterner,
                                      final AttributeMap attributeMap,
                                      final ZipFile stagingZip,
                                      final ZipArchiveEntry entry,
                                      final ProxyZipValidator validator,
                                      final ZipWriter zipWriter,
                                      final Map<String, ZipEntryGroup> baseNameToGroupMap,
                                      final List<Entry> dataEntries) {
        try {
            final String entryName = entry.getName();
            // We will validate the data as we receive it to see if the format is exactly as expected.
            validator.addEntry(entryName);

            final long size;
            if (entry.isDirectory()) {
                zipWriter.writeDir(entryName);
                size = getSize(entry);
            } else {
                final FileName fileName = FileName.parse(entryName);
                final String baseName = fileName.getBaseName();
                final StroomZipFileType stroomZipFileType =
                        StroomZipFileType.fromExtension(fileName.getExtension());

                if (StroomZipFileType.META.equals(stroomZipFileType)) {
                    size = cloneAndUpdateMetaEntry(
                            attributeMap,
                            feedKeyInterner,
                            stagingZip,
                            entry,
                            zipWriter,
                            baseNameToGroupMap,
                            entryName,
                            baseName);
                } else if (StroomZipFileType.CONTEXT.equals(stroomZipFileType)) {
                    final ZipEntryGroup zipEntryGroup = baseNameToGroupMap.computeIfAbsent(baseName, k ->
                            new ZipEntryGroup(defaultFeedKey));
                    if (zipEntryGroup.getContextEntry() != null) {
                        throw new RuntimeException("Duplicate context found: " + entryName);
                    }

                    size = writeUnchangedEntry(zipWriter, stagingZip, entry);
                    zipEntryGroup.setContextEntry(new Entry(entryName, size));
                } else if (StroomZipFileType.MANIFEST.equals(stroomZipFileType)) {
                    final ZipEntryGroup zipEntryGroup = baseNameToGroupMap.computeIfAbsent(baseName, k ->
                            new ZipEntryGroup(defaultFeedKey));
                    if (zipEntryGroup.getManifestEntry() != null) {
                        throw new RuntimeException("Duplicate manifest found: " + entryName);
                    }

                    size = writeUnchangedEntry(zipWriter, stagingZip, entry);
                    zipEntryGroup.setManifestEntry(new Entry(entryName, size));
                } else {
                    size = writeUnchangedEntry(zipWriter, stagingZip, entry);
                    dataEntries.add(new Entry(entryName, size));
                }
            }
            return size;
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
Static and pkg private to aid testing
stroom-proxy/stroom-proxy-app/src/main/java/stroom/proxy/app/handler/ZipReceiver.java