Commits
md_5 authored ab525c0a154
661 661 | public static void unzip(File zipFile, File targetFolder) throws IOException |
662 662 | { |
663 663 | unzip( zipFile, targetFolder, null ); |
664 664 | } |
665 665 | |
666 666 | public static void unzip(File zipFile, File targetFolder, Predicate<String> filter) throws IOException |
667 667 | { |
668 668 | targetFolder.mkdir(); |
669 669 | ZipFile zip = new ZipFile( zipFile ); |
670 670 | |
671 - | for ( Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements(); ) |
671 + | try |
672 672 | { |
673 - | ZipEntry entry = entries.nextElement(); |
674 - | |
675 - | if ( filter != null ) |
673 + | for ( Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements(); ) |
676 674 | { |
677 - | if ( !filter.apply( entry.getName() ) ) |
675 + | ZipEntry entry = entries.nextElement(); |
676 + | |
677 + | if ( filter != null ) |
678 678 | { |
679 - | continue; |
679 + | if ( !filter.apply( entry.getName() ) ) |
680 + | { |
681 + | continue; |
682 + | } |
680 683 | } |
681 - | } |
682 684 | |
683 - | File outFile = new File( targetFolder, entry.getName() ); |
685 + | File outFile = new File( targetFolder, entry.getName() ); |
684 686 | |
685 - | if ( entry.isDirectory() ) |
686 - | { |
687 - | outFile.mkdirs(); |
688 - | continue; |
689 - | } |
690 - | if ( outFile.getParentFile() != null ) |
691 - | { |
692 - | outFile.getParentFile().mkdirs(); |
693 - | } |
687 + | if ( entry.isDirectory() ) |
688 + | { |
689 + | outFile.mkdirs(); |
690 + | continue; |
691 + | } |
692 + | if ( outFile.getParentFile() != null ) |
693 + | { |
694 + | outFile.getParentFile().mkdirs(); |
695 + | } |
694 696 | |
695 - | InputStream is = zip.getInputStream( entry ); |
696 - | OutputStream os = new FileOutputStream( outFile ); |
697 - | try |
698 - | { |
699 - | ByteStreams.copy( is, os ); |
700 - | } finally |
701 - | { |
702 - | is.close(); |
703 - | os.close(); |
704 - | } |
697 + | InputStream is = zip.getInputStream( entry ); |
698 + | OutputStream os = new FileOutputStream( outFile ); |
699 + | try |
700 + | { |
701 + | ByteStreams.copy( is, os ); |
702 + | } finally |
703 + | { |
704 + | is.close(); |
705 + | os.close(); |
706 + | } |
705 707 | |
706 - | System.out.println( "Extracted: " + outFile ); |
708 + | System.out.println( "Extracted: " + outFile ); |
709 + | } |
710 + | } finally |
711 + | { |
712 + | zip.close(); |
707 713 | } |
708 714 | } |
709 715 | |
710 716 | public static void clone(String url, File target) throws GitAPIException, IOException |
711 717 | { |
712 718 | System.out.println( "Starting clone of " + url + " to " + target ); |
713 719 | |
714 720 | Git result = Git.cloneRepository().setURI( url ).setDirectory( target ).call(); |
715 721 | |
716 722 | try |