Changeset 9166 for trunk/gli/src/org/greenstone/gatherer/util
- Timestamp:
- 2005-02-24T13:57:06+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r9095 r9166 602 602 } 603 603 604 static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source) 605 { 604 /* 605 Method to handle zipping up of a file. Called by zipup and dirFunc. 606 607 @param zos the zip output stream, as a <strong>ZipOutputStream</strong> 608 @param file_path the <strong>String</strong> containing the path to the file/directory tozip up 609 @param prefix_strip the <strong>int</strong> used to substring the file_path 610 @param source the <strong>GShell</strong> that is calling this method, so that we can check to see if the process has been cancelled. null if GShell is not the calling object. 611 @param accept_expr a <strong>String</strong> containing a regular expression of files to include in the archive. All other files will be excluded. 612 @param reject_expr a <strong>String</strong> containing a regular expression of files not to include in the archive. 613 614 @return boolean 615 616 @see dirFunc 617 @see zipup 618 */ 619 static protected boolean zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source, boolean encountered_file, String accept_expr, String reject_expr) 620 { 621 622 if((reject_expr != "") && (file_path.matches(reject_expr))) { 623 // matches reject expression 624 DebugStream.println("File \'" + file_path + "\' matches the reject expression \'" + reject_expr + "\'"); 625 return encountered_file; 626 } 627 628 if ((accept_expr != "") && (!file_path.matches(accept_expr))) { 629 // does not match accept expression 630 DebugStream.println("File \'" + file_path + "\' doesn't match accept expression \'" + accept_expr + "\'"); 631 return encountered_file; 632 } 633 606 634 // Using try is required because of file io. 607 635 try { 608 636 // Exit if pressed cancel. 609 637 if (source != null && source.hasSignalledStop()) { 610 return; 611 } 638 return false; 639 } 640 612 641 // Create a Zip Entry and put it into the archive (no data yet). 613 642 … … 616 645 // Zip files use '/' for directory separator 617 646 String unix_style_path = unixStylePath(zip_path); 647 618 648 ZipEntry fileEntry = new ZipEntry(unix_style_path); 619 649 zos.putNextEntry(fileEntry); … … 637 667 zos.write(data, 0, byteCount); 638 668 } 669 encountered_file = true; 639 670 } 640 671 catch (IOException e) { … … 642 673 } 643 674 644 DebugStream.println(" Zipping up: " + file_path); 645 } 646 647 static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source) 648 { 675 DebugStream.println("Zipping up: " + file_path); 676 return encountered_file; 677 } 678 679 /* 680 Method to handle ziping up of a directory. 681 682 @param zos 683 @param dir_name 684 @param prefix_strip 685 @param source 686 @param encountered_file ??What's this?? 687 @param accept_expr 688 @param reject_expr 689 690 @see zipup 691 @see zipFunc 692 */ 693 static protected boolean dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source, boolean encountered_file, String accept_expr, String reject_expr) 694 { 695 /* 696 if (reject_expr != "" && (dir_name.matches(reject_expr))) { 697 // matches reject expression 698 System.err.println("matches reject expression"); 699 return encountered_file; 700 } 701 702 if ((accept_expr != "") && (!dir_name.matches(accept_expr))) { 703 // does not match accept expression 704 System.err.println("doesn't match accept expression"); 705 return encountered_file; 706 } 707 */ 708 649 709 File dirObj = new File(dir_name); 650 710 … … 656 716 // Loop through File array and display. 657 717 for (int i = 0; i < fileList.length; i++) { 658 if(source != null) { 659 if(source.hasSignalledStop()) { 660 break; 661 } 662 } 718 if(source != null && source.hasSignalledStop()) { break; } 663 719 File file = fileList[i]; 664 720 if (file.isDirectory()) { … … 677 733 } 678 734 679 dirFunc(zos,dir_path,prefix_strip, source);735 encountered_file = dirFunc(zos, dir_path, prefix_strip, source, encountered_file, accept_expr, reject_expr); 680 736 } else if (file.isFile()) { 681 737 // Call the zipFunc function 682 738 String file_path = fileList[i].getPath(); 683 zipFunc(zos,file_path,prefix_strip, source);739 encountered_file = zipFunc(zos,file_path,prefix_strip, source, encountered_file, accept_expr, reject_expr); 684 740 } 685 } 741 } 686 742 } 687 743 else { … … 692 748 System.err.println ("Directory "+dir_name+" does not exist."); 693 749 } 750 return encountered_file; 694 751 } 695 752 696 697 698 static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source) 753 /** 754 Method to zip up a given file or directory 755 756 @param col_dir 757 @param col_name 758 @param dir_or_file 759 @param source 760 @param filter 761 762 @see zipFunc 763 @see dirFunc 764 */ 765 static public boolean zipup(String col_dir, String col_name, String dir_or_file, GShell source, String accept_expr, String reject_expr) 699 766 { 700 767 int prefix_strip = col_dir.length(); 768 boolean encountered_file = false; 701 769 702 770 String zip_fname = col_dir + col_name + ".zip"; … … 711 779 if (zip_dof.isDirectory()) { 712 780 String zip_dir = zip_dir_or_file; 713 dirFunc(zos,zip_dir,prefix_strip, source);781 encountered_file = dirFunc(zos, zip_dir, prefix_strip, source, encountered_file, accept_expr, reject_expr); 714 782 } 715 783 else { … … 730 798 } 731 799 } 732 zipFunc(zos,zip_full_file,prefix_strip, source);800 encountered_file = zipFunc(zos, zip_full_file, prefix_strip, source, encountered_file, accept_expr, reject_expr); 733 801 } 734 802 } … … 744 812 catch (IOException exception) { 745 813 DebugStream.printStackTrace(exception); 746 } 814 return false; 815 } 816 return encountered_file; 747 817 } 748 818 … … 760 830 ZipEntry zipentry = (ZipEntry) e.nextElement(); 761 831 String zentryname = col_dir + zipentry.getName(); 832 File file = new File(zentryname); 762 833 DebugStream.println(" Unzipping: " + zentryname); 763 834 … … 771 842 else { 772 843 // Write out file to disk 844 845 //Make sure it's parent directory exists. 846 File dir = new File(file.getParent()); 847 dir.mkdirs(); 773 848 774 849 // set up input stream
Note:
See TracChangeset
for help on using the changeset viewer.