List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream
public GZIPOutputStream(OutputStream out) throws IOException
From source file:GZIPcompress.java
public static void main(String[] args) throws IOException { if (args.length == 0) { System.out.println("Usage: \nGZIPcompress file\n" + "\tUses GZIP compression to compress " + "the file to test.gz"); System.exit(1);/* w w w . j a v a 2 s . co m*/ } BufferedReader in = new BufferedReader(new FileReader(args[0])); BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("test.gz"))); System.out.println("Writing file"); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); System.out.println("Reading file"); BufferedReader in2 = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream("test.gz")))); String s; while ((s = in2.readLine()) != null) System.out.println(s); }
From source file:cmd.freebase2rdf.java
public static void main(String[] args) throws Exception { if (args.length != 2) { usage();/*w w w. ja v a 2 s . c om*/ } File input = new File(args[0]); if (!input.exists()) error("File " + input.getAbsolutePath() + " does not exist."); if (!input.canRead()) error("Cannot read file " + input.getAbsolutePath()); if (!input.isFile()) error("Not a file " + input.getAbsolutePath()); File output = new File(args[1]); if (output.exists()) error("Output file " + output.getAbsolutePath() + " already exists, this program do not override existing files."); if (output.canWrite()) error("Cannot write file " + output.getAbsolutePath()); if (output.isDirectory()) error("Not a file " + output.getAbsolutePath()); if (!output.getName().endsWith(".nt.gz")) error("Output filename should end with .nt.gz, this is the only format supported."); BufferedReader in = new BufferedReader( new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(input)))); BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(output))); String line; ProgressLogger progressLogger = new ProgressLogger(log, "lines", 100000, 1000000); progressLogger.start(); Freebase2RDF freebase2rdf = null; try { freebase2rdf = new Freebase2RDF(out); while ((line = in.readLine()) != null) { freebase2rdf.send(line); progressLogger.tick(); } } finally { if (freebase2rdf != null) freebase2rdf.close(); } print(log, progressLogger); }
From source file:io.minimum.minecraft.rbclean.RedisBungeeClean.java
public static void main(String... args) { Options options = new Options(); Option hostOption = new Option("h", "host", true, "Sets the Redis host to use."); hostOption.setRequired(true);/* w w w.j av a 2s . co m*/ options.addOption(hostOption); Option portOption = new Option("p", "port", true, "Sets the Redis port to use."); options.addOption(portOption); Option passwordOption = new Option("w", "password", true, "Sets the Redis password to use."); options.addOption(passwordOption); Option dryRunOption = new Option("d", "dry-run", false, "Performs a dry run (no data is modified)."); options.addOption(dryRunOption); CommandLine commandLine; try { commandLine = new DefaultParser().parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("RedisBungeeClean", options); return; } int port = commandLine.hasOption('p') ? Integer.parseInt(commandLine.getOptionValue('p')) : 6379; try (Jedis jedis = new Jedis(commandLine.getOptionValue('h'), port, 0)) { if (commandLine.hasOption('w')) { jedis.auth(commandLine.getOptionValue('w')); } System.out.println("Fetching UUID cache..."); Map<String, String> uuidCache = jedis.hgetAll("uuid-cache"); Gson gson = new Gson(); // Just in case we need it, compress everything in JSON format. if (!commandLine.hasOption('d')) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); File file = new File("uuid-cache-previous-" + dateFormat.format(new Date()) + ".json.gz"); try { file.createNewFile(); } catch (IOException e) { System.out.println("Can't write backup of the UUID cache, will NOT proceed."); e.printStackTrace(); return; } System.out.println("Creating backup (as " + file.getName() + ")..."); try (OutputStreamWriter bw = new OutputStreamWriter( new GZIPOutputStream(new FileOutputStream(file)))) { gson.toJson(uuidCache, bw); } catch (IOException e) { System.out.println("Can't write backup of the UUID cache, will NOT proceed."); e.printStackTrace(); return; } } System.out.println("Cleaning out the bird cage (this may take a while...)"); int originalSize = uuidCache.size(); for (Iterator<Map.Entry<String, String>> it = uuidCache.entrySet().iterator(); it.hasNext();) { CachedUUIDEntry entry = gson.fromJson(it.next().getValue(), CachedUUIDEntry.class); if (entry.expired()) { it.remove(); } } int newSize = uuidCache.size(); if (commandLine.hasOption('d')) { System.out.println( (originalSize - newSize) + " records would be expunged if a dry run was not conducted."); } else { System.out.println("Expunging " + (originalSize - newSize) + " records..."); Transaction transaction = jedis.multi(); transaction.del("uuid-cache"); transaction.hmset("uuid-cache", uuidCache); transaction.exec(); System.out.println("Expunging complete."); } } }
From source file:di.uniba.it.tee2.wiki.Wikidump2Text.java
/** * @param args the command line arguments *///from w w w . jav a 2s .c o m public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) { encoding = cmd.getOptionValue("e", "UTF-8"); int counter = 0; try { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new GZIPOutputStream(new FileOutputStream(cmd.getOptionValue("o"))), "UTF-8")); WikipediaDumpIterator it = new WikipediaDumpIterator(new File(cmd.getOptionValue("d")), encoding); PageCleaner cleaner = PageCleanerWrapper.getInstance(cmd.getOptionValue("l")); while (it.hasNext()) { WikiPage wikiPage = it.next(); ParsedPage parsedPage = wikiPage.getParsedPage(); if (parsedPage != null) { String title = wikiPage.getTitle(); if (!title.matches(notValidTitle)) { if (parsedPage.getText() != null) { writer.append(cleaner.clean(parsedPage.getText())); writer.newLine(); writer.newLine(); counter++; if (counter % 10000 == 0) { System.out.println(counter); writer.flush(); } } } } } writer.flush(); writer.close(); } catch (Exception ex) { Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Indexed pages: " + counter); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Wikipedia dump to text", options, true); } } catch (ParseException ex) { Logger.getLogger(Wikidump2Text.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.foudroyantfactotum.mod.fousarchive.utility.midi.FileSupporter.java
public static void main(String[] args) throws InterruptedException, IOException { for (int i = 0; i < noOfWorkers; ++i) pool.submit(new ConMidiDetailsPuller()); final File sourceDir = new File(source); final File outputDir = new File(output); Logger.info(UserLogger.GENERAL, "source directory: " + sourceDir.getAbsolutePath()); Logger.info(UserLogger.GENERAL, "output directory: " + outputDir.getAbsolutePath()); Logger.info(UserLogger.GENERAL, "processing midi files using " + noOfWorkers + " cores"); FileUtils.deleteDirectory(outputDir); FileUtils.touch(new File(outputDir + "/master.json.gz")); for (File sfile : sourceDir.listFiles()) { recFile(sfile, files);//w ww . j a va 2 s . c o m } for (int i = 0; i < noOfWorkers; ++i) files.put(TERMINATOR); pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);//just get all the work done first. try (final OutputStream fstream = new FileOutputStream(outputDir + "/master.json.gz")) { try (final GZIPOutputStream gzstream = new GZIPOutputStream(fstream)) { final OutputStreamWriter osw = new OutputStreamWriter(gzstream); osw.write(JSON.toJson(processedMidiFiles)); osw.flush(); } } catch (IOException e) { Logger.info(UserLogger.GENERAL, e.toString()); } Logger.info(UserLogger.GENERAL, "Processed " + processedMidiFiles.size() + " midi files out of " + fileCount + " files. " + (fileCount - processedMidiFiles.size()) + " removed"); }
From source file:btrplace.fromEntropy.Converter.java
public static void main(String[] args) { String src, dst = null, output, scriptDC = null, dirScriptsCL = null; if (args.length < 5 || args.length > 6 || !args[args.length - 2].equals("-o")) { usage(1);/*from w w w. ja v a2 s. c om*/ } src = args[0]; output = args[args.length - 1]; if (args.length > 5) { dst = args[1]; } scriptDC = args[args.length - 4]; dirScriptsCL = args[args.length - 3]; OutputStreamWriter out = null; try { // Convert the src file ConfigurationConverter conv = new ConfigurationConverter(src); Instance i = conv.getInstance(); // Read the dst file, deduce and add the states constraints if (dst != null) { i.getSatConstraints().addAll(conv.getNextStates(dst)); } // Read the script files ScriptBuilder scriptBuilder = new ScriptBuilder(i.getModel()); //scriptBuilder.setIncludes(new PathBasedIncludes(scriptBuilder, // new File("src/test/resources"))); // Read the datacenter script file if exists if (scriptDC != null) { String strScriptDC = null; try { strScriptDC = readFile(scriptDC); } catch (IOException e) { e.printStackTrace(); } Script scrDC = null; try { // Build the DC script scrDC = scriptBuilder.build(strScriptDC); } catch (ScriptBuilderException sbe) { System.out.println(sbe); } // Set the DC script as an include BasicIncludes bi = new BasicIncludes(); bi.add(scrDC); scriptBuilder.setIncludes(bi); } // Read all the client script files String scriptCL = null, strScriptCL = null; Script scrCL = null; Iterator it = FileUtils.iterateFiles(new File(dirScriptsCL), null, false); while (it.hasNext()) { scriptCL = dirScriptsCL + "/" + ((File) it.next()).getName(); if (scriptCL != null) { // Read try { strScriptCL = readFile(scriptCL); } catch (IOException e) { e.printStackTrace(); } // Parse try { scrCL = scriptBuilder.build(strScriptCL); } catch (ScriptBuilderException sbe) { System.out.println(sbe); sbe.printStackTrace(); } // Add the resulting constraints if (scrCL.getConstraints() != null) { i.getSatConstraints().addAll(scrCL.getConstraints()); } } } /************** PATCH **************/ // State constraints; for (Node n : i.getModel().getMapping().getOnlineNodes()) { i.getSatConstraints().add(new Online(n)); } for (Node n : i.getModel().getMapping().getOfflineNodes()) { i.getSatConstraints().add(new Offline(n)); } // Remove preserve constraints for (Iterator<SatConstraint> ite = i.getSatConstraints().iterator(); ite.hasNext();) { SatConstraint s = ite.next(); if (s instanceof Preserve && src.contains("nr")) { ite.remove(); } } /************************************/ // Convert to JSON InstanceConverter iConv = new InstanceConverter(); JSONObject o = iConv.toJSON(i); // Check for gzip extension if (output.endsWith(".gz")) { out = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(output))); } else { out = new FileWriter(output); } // Write the output file o.writeJSONString(out); out.close(); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(1); } finally { if (out != null) { try { out.close(); } catch (IOException e) { System.err.println(e.getMessage()); System.exit(1); } } } }
From source file:com.boundary.zoocreeper.Backup.java
public static void main(String[] args) throws IOException, InterruptedException, KeeperException { BackupOptions options = new BackupOptions(); CmdLineParser parser = new CmdLineParser(options); try {/*from www .ja v a2 s. c o m*/ parser.parseArgument(args); if (options.help) { usage(parser, 0); } } catch (CmdLineException e) { if (!options.help) { System.err.println(e.getLocalizedMessage()); } usage(parser, options.help ? 0 : 1); } if (options.verbose) { LoggingUtils.enableDebugLogging(Backup.class.getPackage().getName()); } Backup backup = new Backup(options); OutputStream os; if ("-".equals(options.outputFile)) { os = System.out; } else { os = new BufferedOutputStream(new FileOutputStream(options.outputFile)); } try { if (options.compress) { os = new GZIPOutputStream(os); } backup.backup(os); } finally { os.flush(); Closeables.close(os, true); } }
From source file:Main.java
public static byte[] compressGZIP(byte bytes[]) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); GZIPOutputStream gzipos = new GZIPOutputStream(os); gzipos.write(bytes, 0, bytes.length); gzipos.close();//from w w w. ja v a2 s. c o m return os.toByteArray(); }
From source file:Main.java
public static byte[] gzip(byte[] data) { byte[] b = null; try {// w w w .j av a 2 s . co m ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(bos); gzip.write(data); gzip.finish(); gzip.close(); b = bos.toByteArray(); bos.close(); } catch (Exception ex) { ex.printStackTrace(); } return b; }
From source file:Main.java
public static final byte[] compress(byte[] val) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(val.length); GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(val, 0, val.length); gos.finish();/* w w w. j ava2 s . c o m*/ gos.close(); // store it and set compression flag return bos.toByteArray(); }