List of usage examples for java.util.zip ZipOutputStream setMethod
public void setMethod(int method)
From source file:org.exist.util.Compressor.java
/** * The method <code>compress</code> * * @param whatToCompress a <code>byte[]</code> value * @param length an <code>int</code> value * @return a <code>byte[]</code> value * @exception IOException if an error occurs *///from w w w . j a v a 2s . c o m public static byte[] compress(byte[] whatToCompress, int length) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream gzos = new ZipOutputStream(baos); gzos.setMethod(ZipOutputStream.DEFLATED); gzos.putNextEntry(new ZipEntry(length + "")); gzos.write(whatToCompress, 0, length); gzos.closeEntry(); gzos.finish(); gzos.close(); return baos.toByteArray(); }
From source file:Main.java
public static String compress(String filename) throws FileNotFoundException, IOException { byte[] buffer = new byte[4096]; int bytesRead; String[] entries = { ".mp4" }; String zipfile = filename.replace(".mp4", ".zip"); if (!(new File(zipfile)).exists()) { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile)); out.setLevel(Deflater.BEST_COMPRESSION); out.setMethod(ZipOutputStream.DEFLATED); for (int i = 0; i < entries.length; i++) { File f = new File(filename.replace(".mp4", entries[i])); if (f.exists()) { FileInputStream in = new FileInputStream(f); ZipEntry entry = new ZipEntry(f.getName()); out.putNextEntry(entry); while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead); in.close();// w w w. ja v a 2s. c o m } } out.close(); } return zipfile; }
From source file:com.l2jfree.gameserver.util.DatabaseBackupManager.java
public static void makeBackup() { File f = new File(Config.DATAPACK_ROOT, Config.DATABASE_BACKUP_SAVE_PATH); if (!f.mkdirs() && !f.exists()) { _log.warn("Could not create folder " + f.getAbsolutePath()); return;/*w w w .j a va2 s . com*/ } _log.info("DatabaseBackupManager: backing up `" + Config.DATABASE_BACKUP_DATABASE_NAME + "`..."); Process run = null; try { run = Runtime.getRuntime().exec("mysqldump" + " --user=" + Config.DATABASE_LOGIN + " --password=" + Config.DATABASE_PASSWORD + " --compact --complete-insert --default-character-set=utf8 --extended-insert --lock-tables --quick --skip-triggers " + Config.DATABASE_BACKUP_DATABASE_NAME, null, new File(Config.DATABASE_BACKUP_MYSQLDUMP_PATH)); } catch (Exception e) { } finally { if (run == null) { _log.warn("Could not execute mysqldump!"); return; } } try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); Date time = new Date(); File bf = new File(f, sdf.format(time) + (Config.DATABASE_BACKUP_COMPRESSION ? ".zip" : ".sql")); if (!bf.createNewFile()) throw new IOException("Cannot create backup file: " + bf.getCanonicalPath()); InputStream input = run.getInputStream(); OutputStream out = new FileOutputStream(bf); if (Config.DATABASE_BACKUP_COMPRESSION) { ZipOutputStream dflt = new ZipOutputStream(out); dflt.setMethod(ZipOutputStream.DEFLATED); dflt.setLevel(Deflater.BEST_COMPRESSION); dflt.setComment("L2JFree Schema Backup Utility\r\n\r\nBackup date: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS z").format(time)); dflt.putNextEntry(new ZipEntry(Config.DATABASE_BACKUP_DATABASE_NAME + ".sql")); out = dflt; } byte[] buf = new byte[4096]; int written = 0; for (int read; (read = input.read(buf)) != -1;) { out.write(buf, 0, read); written += read; } input.close(); out.close(); if (written == 0) { bf.delete(); BufferedReader br = new BufferedReader(new InputStreamReader(run.getErrorStream())); String line; while ((line = br.readLine()) != null) _log.warn("DatabaseBackupManager: " + line); br.close(); } else _log.info("DatabaseBackupManager: Schema `" + Config.DATABASE_BACKUP_DATABASE_NAME + "` backed up successfully in " + (System.currentTimeMillis() - time.getTime()) / 1000 + " s."); run.waitFor(); } catch (Exception e) { _log.warn("DatabaseBackupManager: Could not make backup: ", e); } }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
public static byte[] zipContest(Contests contest) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(baos); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(java.util.zip.Deflater.BEST_COMPRESSION); Contest xml = new Contest(); ZipContest.addContest(out, xml, contest); putXml(out, "contest.xml", xml); out.close();/*w w w. j a v a 2 s. co m*/ return baos.toByteArray(); }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
public static byte[] zipSerie(Series serie) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(baos); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(java.util.zip.Deflater.BEST_COMPRESSION); Serie xml = new Serie(); ZipSerie.addSerie(out, xml, serie);//w w w . java 2s . com putXml(out, "serie.xml", xml); out.close(); return baos.toByteArray(); }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
public static byte[] zipProblem(Problems problem) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(baos); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(java.util.zip.Deflater.BEST_COMPRESSION); Problem xml = new Problem(); ZipProblem.addProblem(out, xml, problem); putXml(out, "problem.xml", xml); out.close();//from w w w . jav a2 s. c om return baos.toByteArray(); }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
public static byte[] zipTest(Tests test) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(baos); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(java.util.zip.Deflater.BEST_COMPRESSION); Test xml = new Test(); ZipTest.addTest(out, xml, test);/*from w ww . ja v a 2s.c o m*/ putXml(out, "test.xml", xml); out.close(); return baos.toByteArray(); }
From source file:pl.umk.mat.zawodyweb.www.zip.ZipFile.java
public static byte[] zipTests(List<Tests> tests) throws IOException, JAXBException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(baos); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(java.util.zip.Deflater.BEST_COMPRESSION); pl.umk.mat.zawodyweb.database.xml.Tests xml = new pl.umk.mat.zawodyweb.database.xml.Tests(); for (Tests test : tests) { Test xmlTest = new Test(); ZipTest.addTest(out, xmlTest, test); xml.getTests().add(xmlTest);/*from w ww . j a v a 2 s . co m*/ } putXml(out, "tests.xml", xml); out.close(); return baos.toByteArray(); }
From source file:mpimp.assemblxweb.util.J5FileUtils.java
public static void zipDirectory(String dirPath, String targetPath) throws Exception { BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream(targetPath); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); out.setMethod(ZipOutputStream.DEFLATED); int BUFFER = 2048; byte data[] = new byte[BUFFER]; zipDirectoryRecursively(dirPath, origin, BUFFER, out, data, new File(dirPath).getName()); out.close();/* www .j a v a2 s . co m*/ }
From source file:org.xdi.util.io.ResponseHelper.java
public static ZipOutputStream createZipStream(OutputStream output, String comment) { ZipOutputStream zos = new ZipOutputStream(output); zos.setComment("Shibboleth2 SP configuration files"); zos.setMethod(ZipOutputStream.DEFLATED); zos.setLevel(Deflater.DEFAULT_COMPRESSION); return zos;/*from w w w. java 2s . c om*/ }