List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream
public GZIPOutputStream(OutputStream out) throws IOException
From source file:com.stacksync.desktop.util.FileUtil.java
public static byte[] gzip(byte[] content) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); gzipOutputStream.write(content);/*from w w w.jav a 2 s. c o m*/ gzipOutputStream.close(); byte[] result = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.close(); return result; }
From source file:dk.dma.ais.utils.filter.AisFilter.java
private PrintStream getNextOutputStram() { if (outFile == null) { throw new Error("No output stream and no out file argument given"); }//from w ww . j a v a2 s . co m String filename; if (splitSize == null) { filename = outFile; } else { Path path = Paths.get(outFile); filename = String.format("%06d", fileCounter++) + "." + path.getFileName(); Path dir = path.getParent(); if (dir != null) { filename = dir + "/" + filename; } } if (compress) { filename += ".gz"; } try { if (!compress) { return new PrintStream(filename); } else { return new PrintStream(new GZIPOutputStream(new FileOutputStream(filename))); } } catch (IOException e) { throw new RuntimeException("Failed to open output file: " + filename, e); } }
From source file:TextFileHandler.java
public PrintWriter getGZipWriter(String fileName) throws Exception { GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(fileName)); return new PrintWriter(out); }
From source file:de.helmholtz_muenchen.ibis.utils.ngs.samsplitter.helpers.FileHelpers.java
public static BufferedWriter getBufferedWriterOnFile(File file, String format) throws FileNotFoundException, IOException { BufferedWriter bw;/* w w w . j a v a 2s . c o m*/ if (format.toLowerCase().equals("auto")) { format = file.getName(); } if (format.toLowerCase().endsWith("gz")) { bw = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))); } // else if(format.toLowerCase().endsWith("bz2")) // { // bw = new BufferedWriter(new OutputStreamWriter( // new BZip2OutputStream(new FileOutputStream(file)))); // } else { bw = new BufferedWriter(new FileWriter(file)); } return bw; }
From source file:TextFileHandler.java
public void saveGZipFile(File outFile, String content) throws Exception { GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFile)); PrintWriter pw = new PrintWriter(out); pw.write(content);// w w w. j a va 2 s . c o m pw.flush(); pw.close(); }
From source file:com.github.jasonruckman.gzip.AbstractBenchmark.java
private byte[] initializeSidney(JavaSid sid) { Writer<T> writer = sid.newWriter(token); try {/*www . java 2 s .c o m*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); writer.open(gzos); for (T t : sampleData) { writer.write(t); } writer.close(); gzos.close(); return baos.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.mtgi.analytics.XmlBehaviorEventPersisterImpl.java
/** * Force a rotation of the log. The new archive log will be named <code>[logfile].yyyyMMddHHmmss</code>. * If a file of that name already exists, an extra _N will be appended to it, where N is an * integer sufficiently large to make the name unique. This method can be called * externally by the Quartz scheduler for periodic rotation, or by an administrator * via JMX./*from www . ja va 2s. com*/ */ @ManagedOperation(description = "Force a rotation of the behavior tracking log") public String rotateLog() throws IOException, XMLStreamException { StringBuffer msg = new StringBuffer(); synchronized (this) { //flush current writer and close streams. closeWriter(); //rotate old log data to timestamped archive file. File archived = moveToArchive(); if (archived == null) msg.append("No existing log data."); else msg.append(archived.getAbsolutePath()); //update output file name, in case binary/compress settings changed since last rotate. file = getLogFile(file); //perform archive again, in case our file name changed and has pointed us at a preexisting file; //this can happen if the system wasn't shut down cleanly the last time. moveToArchive(); //open a new stream, optionally compressed. if (compress) stream = new GZIPOutputStream(new FileOutputStream(file)); else stream = new BufferedOutputStream(new FileOutputStream(file)); //open a new writer over the stream. if (binary) { StAXDocumentSerializer sds = new StAXDocumentSerializer(); sds.setOutputStream(stream); writer = sds; } else { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(stream); } writer.writeStartDocument(); writer.writeStartElement("event-log"); } return msg.toString(); }
From source file:com.st.maven.debian.DebianPackageMojo.java
private void fillDataTar(Config config, ArFileOutputStream output) throws MojoExecutionException { TarArchiveOutputStream tar = null;//from w w w . j a v a 2 s.co m try { tar = new TarArchiveOutputStream(new GZIPOutputStream(new ArWrapper(output))); tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); if (Boolean.TRUE.equals(javaServiceWrapper)) { byte[] daemonData = processTemplate(freemarkerConfig, config, "daemon.ftl"); TarArchiveEntry initScript = new TarArchiveEntry("etc/init.d/" + project.getArtifactId()); initScript.setSize(daemonData.length); initScript.setMode(040755); tar.putArchiveEntry(initScript); tar.write(daemonData); tar.closeArchiveEntry(); } String packageBaseDir = "home/" + unixUserId + "/" + project.getArtifactId() + "/"; if (fileSets != null && !fileSets.isEmpty()) { writeDirectory(tar, packageBaseDir); Collections.sort(fileSets, MappingPathComparator.INSTANCE); for (Fileset curPath : fileSets) { curPath.setTarget(packageBaseDir + curPath.getTarget()); addRecursively(config, tar, curPath); } } } catch (Exception e) { throw new MojoExecutionException("unable to create data tar", e); } finally { IOUtils.closeQuietly(tar); } }
From source file:anhttpclient.AnhttpclientTest.java
@Test public void testGzipResponse() throws Exception { final String responseText = "Hello from SimpleHttperver"; server.addHandler("/gzip", new ByteArrayHandlerAdapter() { public byte[] getResponseAsByteArray(HttpRequestContext httpRequestContext) { byte[] out; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = new GZIPOutputStream(baos); os.write(responseText.getBytes()); os.flush();//from w w w .j a va2s . c o m os.close(); out = baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } setResponseHeader("Content-Encoding", "gzip", httpRequestContext); return out; } }); WebRequest req = new HttpGetWebRequest(server.getBaseUrl() + "/gzip"); WebResponse resp = wb.getResponse(req); assertEquals("Response from server is incorrect", responseText, resp.getText()); }
From source file:edu.illinois.cs.cogcomp.core.datastructures.Lexicon.java
/** * Saves the feature to id mapping. Note: This does not store the feature names. *//*from w w w.j a v a 2 s . c o m*/ public void save(String file) throws IOException { BufferedOutputStream stream = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))); final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream)); writer.write(lexManagerVersion); writer.newLine(); writeInt(writer, nextFeatureId); log.info("Lexicon contains {} features", feature2Id.size()); writeInt(writer, feature2Id.size()); feature2Id.forEachEntry(new TIntIntProcedure() { @Override public boolean execute(int a, int b) { try { writeInt(writer, a); writeInt(writer, b); } catch (IOException e) { throw new RuntimeException(e); } return true; } }); if (featureNames != null) { writeInt(writer, featureNames.size()); for (String s : featureNames) { writer.write(s); writer.newLine(); } } else { writeInt(writer, 0); } writer.close(); log.info("Verifying save..."); new Lexicon(new FileInputStream(new File(file)), false); log.info("Done."); }