List of usage examples for java.util.zip ZipEntry ZipEntry
public ZipEntry(ZipEntry e)
From source file:pl.betoncraft.betonquest.editor.model.PackageSet.java
/** * Saves the package to a .zip file./*from w ww . jav a 2 s .c o m*/ * * @param zipFile */ public void saveToZip(File zip) { try { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip)); for (QuestPackage pack : packages) { String prefix = pack.getName().get().replace("-", File.separator) + File.separator; // save main.yml file ZipEntry main = new ZipEntry(prefix + "main.yml"); out.putNextEntry(main); pack.printMainYAML(out); out.closeEntry(); // save conversation files for (Conversation conv : pack.getConversations()) { ZipEntry conversation = new ZipEntry( prefix + "conversations" + File.separator + conv.getId().get() + ".yml"); out.putNextEntry(conversation); pack.printConversationYaml(out, conv); out.closeEntry(); } // save events.yml file ZipEntry events = new ZipEntry(prefix + "events.yml"); out.putNextEntry(events); pack.printEventsYaml(out); out.closeEntry(); // save conditions.yml file ZipEntry conditions = new ZipEntry(prefix + "conditions.yml"); out.putNextEntry(conditions); pack.printConditionsYaml(out); out.closeEntry(); // save objectives.yml file ZipEntry objectives = new ZipEntry(prefix + "objectives.yml"); out.putNextEntry(objectives); pack.printObjectivesYaml(out); out.closeEntry(); // save items.yml file ZipEntry items = new ZipEntry(prefix + "items.yml"); out.putNextEntry(items); pack.printItemsYaml(out); out.closeEntry(); // save journal.yml file ZipEntry journal = new ZipEntry(prefix + "journal.yml"); out.putNextEntry(journal); pack.printJournalYaml(out); out.closeEntry(); } // done out.close(); } catch (Exception e) { ExceptionController.display(e); } }
From source file:com.dbi.jmmerge.MapController.java
private void addDirectoryContents(String fullDirPath, File directory, ZipOutputStream zip) throws IOException { if (fullDirPath == null) fullDirPath = ""; for (File file : directory.listFiles()) { if (file.isDirectory()) { if (fullDirPath.length() > 0) { addDirectoryContents(fullDirPath + "/" + file.getName(), file, zip); } else { addDirectoryContents(file.getName(), file, zip); }/*from w w w.j a v a 2 s . c om*/ } else { String entryName = ""; if (fullDirPath.length() == 0) { entryName = file.getName(); } else { entryName = fullDirPath + "/" + file.getName(); } ZipEntry entry = new ZipEntry(entryName); zip.putNextEntry(entry); FileInputStream in = new FileInputStream(file); IOUtils.copy(in, zip); in.close(); zip.closeEntry(); } } }
From source file:moskitt4me.repositoryClient.core.util.RepositoryClientUtil.java
public static void addFolderToZip(File folder, String parentFolder, ZipOutputStream zos) throws Exception { for (File file : folder.listFiles()) { if (file.isDirectory()) { zos.putNextEntry(new ZipEntry(parentFolder + file.getName() + "/")); zos.closeEntry();// w w w .ja va 2 s .co m addFolderToZip(file, parentFolder + file.getName() + "/", zos); continue; } else { zos.putNextEntry(new ZipEntry(parentFolder + file.getName())); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); long bytesRead = 0; byte[] bytesIn = new byte[1024]; int read = 0; while ((read = bis.read(bytesIn)) != -1) { zos.write(bytesIn, 0, read); bytesRead += read; } zos.closeEntry(); bis.close(); } } }
From source file:org.tonguetied.datatransfer.DataServiceImpl.java
public void createArchive(File directory) throws ExportException, IllegalArgumentException { if (!directory.isDirectory()) throw new IllegalArgumentException("expecting a directory"); ZipOutputStream zos = null;//from w ww.j a v a 2s. c o m try { File[] files = directory.listFiles(); if (files.length > 0) { final File archive = new File(directory, directory.getName() + ".zip"); zos = new ZipOutputStream(new FileOutputStream(archive)); for (File file : files) { zos.putNextEntry(new ZipEntry(file.getName())); IOUtils.write(FileUtils.readFileToByteArray(file), zos); zos.closeEntry(); } if (logger.isDebugEnabled()) logger.debug("archived " + files.length + " files to " + archive.getPath()); } } catch (IOException ioe) { throw new ExportException(ioe); } finally { IOUtils.closeQuietly(zos); } }
From source file:net.solarnetwork.node.backup.DefaultBackupManager.java
@Override public void exportBackupArchive(String backupKey, OutputStream out) throws IOException { final BackupService service = activeBackupService(); if (service == null) { return;//from ww w .ja va2 s . co m } final Backup backup = service.backupForKey(backupKey); if (backup == null) { return; } // create the zip archive for the backup files ZipOutputStream zos = new ZipOutputStream(out); try { BackupResourceIterable resources = service.getBackupResources(backup); for (BackupResource r : resources) { zos.putNextEntry(new ZipEntry(r.getBackupPath())); FileCopyUtils.copy(r.getInputStream(), new FilterOutputStream(zos) { @Override public void close() throws IOException { // FileCopyUtils closed the stream, which we don't want here } }); } resources.close(); } finally { zos.flush(); zos.finish(); zos.close(); } }
From source file:de.uni_koeln.spinfo.maalr.services.editor.server.EditorServiceImpl.java
public void export(Set<String> fields, MaalrQuery query, File dest) throws IOException, InvalidQueryException, NoIndexAvailableException, BrokenIndexException, InvalidTokenOffsetsException { query.setPageNr(0);//from w w w .j a va 2s . co m query.setPageSize(50); ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(dest)); zout.putNextEntry(new ZipEntry("exported.tsv")); OutputStream out = new BufferedOutputStream(zout); OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); for (String field : fields) { writer.write(field); writer.write("\t"); } writer.write("\n"); while (true) { QueryResult result = index.query(query, false); if (result == null || result.getEntries() == null || result.getEntries().size() == 0) break; List<LemmaVersion> entries = result.getEntries(); for (LemmaVersion version : entries) { write(writer, version, fields); writer.write("\n"); } query.setPageNr(query.getPageNr() + 1); } writer.flush(); zout.closeEntry(); writer.close(); }
From source file:es.urjc.mctwp.bbeans.research.image.DownloadBean.java
private void addFileToZos(ZipOutputStream zos, File file, String path) throws IOException { //Prepare entry path String entry = null;/*from w w w .j a v a 2s . com*/ if (path != null && !path.isEmpty()) entry = path + "/" + file.getName(); else entry = file.getName(); //Create zip entry ZipEntry ze = new ZipEntry(entry); zos.putNextEntry(ze); //Write zip entry FileInputStream fileIS = new FileInputStream(file); while (fileIS.available() > 0) { byte bytes[] = new byte[fileIS.available()]; fileIS.read(bytes); zos.write(bytes); } zos.flush(); fileIS.close(); }
From source file:org.elasticsearch.plugins.PluginManagerIT.java
/** creates a plugin .zip and bad checksum file and returns the url for testing */ private String createPluginWithBadChecksum(final Path structure, String... properties) throws IOException { writeProperties(structure, properties); Path zip = createTempDir().resolve(structure.getFileName() + ".zip"); try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zip))) { Files.walkFileTree(structure, new SimpleFileVisitor<Path>() { @Override/* www . j a v a 2 s . co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { stream.putNextEntry(new ZipEntry(structure.relativize(file).toString())); Files.copy(file, stream); return FileVisitResult.CONTINUE; } }); } if (randomBoolean()) { writeSha1(zip, true); } else { writeMd5(zip, true); } return zip.toUri().toURL().toString(); }
From source file:com.wavemaker.tools.project.StageDeploymentManager.java
protected void assembleEar(Map<String, Object> properties, com.wavemaker.tools.io.File warFile) { ZipOutputStream out;/*from www .j a va 2s . c o m*/ InputStream is; try { com.wavemaker.tools.io.File earFile = (com.wavemaker.tools.io.File) properties .get(EAR_FILE_NAME_PROPERTY); out = new ZipOutputStream(earFile.getContent().asOutputStream()); out.putNextEntry(new ZipEntry(warFile.getName())); is = warFile.getContent().asInputStream(); org.apache.commons.io.IOUtils.copy(is, out); out.closeEntry(); is.close(); Folder webInf = ((Folder) properties.get(BUILD_WEBAPPROOT_PROPERTY)).getFolder("WEB-INF"); com.wavemaker.tools.io.File appXml = webInf.getFile("application.xml"); out.putNextEntry(new ZipEntry("META-INF/" + appXml.getName())); is = appXml.getContent().asInputStream(); org.apache.commons.io.IOUtils.copy(is, out); out.closeEntry(); is.close(); String maniFest = "Manifest-Version: 1.0\n" + "Created-By: WaveMaker Studio (CloudJee Inc.)"; out.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); org.apache.commons.io.IOUtils.write(maniFest, out); out.closeEntry(); is.close(); out.close(); } catch (IOException ex) { throw new WMRuntimeException(ex); } }
From source file:com.l2jfree.sql.L2DataSource.java
protected static final boolean writeBackup(String databaseName, InputStream in) throws IOException { FileUtils.forceMkdir(new File("backup/database")); final Date time = new Date(); final L2TextBuilder tb = new L2TextBuilder(); tb.append("backup/database/DatabaseBackup_"); tb.append(new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date())); tb.append("_uptime-").append(L2Config.getShortUptime()); tb.append(".zip"); final File backupFile = new File(tb.moveToString()); int written = 0; ZipOutputStream out = null;/*w w w . ja v a2 s .c o m*/ try { out = new ZipOutputStream(new FileOutputStream(backupFile)); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(Deflater.BEST_COMPRESSION); out.setComment("L2jFree Schema Backup Utility\r\n\r\nBackup date: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS z").format(new Date())); out.putNextEntry(new ZipEntry(databaseName + ".sql")); byte[] buf = new byte[4096]; for (int read; (read = in.read(buf)) != -1;) { out.write(buf, 0, read); written += read; } } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } if (written == 0) { backupFile.delete(); return false; } _log.info("DatabaseBackupManager: Database `" + databaseName + "` backed up successfully in " + (System.currentTimeMillis() - time.getTime()) / 1000 + " s."); return true; }