java/unzip/src/main/java/be/bosa/dt/best/unzip/Unzipper.java
/**
	 * Unzip a zip file into a directory
	 * 
	 * @param pin input file
	 * @param pout output directory
	 * @return false in case of error
	 */
Unzip a zip file into a directory

@param pin input file
@param pout output directory
@return false in case of error
Unzip a zip file into a directory @param pin input file @param pout output directory @return false in case of error
public boolean unzip(Path pin, Path pout) {
		boolean ok = true;
		try (ZipFile zip = new ZipFile(pin.toFile())) {
			for (ZipEntry f: zip.stream().toArray(ZipEntry[]::new)) {
				String name = f.getName();
				Path p = Paths.get(pout.toString(), name);
				LOG.log(Level.INFO, "Unzipping {0}", p);
				try (InputStream is = zip.getInputStream(f);
					OutputStream os = Files.newOutputStream(p)) {
					IOUtils.copyLarge(is, os);
					if (name.endsWith("zip")) { 
						unzip(p, pout);
						Files.delete(p);
					}
				} catch (IOException e) {
					ok = false;
					LOG.log(Level.SEVERE, "Error extracting {0}", p);
				}
			}
		} catch (IOException ioe) {
			ok = false;
			LOG.log(Level.SEVERE, "Error extracting {0}", pin);
		}
		return ok;
	}
public boolean unzip ( Path pin , Path pout ) { boolean ok = true ; try ( ZipFile zip = new ZipFile ( pin . toFile ( ) ) ) { for ( ZipEntry f : zip . stream ( ) . toArray ( ZipEntry [ ] :: new ) ) { String name = f . getName ( ) ; Path p = Paths . get ( pout . toString ( ) , name ) ; LOG . log ( Level . INFO , "Unzipping {0}" , p ) ; try ( InputStream is = zip . getInputStream ( f ) ; OutputStream os = Files . newOutputStream ( p ) ) { IOUtils . copyLarge ( is , os ) ; if ( name . endsWith ( "zip" ) ) { unzip ( p , pout ) ; Files . delete ( p ) ; } } catch ( IOException e ) { ok = false ; LOG . log ( Level . SEVERE , "Error extracting {0}" , p ) ; } } } catch ( IOException ioe ) { ok = false ; LOG . log ( Level . SEVERE , "Error extracting {0}" , pin ) ; } return ok ; }
Unzip a zip file into a directory
Unzip a zip file into a directory
// zip within zip