java/automation/src/main/java/be/bosa/dt/best/automation/services/ZipService.java
/**
	 * Move files to a zip file
	 * 
	 * @param indir input directory containing files to be zipped
	 * @param outfile output zip file
	 * @param filter only include specific files
	 * @return false on error
	 */
Move files to a zip file

@param indir input directory containing files to be zipped
@param outfile output zip file
@param filter only include specific files
@return false on error
Move files to a zip file @param indir input directory containing files to be zipped @param outfile output zip file @param filter only include specific files @return false on error
public boolean zip(String indir, String outfile, Predicate<? super Path> filter) {
		Path pin = Paths.get(indir);
		if (! (Files.exists(pin) && Files.isDirectory(pin))) {
			LOG.errorf("Could not find input directory %s", pin);
			return false;
		}
		Path pout = Paths.get(outfile);
		LOG.infof("New zipfile %s", pout);
		try (OutputStream os = Files.newOutputStream(pout);
			ZipOutputStream zos = new ZipOutputStream(os)) {
			Path[] files = Files.walk(pin).filter(f -> f.toFile().isFile()).filter(filter).toArray(Path[]::new);
			for (Path f: files) {
				zip(f, zos);
			}
		} catch (IOException ioe) {
			LOG.error("Could not zip files", ioe);
			return false;
		}
		return true;
	}
public boolean zip ( String indir , String outfile , Predicate < ? super Path > filter ) { Path pin = Paths . get ( indir ) ; if ( ! ( Files . exists ( pin ) && Files . isDirectory ( pin ) ) ) { LOG . errorf ( "Could not find input directory %s" , pin ) ; return false ; } Path pout = Paths . get ( outfile ) ; LOG . infof ( "New zipfile %s" , pout ) ; try ( OutputStream os = Files . newOutputStream ( pout ) ; ZipOutputStream zos = new ZipOutputStream ( os ) ) { Path [ ] files = Files . walk ( pin ) . filter ( f -> f . toFile ( ) . isFile ( ) ) . filter ( filter ) . toArray ( Path [ ] :: new ) ; for ( Path f : files ) { zip ( f , zos ) ; } } catch ( IOException ioe ) { LOG . error ( "Could not zip files" , ioe ) ; return false ; } return true ; }
Move files to a zip file
Move files to a zip file