List of usage examples for java.util.zip GZIPOutputStream write
public void write(int b) throws IOException
From source file:de.dentrassi.pm.deb.aspect.internal.RepoBuilder.java
private byte[] compressGzip(final byte[] data) throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(data); gos.close();/* ww w . j ava 2s . c o m*/ return bos.toByteArray(); }
From source file:org.jabsorb.ng.JSONRPCServlet.java
/** * Gzip something.//from w ww. ja va 2s. c o m * * @param in * original content * @return size gzipped content */ private byte[] gzip(final byte[] in) { if (in != null && in.length > 0) { long tstart = System.currentTimeMillis(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { GZIPOutputStream gout = new GZIPOutputStream(bout); gout.write(in); gout.flush(); gout.close(); if (log.isDebugEnabled()) { log.debug("gzip", "gzipping took " + (System.currentTimeMillis() - tstart) + " msec"); } return bout.toByteArray(); } catch (IOException io) { log.error("gzip", "io exception gzipping byte array", io); } } return new byte[0]; }
From source file:edu.umd.cs.marmoset.modelClasses.TestOutcome.java
public static byte[] compress(String txt) { byte[] rawBYtes = txt.getBytes(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/*ww w . ja v a2 s .c o m*/ GZIPOutputStream gzout = new GZIPOutputStream(out); gzout.write(rawBYtes); gzout.close(); } catch (IOException e) { e.printStackTrace(); return rawBYtes; } return out.toByteArray(); }
From source file:org.rhq.enterprise.server.plugins.rhnhosted.RHNHelper.java
private byte[] gzip(byte[] input) throws IOException { ByteArrayOutputStream zipped = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(zipped); try {/*from w w w .j av a 2 s . c o m*/ gzip.write(input); } finally { gzip.close(); } return zipped.toByteArray(); }
From source file:org.example.Serializer.java
private byte[] zip(byte[] serialized) throws Exception { ByteArrayOutputStream zipBaos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(zipBaos); gzos.write(serialized); gzos.close();//from w w w . j av a 2s . c o m return zipBaos.toByteArray(); }
From source file:net.sf.ehcache.constructs.web.PageInfoTest.java
/** * Create gzip file in tmp//from w ww .j av a2 s .c o m * * @throws Exception */ protected void setUp() throws Exception { String testGzipFile = System.getProperty("java.io.tmpdir") + File.separator + "test.gzip"; testFile = new File(testGzipFile); FileOutputStream fout = new FileOutputStream(testFile); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(fout); for (int j = 0; j < 100; j++) { for (int i = 0; i < 1000; i++) { gzipOutputStream.write(i); } } gzipOutputStream.close(); }
From source file:org.pentaho.di.www.GetTransStatusServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) { return;/* ww w . j av a 2s. c o m*/ } if (log.isDebug()) logDebug(BaseMessages.getString(PKG, "TransStatusServlet.Log.TransStatusRequested")); String transName = request.getParameter("name"); String id = request.getParameter("id"); boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml")); int startLineNr = Const.toInt(request.getParameter("from"), 0); response.setStatus(HttpServletResponse.SC_OK); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); } else { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); } PrintWriter out = response.getWriter(); // ID is optional... // Trans trans; CarteObjectEntry entry; if (Const.isEmpty(id)) { // get the first transformation that matches... // entry = getTransformationMap().getFirstCarteObjectEntry(transName); if (entry == null) { trans = null; } else { id = entry.getId(); trans = getTransformationMap().getTransformation(entry); } } else { // Take the ID into account! // entry = new CarteObjectEntry(transName, id); trans = getTransformationMap().getTransformation(entry); } if (trans != null) { String status = trans.getStatus(); int lastLineNr = CentralLogStore.getLastBufferLineNr(); String logText = CentralLogStore.getAppender() .getBuffer(trans.getLogChannel().getLogChannelId(), false, startLineNr, lastLineNr).toString(); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING)); SlaveServerTransStatus transStatus = new SlaveServerTransStatus(transName, entry.getId(), status); transStatus.setFirstLoggingLineNr(startLineNr); transStatus.setLastLoggingLineNr(lastLineNr); for (int i = 0; i < trans.nrSteps(); i++) { StepInterface baseStep = trans.getRunThread(i); if ((baseStep.isRunning()) || baseStep.getStatus() != StepExecutionStatus.STATUS_EMPTY) { StepStatus stepStatus = new StepStatus(baseStep); transStatus.getStepStatusList().add(stepStatus); } } // 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(logText.getBytes()); gzos.close(); String loggingString = new String(Base64.encodeBase64(baos.toByteArray())); transStatus.setLoggingString(loggingString); // Also set the result object... // transStatus.setResult(trans.getResult()); // Is the transformation paused? // transStatus.setPaused(trans.isPaused()); // Send the result back as XML // try { out.println(transStatus.getXML()); } catch (KettleException e) { throw new ServletException("Unable to get the transformation status in XML format", e); } } else { response.setContentType("text/html;charset=UTF-8"); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>" + BaseMessages.getString(PKG, "TransStatusServlet.KettleTransStatus") + "</TITLE>"); out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">"); out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>" + BaseMessages.getString(PKG, "TransStatusServlet.TopTransStatus", transName) + "</H1>"); try { out.println("<table border=\"1\">"); out.print("<tr> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.TransName") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.CarteObjectId") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.TransStatus") + "</th> </tr>"); out.print("<tr>"); out.print("<td>" + transName + "</td>"); out.print("<td>" + id + "</td>"); out.print("<td>" + status + "</td>"); out.print("</tr>"); out.print("</table>"); out.print("<p>"); if ((trans.isFinished() && trans.isRunning()) || (!trans.isRunning() && !trans.isPreparing() && !trans.isInitializing())) { out.print("<a href=\"" + convertContextPath(StartTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.StartTrans") + "</a>"); out.print("<p>"); out.print("<a href=\"" + convertContextPath(PrepareExecutionTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.PrepareTrans") + "</a><br>"); } else if (trans.isRunning()) { out.print("<a href=\"" + convertContextPath(PauseTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "PauseStatusServlet.PauseResumeTrans") + "</a><br>"); out.print("<a href=\"" + convertContextPath(StopTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.StopTrans") + "</a>"); out.print("<p>"); } out.print("<a href=\"" + convertContextPath(CleanupTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.CleanupTrans") + "</a>"); out.print("<p>"); out.println("<table border=\"1\">"); out.print("<tr> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Stepname") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.CopyNr") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Read") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Written") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Input") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Output") + "</th> " + "<th>" + BaseMessages.getString(PKG, "TransStatusServlet.Updated") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Rejected") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Errors") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Active") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Time") + "</th> " + "<th>" + BaseMessages.getString(PKG, "TransStatusServlet.Speed") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.prinout") + "</th> </tr>"); for (int i = 0; i < trans.nrSteps(); i++) { StepInterface step = trans.getRunThread(i); if ((step.isRunning()) || step.getStatus() != StepExecutionStatus.STATUS_EMPTY) { StepStatus stepStatus = new StepStatus(step); if (step.isRunning() && !step.isStopped() && !step.isPaused()) { String sniffLink = " <a href=\"" + convertContextPath(SniffStepServlet.CONTEXT_PATH) + "?trans=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "&lines=50" + "©nr=" + step.getCopy() + "&type=" + SniffStepServlet.TYPE_OUTPUT + "&step=" + URLEncoder.encode(step.getStepname(), "UTF-8") + "\">" + stepStatus.getStepname() + "</a>"; stepStatus.setStepname(sniffLink); } out.print(stepStatus.getHTMLTableRow()); } } out.println("</table>"); out.println("<p>"); out.print("<a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "&xml=y\">" + BaseMessages.getString(PKG, "TransStatusServlet.ShowAsXml") + "</a><br>"); out.print("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><br>"); out.print("<p><a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.Refresh") + "</a>"); // Put the logging below that. out.println("<p>"); out.println( "<textarea id=\"translog\" cols=\"120\" rows=\"20\" wrap=\"off\" name=\"Transformation log\" readonly=\"readonly\">" + logText + "</textarea>"); out.println("<script type=\"text/javascript\"> "); out.println(" translog.scrollTop=translog.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, BaseMessages.getString(PKG, "TransStatusServlet.Log.CoundNotFindSpecTrans", transName))); } else { out.println( "<H1>" + BaseMessages.getString(PKG, "TransStatusServlet.Log.CoundNotFindTrans", transName) + "</H1>"); out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>"); } } }
From source file:com.nokia.helium.core.EmailDataSender.java
/** * GZipping a string./*from w w w. j av a2 s . c om*/ * * @param data the content to be gzipped. * @param filename the name for the file. * @return a ByteArrayDataSource. */ protected ByteArrayDataSource compressFile(File fileName) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gz = new GZIPOutputStream(out); BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(fileName)); byte[] dataBuffer = new byte[512]; while ((bufferedInputStream.read(dataBuffer)) != -1) { gz.write(dataBuffer); } gz.close(); bufferedInputStream.close(); ByteArrayDataSource dataSrc = new ByteArrayDataSource(out.toByteArray(), "application/x-gzip"); return dataSrc; }
From source file:org.apache.pig.test.TestCompressedFiles.java
@Override @Before// w w w. j a v a 2s .co m protected void setUp() throws Exception { datFile = File.createTempFile("compTest", ".dat"); gzFile = File.createTempFile("compTest", ".gz"); FileOutputStream dat = new FileOutputStream(datFile); GZIPOutputStream gz = new GZIPOutputStream(new FileOutputStream(gzFile)); Random rand = new Random(); for (int i = 0; i < 1024; i++) { StringBuffer sb = new StringBuffer(); int x = rand.nextInt(); int y = rand.nextInt(); sb.append(x); sb.append('\t'); sb.append(y); sb.append('\n'); byte bytes[] = sb.toString().getBytes(); dat.write(bytes); gz.write(bytes); } dat.close(); gz.close(); }
From source file:com.kloudtek.buildmagic.tools.createinstaller.deb.CreateDebTask.java
private void prepare() throws IOException { // validate parameters if (name == null || name.trim().length() == 0) { throw new BuildException("name attribute is missing or invalid"); }//from w w w . j a v a2 s . c om if (version == null || version.trim().length() == 0) { throw new BuildException("version attribute is missing or invalid"); } if (arch == null || arch.trim().length() == 0) { throw new BuildException("arch attribute is missing or invalid"); } if (maintName == null || maintName.trim().length() == 0) { throw new BuildException("maintName attribute is missing"); } if (maintEmail == null || maintEmail.trim().length() == 0) { throw new BuildException("maintEmail attribute is missing"); } if (priority != null && !PRIORITIES.contains(priority.toLowerCase())) { log("Priority '" + priority + "' isn't recognized as a valid value", Project.MSG_WARN); } if (control != null) { for (final TemplateEntry entry : control.getTemplateEntries()) { if (entry.getPackageName() == null) { entry.setPackageName(name); } templateEntries.add(entry); } } // generate copyright file if (copyrights.isEmpty()) { if (license == null) { throw new BuildException("No license has been specified"); } if (licenseFile == null) { licenseFile = new File("license.txt"); } copyrights.add(new Copyright(license, licenseFile)); } copyrights.validate(); copyright = dataBufferManager.createBuffer(); copyrights.write(copyright, this); // generate changelog changelog = new Changelog(name); Changelog.Entry entry = changelog.createEntry(); changelog.setDistributions("main"); // TODO entry.setMaintName(maintName); entry.setMaintEmail(maintEmail); entry.setChanges("Released"); entry.setVersion(version); entry.setDate(new Date()); changelog.validate(); changelogData = changelog.export(Changelog.Type.DEBIAN); ByteArrayOutputStream changelogBuf = new ByteArrayOutputStream(); GZIPOutputStream changelogGzipBuf = new GZIPOutputStream(changelogBuf); changelogGzipBuf.write(changelogData.getBytes()); changelogGzipBuf.finish(); changelogGzipBuf.close(); changelogDataGzipped = changelogBuf.toByteArray(); }