??? ?? ????? ??? ??

Zip ?????? ? ?? ?? zip ??????? ? ????. ?? Zip ????? ??? ?? ????? ???? ??? ??? ?? ? ????.

?? ???? ??
outer.zip
 +first.txt
 +inner.zip
 � +game.exe
 � +subitem.bin
 +picture.gif
??? ???? ??
flatten.zip
 +first.txt
 +picture.gif
 +game.exe
 +subitem.bin

aspose? ???? ?? ?? zip Zip Archive? ???? ??? ?? ?????.

?? ??

?? ????? ?? ??? ???????. ??? ? ??? ??? ???????, ??? ???? ????? ????. ???? ??? ??? ???? ???? ?? ?????? ???????. ??? ???? ?? ????? ????????.

???? ? ?? ??

???? ??? ?? ??? ???????. ?? ??? ???? ??? ??? ? ????. ??? ??? ?? ?????? ?? ??? ????? ??? ??? ??? ??????.

1if (Entry.getName (). TolowerCase (locale.root) .endswith ( ". Zip")) {
2    Entriestodelete.add (Entry);
3    ...
4}

??? ?? ?? ????

ASSPER.zip? ???? Zip Entry? ??? ???? ??? ?? ??? ????? ?? ? ? ????. ??? ?? ????? ??? ????? ?? ? ? ????.

?? : ?? ???? ?? ? ?? ???? ????? ??? ?????.

1??? [] B = ??? ??? [8192];
2int bytesread;
3inputStream entrystream = enlic.open ();
4BytearRayoutputStream InnerCompressed = New BytearRayoutputStream ();
5while (0 <(bytesRead = entrystream.read (b, 0, b.length))) {
6    innercompressed.write (b, 0, ??? ???);
7}

? ? ?? ?? ????? ?? ???? ??? ???? ????. ???? ???? ??? ???? ?? ?? ? ? ????. ??? ??? ??? ?? ? ? ????.

1Archive Inner = New Archive (New BytearrayInputStream (InnerCompressed.tobytearRay ()));

?? ??

?? ???? Zip Archive?? ??? ?? ? ? ????.

1for (Archiveentry e : Entriestodelete) {
2    ?? .DeleteEntry (e);
3}

?? ?? ?????

??? ?? ???????.

 1try (???? OUTER = New Archive ( "OUTER.ZIP")) {
 2    ArrayList <ArchiveEntry> EntriestOdelete = New ArrayList <CariveEntry> ();
 3    ArrayList <string> namestoInsert = new ArrayList <string> ();
 4    ArrayList <InputStream> ContentToInsert = New ArrayList <inputStream> ();
 5    for (ArchiveEntry ?? : OUTER.GETERTRIES ()) {
 6        // ???? ?? ? ??? ?????
 7        if (Entry.getName (). TolowerCase (locale.root) .endswith ( ". Zip")) {
 8            // ??? ?????? ????? ??? ??????.
 9            Entriestodelete.add (Entry);
10
11            //This extracts the entry to a memory stream
12            byte[] b = new byte[8192];
13            int bytesRead;
14            InputStream entryStream = entry.open();
15            ByteArrayOutputStream innerCompressed = new ByteArrayOutputStream();
16            while (0 < (bytesRead = entryStream.read(b, 0, b.length))) {
17                innerCompressed.write(b, 0, bytesRead);
18            }
19
20            // We know that content of the entry is a zip archive, so we may extract
21            try(Archive inner = new Archive(new ByteArrayInputStream(innerCompressed.toByteArray()))) {
22
23                // Loop over entries of inner archive
24                for(ArchiveEntry ie : inner.getEntries()) {
25
26                    // Keep the name of inner entry.
27                    namesToInsert.add(ie.getName());
28
29                    InputStream ieStream = ie.open();
30                    ByteArrayOutputStream content = new ByteArrayOutputStream();
31                    while (0 < (bytesRead = ieStream.read(b, 0, b.length))) {
32                        content.write(b, 0, bytesRead);
33                    }
34
35                    // Keep the content of inner entry.
36                    contentToInsert.add(new ByteArrayInputStream(content.toByteArray()));
37                }
38            }
39        }
40    }
41
42    for(ArchiveEntry e : entriesToDelete) {
43        // Delete all the entries which are archives itself
44        outer.deleteEntry(e);
45    }
46
47    for(int i = 0; i < namesToInsert.size(); i++) {
48        // Adds entries which were entries of inner archives
49        outer.createEntry(namesToInsert.get(i), contentToInsert.get(i));
50    }
51
52    outer.save("flatten.zip");
53} catch (??) {
54    System.out.println (?);
55}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.