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

??? zip Archive ????? ????? ? ??? ?????? ?????? 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}

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

Aspose.zip ????????? ????????? ?????????? ????? ZIP ? ????? riseable -????? ?? ?????? ? ????. ????, ?? ????? ??????? ????????? ????? ? ????? ??????.

???????? ????????: ??????????? ?????? ?????? ???? ?????????? ???????, ????? ????????? ???? ??????????? ???????.

1???? [] b = ????? ???? [8192];
2int bytesread;
3InputStream intryStream = intrint.open ();
4BytearRayOutputStream InnerCompressed = New BytearRayOutputStream ();
5while (0 <(bytesread = intrintstream.read (b, 0, b.length))) {
6    InnerCompressed.Write (B, 0, BytesRead);
7}

????? ????? ?????????? ????? ???????? ??? ?????????? ?????. ????? -??????????? ????????? ????????????????? ??????????????? ?????. ????, ?? ????? ????? ??????? ???:

1Archive Inner = ????? ????? (????? BytearrayinputStream (InnerCompressed.TobyTearray ()));

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

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

1??? (ArchiveEntry E: EntriestoDelete) {
2    ???????.deleteEntry (e);
3}

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

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

 1?????????? (Archive Outter = New Archive ("over.zip")) {
 2    ArrayList <ArchiveEntry> intriestoDelete = new ArrayList <ArchiveEntry> ();
 3    Arraylist <string> namestoinsert = new ArrayList <string> ();
 4    ArrayList <InputStream> contentToinSert = new ArrayList <InputStream> ();
 5    ??? (ArchiveEntry ??????: over.getEntries ()) {
 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 (Exception ex) {
54    System.out.println (Ex);
55}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.