List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream
public GZIPOutputStream(OutputStream out) throws IOException
From source file:com.linkedin.r2.filter.compression.stream.TestStreamingCompression.java
@Test public void testGzipCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException { StreamingCompressor compressor = new GzipCompressor(_executor); final byte[] origin = new byte[BUF_SIZE]; Arrays.fill(origin, (byte) 'b'); ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); IOUtils.write(origin, gzip);//from w w w.j ava 2s .c o m gzip.close(); byte[] compressed = out.toByteArray(); testCompress(compressor, origin, compressed); testDecompress(compressor, origin, compressed); testCompressThenDecompress(compressor, origin); }
From source file:com.panet.imeta.www.GetJobStatusServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!request.getContextPath().equals(CONTEXT_PATH)) return;/* w w w . j av a 2 s .com*/ if (log.isDebug()) log.logDebug(toString(), Messages.getString("GetJobStatusServlet.Log.JobStatusRequested")); String jobName = request.getParameter("name"); boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml")); response.setStatus(HttpServletResponse.SC_OK); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); } else { response.setContentType("text/html"); } PrintWriter out = response.getWriter(); Job job = jobMap.getJob(jobName); if (job != null) { String status = job.getStatus(); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING)); SlaveServerJobStatus jobStatus = new SlaveServerJobStatus(jobName, status); Log4jStringAppender appender = (Log4jStringAppender) jobMap.getAppender(jobName); if (appender != null) { // The log can be quite large at times, we are going to put a base64 encoding around a compressed stream // of bytes to handle this one. ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(appender.getBuffer().toString().getBytes()); gzos.close(); String loggingString = new String(Base64.encodeBase64(baos.toByteArray())); jobStatus.setLoggingString(loggingString); } // Also set the result object... // jobStatus.setResult(job.getResult()); // might be null out.println(jobStatus.getXML()); } else { response.setContentType("text/html"); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>" + Messages.getString("GetJobStatusServlet.KettleJobStatus") + "</TITLE>"); out.println("<META http-equiv=\"Refresh\" content=\"10;url=/kettle/jobStatus?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>" + Messages.getString("GetJobStatusServlet.JobStatus") + "</H1>"); try { out.println("<table border=\"1\">"); out.print("<tr> <th>" + Messages.getString("GetJobStatusServlet.Jobname") + "</th> <th>" + Messages.getString("TransStatusServlet.TransStatus") + "</th> </tr>"); out.print("<tr>"); out.print("<td>" + jobName + "</td>"); out.print("<td>" + status + "</td>"); out.print("</tr>"); out.print("</table>"); out.print("<p>"); if (job.isFinished()) { out.print("<a href=\"/kettle/startJob?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">" + Messages.getString("GetJobStatusServlet.StartJob") + "</a>"); out.print("<p>"); } else { out.print("<a href=\"/kettle/stopJob?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">" + Messages.getString("GetJobStatusServlet.StopJob") + "</a>"); out.print("<p>"); } out.println("<p>"); out.print("<a href=\"/kettle/jobStatus/?name=" + URLEncoder.encode(jobName, "UTF-8") + "&xml=y\">" + Messages.getString("TransStatusServlet.ShowAsXml") + "</a><br>"); out.print("<a href=\"/kettle/status\">" + Messages.getString("TransStatusServlet.BackToStatusPage") + "</a><br>"); out.print("<p><a href=\"/kettle/jobStatus?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">" + Messages.getString("TransStatusServlet.Refresh") + "</a>"); // Put the logging below that. Log4jStringAppender appender = (Log4jStringAppender) jobMap.getAppender(jobName); if (appender != null) { out.println("<p>"); /* out.println("<pre>"); out.println(appender.getBuffer().toString()); out.println("</pre>"); */ out.println( "<textarea id=\"joblog\" cols=\"120\" rows=\"20\" wrap=\"off\" name=\"Job log\" readonly=\"readonly\">" + appender.getBuffer().toString() + "</textarea>"); out.println("<script type=\"text/javascript\"> "); out.println(" joblog.scrollTop=joblog.scrollHeight; "); out.println("</script> "); out.println("<p>"); } } catch (Exception ex) { out.println("<p>"); out.println("<pre>"); ex.printStackTrace(out); out.println("</pre>"); } out.println("<p>"); out.println("</BODY>"); out.println("</HTML>"); } } else { if (useXML) { out.println(new WebResult(WebResult.STRING_ERROR, Messages.getString("StartJobServlet.Log.SpecifiedJobNotFound", jobName))); } else { out.println("<H1>Job '" + jobName + "' could not be found.</H1>"); out.println("<a href=\"/kettle/status\">" + Messages.getString("TransStatusServlet.BackToStatusPage") + "</a><p>"); } } }
From source file:com.splicemachine.derby.stream.control.output.ControlExportDataSetWriter.java
@Override public DataSet<LocatedRow> write() throws StandardException { Integer count;/*from w ww . java2 s .c o m*/ String extension = ".csv"; SpliceOperation operation = exportFunction.getOperation(); boolean isCompressed = path.endsWith(".gz"); if (!isCompressed && operation instanceof ExportOperation) { ExportOperation op = (ExportOperation) exportFunction.getOperation(); isCompressed = op.getExportParams().isCompression(); if (isCompressed) { extension += ".gz"; } } try { final DistributedFileSystem dfs = SIDriver.driver().fileSystem(); dfs.createDirectory(path, false); // The 'part-r-00000' naming convention is what spark uses so we are consistent on control side try (OutputStream fileOut = dfs.newOutputStream(path /*directory*/, "part-r-00000" + extension/*file*/, StandardOpenOption.CREATE)) { OutputStream toWrite = fileOut; if (isCompressed) { toWrite = new GZIPOutputStream(fileOut); } count = exportFunction.call(toWrite, dataSet.toLocalIterator()); } dfs.touchFile(path, ExportFile.SUCCESS_FILE); } catch (Exception e) { throw new RuntimeException(e); } ValueRow valueRow = new ValueRow(2); valueRow.setColumn(1, new SQLLongint(count)); valueRow.setColumn(2, new SQLInteger(0)); return new ControlDataSet<>(new SingletonIterator(new LocatedRow(valueRow))); }
From source file:com.rapleaf.hank.storage.HdfsPartitionRemoteFileOps.java
@Override public OutputStream getOutputStream(String remoteRelativePath) throws IOException { OutputStream outputStream = fs.create(new Path(getAbsoluteRemotePath(remoteRelativePath)), false); if (compressionCodec == null) { return outputStream; } else {// w ww . j a v a2 s . c o m switch (compressionCodec) { case GZIP: return new GZIPOutputStream(outputStream); default: throw new RuntimeException("Compression codec not supported: " + compressionCodec); } } }
From source file:ch.ledcom.jpreseed.web.JPreseedController.java
@RequestMapping(value = "/", method = RequestMethod.POST, produces = GZIP) public void createUsbImage(@RequestParam("distro") String distro, @RequestParam("version") String version, @RequestParam("preseeds") List<MultipartFile> preseeds, @RequestParam("syslinux") MultipartFile syslinux, HttpServletResponse response, OutputStream out) throws IOException { URI imageUri = distroService.getDistributionByName(distro).getVersionByShortName(version).getUsbImageUri(); try (TemporaryPreseedStore preseedStore = new TemporaryPreseedStore(); Downloader srcBootImgGz = downloaderFactory.getDownloader(imageUri); GZIPOutputStream targetBootImgGz = new GZIPOutputStream(out)) { logger.debug("Storing preseeds..."); preseedStore.addPreseeds(preseeds); logger.debug("Preparing response..."); response.setHeader(CONTENT_DISPOSITION, "attachment; filename=\"boot.img.gz\""); logger.debug("Creating USB image ..."); usbCreator.create(srcBootImgGz.getContent(), targetBootImgGz, wrap(syslinux.getBytes()), preseedStore.getPreseeds()); logger.debug("USB image created."); }/*www .j a v a2 s.co m*/ }
From source file:org.calrissian.accumulorecipes.blobstore.impl.AccumuloBlobStoreTest.java
@Test public void testSaveAndQueryComplex() throws Exception { AccumuloBlobStore blobStore = new AccumuloBlobStore(getConnector(), CHUNK_SIZE); Collection<String> testValues = new ArrayList<String>(10); for (int i = 0; i < CHUNK_SIZE; i++) testValues.add(randomUUID().toString()); //Store json in a Gzipped format OutputStream storageStream = blobStore.store("test", "1", currentTimeMillis(), ""); mapper.writeValue(new GZIPOutputStream(storageStream), testValues); //reassemble the json after unzipping the stream. InputStream retrievalStream = blobStore.get("test", "1", Auths.EMPTY); Collection<String> actualValues = mapper.readValue(new GZIPInputStream(retrievalStream), strColRef); //if there were no errors, then verify that the two collections are equal. assertThat(actualValues, is(equalTo(testValues))); }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VepAnnotationGeneratorStep.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { ObjectMap pipelineOptions = jobOptions.getPipelineOptions(); ProcessBuilder processBuilder = new ProcessBuilder("perl", pipelineOptions.getString("app.vep.path"), "--cache", "--cache_version", pipelineOptions.getString("app.vep.cache.version"), "-dir", pipelineOptions.getString("app.vep.cache.path"), "--species", pipelineOptions.getString("app.vep.cache.species"), "--fasta", pipelineOptions.getString("input.fasta"), "--fork", pipelineOptions.getString("app.vep.num-forks"), "-i", pipelineOptions.getString("vep.input"), "-o", "STDOUT", "--force_overwrite", "--offline", "--everything"); logger.debug("VEP annotation parameters = " + Arrays.toString(processBuilder.command().toArray())); logger.info("Starting read from VEP output"); Process process = processBuilder.start(); long written = connectStreams(new BufferedInputStream(process.getInputStream()), new GZIPOutputStream(new FileOutputStream(pipelineOptions.getString("vep.output")))); int exitValue = process.waitFor(); logger.info("Finishing read from VEP output, bytes written: " + written); if (exitValue > 0) { String errorLog = pipelineOptions.getString("vep.output") + ".errors.txt"; connectStreams(new BufferedInputStream(process.getErrorStream()), new FileOutputStream(errorLog)); throw new Exception("Error while running VEP (exit status " + exitValue + "). See " + errorLog + " for the errors description from VEP."); }//from w w w . j a v a 2s . c o m return RepeatStatus.FINISHED; }
From source file:cn.keke.travelmix.publictransport.JsonProxyRouter.java
public void handle(HttpExchange xchg) throws IOException { try {/*from w w w . ja v a 2 s . c om*/ StringBuffer response = new StringBuffer(4096); String query = xchg.getRequestURI().getRawQuery(); String callbackMethod = HttpClientHelper.parseQueryMap(query).get("callback"); response.append(callbackMethod).append("("); LOG.info(query); if (StringUtils.isNotEmpty(query)) { RoutingJob job = createRoutingJob(query); if (job != null) { RoutingTask task = null; Header[] headers = convertRequestHeaders(xchg.getRequestHeaders()); List<Future<String>> futures = new ArrayList<Future<String>>(Provider.values().length); while ((task = job.pop()) != null) { task.setHeaders(headers); task.setResponse(response); futures.add(ExecutorUtils.THREAD_POOL.submit(task)); } for (Future<String> future : futures) { if (job.isHandled()) { System.out.println("Finished: " + job); break; } else { future.get(); } } } } response.append(");"); xchg.getResponseHeaders().set("Content-Encoding", "gzip"); xchg.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0); GZIPOutputStream os = new GZIPOutputStream(xchg.getResponseBody()); LOG.info(response.toString()); os.write(response.toString().getBytes()); os.finish(); xchg.close(); } catch (Exception e) { LOG.warn("Json Routing Request failed", e); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.ArchiveCompressorTarGzImpl.java
/** * Compress the given files into an archive with the given name, plus the file extension. Put the compressed * archive into the given directory. (So if you pass in /test/ as the destinationDirectory and 'anArchive' as * the archiveName, the compressed archives will be /test/anArchive.tar.gz) * * @param files the files to include in the archive * @param archiveName the name of the archive, minus extension * @param destinationDirectory the location to put the new compressed archive * @param compress flag to compress the archive * @return the File representing the created compressed archive * @throws IOException if it needs to//from w ww. j a v a 2s . co m */ public File createArchive(final List<File> files, final String archiveName, final File destinationDirectory, final Boolean compress) throws IOException { File archive = null; TarOutputStream tarOutputStream = null; FileInputStream in = null; GZIPOutputStream gzipOutputStream = null; try { // first make a tar archive with all the given files final File tarFile = new File(destinationDirectory, archiveName + TAR_EXTENSION); //noinspection IOResourceOpenedButNotSafelyClosed tarOutputStream = new TarOutputStream(new FileOutputStream(tarFile)); tarOutputStream.setLongFileMode(TarOutputStream.LONGFILE_GNU); final byte[] buf = new byte[1024]; for (final File file : files) { try { //noinspection IOResourceOpenedButNotSafelyClosed in = new FileInputStream(file); // name of entry should be archiveName/fileName final TarEntry tarEntry = new TarEntry(file); tarEntry.setName(archiveName + File.separator + file.getName()); tarOutputStream.putNextEntry(tarEntry); int len; while ((len = in.read(buf)) > 0) { tarOutputStream.write(buf, 0, len); } tarOutputStream.closeEntry(); in.close(); } finally { IOUtils.closeQuietly(in); } } tarOutputStream.close(); if (compress) { final File outputFile = new File(destinationDirectory, archiveName + TAR_GZIP_EXTENSION); // then compress it using gzip //noinspection IOResourceOpenedButNotSafelyClosed gzipOutputStream = new GZIPOutputStream(new FileOutputStream(outputFile)); //noinspection IOResourceOpenedButNotSafelyClosed in = new FileInputStream(tarFile); int len; while ((len = in.read(buf)) > 0) { gzipOutputStream.write(buf, 0, len); } // this was a temp file so delete it //noinspection ResultOfMethodCallIgnored tarFile.delete(); archive = outputFile; } else { archive = tarFile; } } finally { IOUtils.closeQuietly(tarOutputStream); IOUtils.closeQuietly(in); IOUtils.closeQuietly(gzipOutputStream); } return archive; }