????????????
Contents
[
Hide
Show
]Aspose.Zip API????????????????????????????Java???????????????????????????????????????????????????????
????????
???????????????????
1try(fileoutputStream zipfile = new fileoutputStream(datadir + "compresswithtraditionalencryption_out.zip"){
2 try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
3 Archive Archive = new Archive(???ArchiveEntrySettings(null?new TraditionalEncryptionsettings( "p@s $")));
4 archive.createentry( "alice29.txt"?source1);
5 archive.save(zipfile);
6 }
7} catch(ioException ex){
8 System.out.println(ex);
9}AES???????????????
AES128?????????????
1try(fileoutputStream zipfile = new fileoutputStream(datadir + "passwordprotectwithaes128_out.zip"){
2 try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
3 Archive Archive = new Archive(???ArchiveEntrySettings(null?new aesencryptionsettings( "p@s $"?encryptionmethod.aes128)));
4 archive.createentry( "alice29.txt"?source1);
5 archive.save(zipfile);
6 }
7} catch(ioException ex){
8 System.out.println(ex);
9}AES192?????????????
1try(fileoutputStream zipfile = new fileoutputStream(datadir + "passwordProtectWithAes192_out.zip"){
2 try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
3 Archive Archive = new Archive(???ArchiveEntrySettings(null?new aesencryptionsettings( "p@s $"?encryptionmethod.aes192)));
4 archive.createentry( "alice29.txt"?source1);
5 archive.save(zipfile);
6 }
7} catch(ioException ex){
8 System.out.println(ex);
9}AES256?????????????
1try(fileoutputStream zipfile = new fileoutputStream(datadir + "passwordprotectwithaes256_out.zip"){
2 try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
3 Archive Archive = new Archive(???ArchiveEntrySettings(null?new aesencryptionsettings( "p@s $"?encryptionmethod.aes256)));
4 archive.createentry( "alice29.txt"?source1);
5 archive.save(zipfile);
6 }
7} catch(ioException ex){
8 System.out.println(ex);
9}?????????????
1try(fileoutputStream zipfile = new fileoutputStream( "?\\ all_corpus_encrypted_out.zip"){
2 file corpus = new file( "?\\ canterburycorpus");
3 try(Archive Archive = new Archive(???ArchiveEntrySettings(null?new TraditionalEncryptionsettings( "p@s $"))){
4 archive.createentries(corpus);
5 archive.save(zipfile);
6 }
7} catch(ioException ex){
8 System.out.println(ex);
9}????????????????????????
1try(fileoutputStream zipfile = new fileoutputStream( "archive.zip")){
2 ????fi1 = new file( "data1.bin");
3 ????fi2 = new file( "data2.bin");
4 ????fi3 = new file( "data3.bin");
5 try(archive archive = new archive()){
6 archive.createentry( "entry1.bin"???fi1?false?new archiveentrysettings(new deflateCompressionsettings()????TraditionalEncryptionsettings( "pass1")));
7 archive.createentry( "entry2.bin"???fi2?false?new archiveEntrysettings(new deflateCompressionsettings()?new aesencryptionsettings( "pass2"?encryptionmethod.aes128)));
8 archive.createentry( "entry3.bin"???fi3?false?new archiveentrysettings(new deflateCompressionsettings()?new aesencryptionsettings( "pass3"?encryptionmethod.aes256)));
9 archive.save(zipfile);
10 }
11} catch(IOException??????){
12}????????
??????????????????????
1try(fileinputStream fs = new fileinputStream(datadir + "compresswithtraditionalencryption_in.zip")){
2 try(fileoutputStream??= new fileoutputStream(datadir + "alice_extracted_out.txt")){
3 archiveloadoptions options = new archiveloadoptions();
4 options.setDecryptionPassWord( "p@s $");
5 try(Archive Archive = new Archive(fs?options)){
6 try(inputstream decompressed = archive.getentries()?get(0).open()){
7 byte [] b = new byte [8192];
8 int bytesRead;
9 while(0 <(bytesread = decompressed.read(b?0?b.length))){
10 ?????.write(b?0?bytesread);
11 }
12 }
13 }
14 }
15} catch(ioException ex){
16 System.out.println(ex);
17}AES?????????????????
1try(fileInputStream fs = new fileInputStream(datadir + "passwordprotectwithaes256_in.zip")){
2 try(fileoutputStream??= new fileoutputStream(datadir + "alice_aesextracted_out.txt")){
3 try(Archive Archive = new Archive(fs)){
4 try(inputstream decompressed = archive.getentries()?get(0).open( "p@s $")){
5 byte [] b = new byte [8192];
6 int bytesRead;
7 while(0 <(bytesread = decompressed.read(b?0?b.length))){
8 ?????.write(b?0?bytesread);
9 }
10 }
11 }
12 }
13} catch(ioException ex){
14 System.out.println(ex);
15}AES??????????????????????
1try(fileInputStream fs = new fileInputStream(datadir + "storemutliplefileswithcompressionwithpassword_in.zip"){
2 try(fileoutputStream??= new fileoutputStream(datadir + "alice_aesextracted_out.txt")){
3 archiveloadoptions options = new archiveloadoptions();
4 options.setDecryptionPassWord( "p@s $");
5 try(Archive Archive = new Archive(fs?options)){
6 try(inputstream decompressed = archive.getentries()?get(0).open()){
7 byte [] b = new byte [8192];
8 int bytesRead;
9 while(0 <(bytesread = decompressed.read(b?0?b.length))){
10 ?????.write(b?0?bytesread);
11 }
12 }
13 }
14 }
15} catch(ioException ex){
16 System.out.println(ex);
17}????????????????????????
1try(fileinputStream zipfile = new fileinputStream( "?\\ all_corpus_encrypted.zip")){
2 archiveloadoptions options = new archiveloadoptions();
3 options.setDecryptionPassWord( "p@s $");
4 ????????(zipfile?options).extracttodirectory( "?\\ all_corpus_decrypted");
5} catch(ioException ex){
6 System.out.println(ex);
7}??????????????????
1try(fileInputStream fs = new fileInputStream(datadir + "compressedsinglefile.zip")){
2 try(Archive Archive = new Archive(fs)){
3 int []?????ready = new int [] {0};
4 archive.getEntries()?get(0).setExtractionProgressed(new event <prowresventargs>(){
5 @???????
6 public void invoke(Object sender?progresseventargs progresseventargs){
7 int?????=(int)((100 * progresseventargs.getProceedBytes()) /((archiveentry)sender).getuncompressedsize());
8 if(?????>?????Ready [0]){
9 System.out.println(????? + "%??");
10 PercentReady [0] =?????;
11 }
12 }
13 });
14 archive.getentries()?get(0).extrage(datadir + "alice_extracted_out.txt");
15 }
16} catch(ioException ex){
17 System.out.println(ex);
18}??????????????????
1try(fileInputStream fs = new fileinputStream(datadir + "compressedmultiplefiles.zip")){
2 stringbuilder sb = new StringBuilder( "?????:");
3 int []?????ready = new int [] {0};
4 archiveloadoptions options = new archiveloadoptions();
5 options.setEntryListed(new event <Entereventargs>(){
6 @???????
7 public void invoke(Object sender?entereventargs entereventargs){
8 sb.append(entereventargs.getentry()?getname())?append( "?");
9 }
10 });
11 options.setEntryExtractionProgressed(???????<ProgressEventargs>(){
12 @???????
13 public void invoke(Object sender?progresseventargs progresseventargs){
14 int?????=(int)((100 * progresseventargs.getProceedBytes()) /((archiveentry)sender).getuncompressedsize());
15 if(?????>?????Ready [0]){
16 System.out.println(????? + "%??");
17 PercentReady [0] =?????;
18 }
19 }
20 });
21 try(Archive Archive = new Archive(fs?options)){
22 System.out.println(sb.substring(0?sb.length()-2));
23 try(fileoutputStream??= new fileoutputStream(datadir + "alice_extracted_out.txt")){
24 try(inputstream decompressed = archive.getentries()?get(0).open()){
25 byte [] buffer = new byte [8192];
26 int bytesRead;
27 while(0 <(bytesread = decompressed.read(buffer?0?buffer.length))){
28 ?????.write(buffer?0?bytesread);
29 }
30 //???????????????????????????
31 }
32 }
33 ?????Ready [0] = 0;
34 archive.getEntries()?get(1).extract(datadir + "asyoulik_extracted_out.txt");
35 }
36} catch(ioException ex){
37 System.out.println(ex);
38}?????????????????????
1try(fileInputStream zipfile = new fileinputStream(datadir + "storemultiplefileswithoutcompression.zip"){
2 try(Archive archive = new Archive(zipfile))){
3 try(fileoutputStream??= new fileoutputStream(datadir + "alice_extracted_store_out.txt")){
4 try(inputstream decompressed = archive.getentries()?get(0).open()){
5 byte [] buffer = new byte [8192];
6 int bytesRead;
7 while(0 <(bytesread = decompressed.read(buffer?0?buffer.length))){
8 ?????.write(buffer?0?bytesread);
9 }
10 //???????????????????????????
11 }
12 }
13 try(fileoutputStream??= new fileoutputStream(datadir + "asyoulik_extracted_store_out.txt")){
14 try(inputstream decompressed = archive.getentries()?get(1).open()){
15 byte [] buffer = new byte [8192];
16 int bytesRead;
17 while(0 <(bytesread = decompressed.read(buffer?0?buffer.length))){
18 ?????.write(buffer?0?bytesread);
19 }
20 //???????????????????????????
21 }
22 }
23 }
24} catch(ioException ex){
25 System.out.println(ex);
26}