?? ???????? ??????? Zip Archive

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

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

???? ?? ?? ??????? ? Aspopy.zip, ??????????, ?? ????????? Zip Archive ????????.

?????????

?? -?????, ??? ???????? ???????????? ??? ?????? ??????. ????????? ?????? ??????? ??????????? ??????, ????? ???? ?, ?? ?????? ?? ??????? ?? ??????????????. ??????, ??? ???? ? ????????, ??????? ???? ????????? ?? ???’??? ?? ???????? ?? ??????????? ??????. ?? ????? ??????? ???? ????????? ?? ????????? ??????.

????????? ???????, ??? ? ????????

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

1if (entry.getName (). TOLOWERCASE (locale.root) .endswith (". Zip")) {
2    prestistodelete.add (?????);
3    ...
4}

????????? ?????? ?????? ? ???’???

Aspose.zip ???????? ?????????? ????? ?????? zip ? ???? -???? ?????, ?? ???????????, ?? ???? ?? ?????. ????, ?? ?????? ????????? ????????? ????? ?? ?????? ???’???.

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

1???? [] b = ????? ???? [8192];
2int bytesread;
3InputStream entnerstream = entry.open ();
4Bytearrayoutputstream innercompressed = ????? bytearrayoutputstream ();
5while (0 <(bytesread = entnerstream.read (b, 0, b.length))) {
6    InnerCompressed.write (B, 0, BytesRead);
7}

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

1????? ???????????? = ????? ????? (????? bytearrayinputstream (Innercompressed.tobytearray ()));

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

?? ?????? ???????? ????? ?? zip Archive ?? ????????? ??????????? ??????.

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

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

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

 1????????? (????? ????????? = ????? ????? ("????????.zip")) {
 2    ArrayList <ChiveEntry> prestistodelete = ????? ArrayList <ChiveEntry> ();
 3    ArrayList <string> namestoinsert = ????? ArrayList <string> ();
 4    ArrayList <Putinstream> contentToinsert = ????? ArrayList <Putinstream> ();
 5    ??? (archiveentry ?????: ????????.getentries ()) {
 6        // ?????? ?????, ???? ? ????? ???????
 7        if (entry.getName (). TOLOWERCASE (locale.root) .endswith (". Zip")) {
 8            // ??????????? ????????? ?? ?????, ??? ??????? ???? ????? ? ??????
 9            prestistodelete.add (?????);
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} ??? (??????? ex) {
54    System.out.println (ex);
55}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.