java/unzip/src/main/java/be/bosa/dt/best/unzip/Unzipper.java
/**
	 * Perform some quick checks and unzip, return on error
	 * 
	 * @param infile zip input file
	 * @param outdir output directory
	 * @return false on error
	 */
Perform some quick checks and unzip, return on error

@param infile zip input file
@param outdir output directory
@return false on error
Perform some quick checks and unzip return on error @param infile zip input file @param outdir output directory @return false on error
public boolean checkAndUnzip(String infile, String outdir) {
		if (! infile.toLowerCase().endsWith("zip")) {
			LOG.severe("Not a zip file");
			return false;
		}
		Path pin = Paths.get(infile);
		if (! (Files.exists(pin) && Files.isRegularFile(pin))) {
			LOG.severe("Could not find input file");
			return false;
		}
		Path pout = Paths.get(outdir);
		if (! (Files.exists(pout))) {
			try {
				LOG.log(Level.INFO, "Creating output directory {0}", pout);
				Files.createDirectories(pout);
			} catch (IOException ex) {
				LOG.log(Level.SEVERE, "Could not create output directory {0}", pout);
				return false;
			}
		}
		try {
			Path[] files = Files.walk(pout).filter(f -> !f.equals(pout)).toArray(Path[]::new);
			for (Path f: files) {
				LOG.log(Level.INFO, "Deleting {}", f);
				Files.delete(f);
			}
		} catch (IOException ioe) {
			LOG.log(Level.SEVERE, "Could not delete files in directory", ioe);
			return false;
		}
		return unzip(pin, pout);
	}
public boolean checkAndUnzip ( String infile , String outdir ) { if ( ! infile . toLowerCase ( ) . endsWith ( "zip" ) ) { LOG . severe ( "Not a zip file" ) ; return false ; } Path pin = Paths . get ( infile ) ; if ( ! ( Files . exists ( pin ) && Files . isRegularFile ( pin ) ) ) { LOG . severe ( "Could not find input file" ) ; return false ; } Path pout = Paths . get ( outdir ) ; if ( ! ( Files . exists ( pout ) ) ) { try { LOG . log ( Level . INFO , "Creating output directory {0}" , pout ) ; Files . createDirectories ( pout ) ; } catch ( IOException ex ) { LOG . log ( Level . SEVERE , "Could not create output directory {0}" , pout ) ; return false ; } } try { Path [ ] files = Files . walk ( pout ) . filter ( f -> ! f . equals ( pout ) ) . toArray ( Path [ ] :: new ) ; for ( Path f : files ) { LOG . log ( Level . INFO , "Deleting {}" , f ) ; Files . delete ( f ) ; } } catch ( IOException ioe ) { LOG . log ( Level . SEVERE , "Could not delete files in directory" , ioe ) ; return false ; } return unzip ( pin , pout ) ; }
Perform some quick checks and unzip, return on error
Perform some quick checks and unzip return on error