private ZipFile createZipFile ( List < Path . Entry < ? > > files ) throws IOException { // The set of known paths HashSet < Path . ID > paths = new HashSet <> ( ) ; // The zip file we're creating ZipFile zf = new ZipFile ( ) ; // Add each file to zip file for ( int i = 0 ; i != files . size ( ) ; ++ i ) { Path . Entry < ? > file = files . get ( i ) ; // Extract path addPaths ( file . id ( ) . parent ( ) , paths , zf ) ; // Construct filename for given entry String filename = file . id ( ) . toString ( ) + "." + file . contentType ( ) . getSuffix ( ) ; // Extract bytes representing entry byte [ ] contents = readFileContents ( file ) ; zf . add ( new ZipEntry ( filename ) , contents ) ; } // return zf ; }
Given a list of files construct a corresponding ZipFile containing them .