List of usage examples for java.util.zip GZIPOutputStream close
public void close() throws IOException
From source file:io.aino.agents.core.Sender.java
private byte[] getRequestContent() { if (!agentConfig.isGzipEnabled()) { return stringToSend.getBytes(); }//w ww. j a va 2s. c om try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzipStream = new GZIPOutputStream(baos); gzipStream.write(stringToSend.getBytes()); gzipStream.finish(); baos.flush(); byte[] returnBytes = baos.toByteArray(); baos.close(); gzipStream.close(); return returnBytes; } catch (IOException e) { throw new AgentCoreException("Failed to compress Aino log message using gzip."); } }
From source file:com.github.abilityapi.abilityapi.external.Metrics.java
/** * Gzips the given String.//from w w w.ja va 2 s. c o m * * @param str The string to gzip. * @return The gzipped String. * @throws IOException If the compression failed. */ private static byte[] compress(final String str) throws IOException { if (str == null) { return null; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(outputStream); gzip.write(str.getBytes("UTF-8")); gzip.close(); return outputStream.toByteArray(); }
From source file:de.schildbach.wallet.ui.TransactionFragment.java
public void update(final Transaction tx) { final Wallet wallet = ((WalletApplication) activity.getApplication()).getWallet(); final byte[] serializedTx = tx.unsafeBitcoinSerialize(); Address from = null;// w ww .ja v a 2 s . co m boolean fromMine = false; try { from = tx.getInputs().get(0).getFromAddress(); fromMine = wallet.isPubKeyHashMine(from.getHash160()); } catch (final ScriptException x) { x.printStackTrace(); } Address to = null; boolean toMine = false; try { to = tx.getOutputs().get(0).getScriptPubKey().getToAddress(); toMine = wallet.isPubKeyHashMine(to.getHash160()); } catch (final ScriptException x) { x.printStackTrace(); } final ContentResolver contentResolver = activity.getContentResolver(); final View view = getView(); final Date time = tx.getUpdateTime(); view.findViewById(R.id.transaction_fragment_time_row) .setVisibility(time != null ? View.VISIBLE : View.GONE); if (time != null) { final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time); viewDate.setText( (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time)); } try { final BigInteger amountSent = tx.getValueSentFromMe(wallet); view.findViewById(R.id.transaction_fragment_amount_sent_row) .setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE); if (amountSent.signum() != 0) { final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent); viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + WalletUtils.formatValue(amountSent)); } } catch (final ScriptException x) { x.printStackTrace(); } final BigInteger amountReceived = tx.getValueSentToMe(wallet); view.findViewById(R.id.transaction_fragment_amount_received_row) .setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE); if (amountReceived.signum() != 0) { final TextView viewAmountReceived = (TextView) view .findViewById(R.id.transaction_fragment_amount_received); viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + WalletUtils.formatValue(amountReceived)); } final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button); final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label); if (from != null) { final String label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (fromMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(from.toString()); viewFromLabel.setTypeface(Typeface.MONOSPACE); } viewFromLabel.setText(builder.toString()); final String addressStr = from.toString(); viewFromButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewFromLabel.setText(null); } final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button); final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label); if (to != null) { final String label = AddressBookProvider.resolveLabel(contentResolver, to.toString()); final StringBuilder builder = new StringBuilder(); if (toMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(to.toString()); viewToLabel.setTypeface(Typeface.MONOSPACE); } viewToLabel.setText(builder.toString()); final String addressStr = to.toString(); viewToButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewToLabel.setText(null); } final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status); final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType(); if (confidenceType == ConfidenceType.DEAD || confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_dead); else if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_pending); else if (confidenceType == ConfidenceType.BUILDING) viewStatus.setText(R.string.transaction_fragment_status_confirmed); else viewStatus.setText(R.string.transaction_fragment_status_unknown); final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash); viewHash.setText(tx.getHash().toString()); final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length); viewLength.setText(Integer.toString(serializedTx.length)); final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr); try { // encode transaction URI final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(serializedTx); gos.close(); final byte[] gzippedSerializedTx = bos.toByteArray(); final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length; final StringBuilder txStr = new StringBuilder("btctx:"); txStr.append(useCompressioon ? 'Z' : '-'); txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx)); final Bitmap qrCodeBitmap = WalletUtils.getQRCodeBitmap(txStr.toString().toUpperCase(Locale.US), 512); viewQr.setImageBitmap(qrCodeBitmap); viewQr.setOnClickListener(new OnClickListener() { public void onClick(final View v) { BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); } catch (final IOException x) { throw new RuntimeException(x); } }
From source file:com.rest4j.impl.ApiResponseImpl.java
@Override public void outputBody(HttpServletResponse response) throws IOException { if (statusMessage == null) response.setStatus(status);/*from www. j a v a 2 s . c o m*/ else response.setStatus(status, statusMessage); headers.outputHeaders(response); if (this.response == null) return; response.addHeader("Content-type", this.response.getContentType()); if (addEtag) { String etag = this.response.getETag(); if (etag != null) response.addHeader("ETag", etag); } OutputStream outputStream; byte[] resourceBytes = ((JSONResource) this.response).getJSONObject().toString().getBytes(); int contentLength = resourceBytes.length; if (compress) { response.addHeader("Content-encoding", "gzip"); ByteArrayOutputStream outputByteStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputByteStream); gzipOutputStream.write(resourceBytes); gzipOutputStream.finish(); // ??! contentLength = outputByteStream.toByteArray().length; gzipOutputStream.close(); outputByteStream.close(); outputStream = new GZIPOutputStream(response.getOutputStream()); } else { outputStream = response.getOutputStream(); } response.addHeader("Content-Length", String.valueOf(contentLength)); if (this.response instanceof JSONResource) { ((JSONResource) this.response).setPrettify(prettify); } if (callbackFunctionName == null) { this.response.write(outputStream); } else { this.response.writeJSONP(outputStream, callbackFunctionName); } outputStream.close(); }
From source file:org.pentaho.di.www.GetJobStatusServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) { return;//from www .j a v a2 s. c o m } if (log.isDebug()) logDebug(BaseMessages.getString(PKG, "GetJobStatusServlet.Log.JobStatusRequested")); String jobName = 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.setContentType("text/html;charset=UTF-8"); } PrintWriter out = response.getWriter(); // ID is optional... // Job job; CarteObjectEntry entry; if (Const.isEmpty(id)) { // get the first job that matches... // entry = getJobMap().getFirstCarteObjectEntry(jobName); if (entry == null) { job = null; } else { id = entry.getId(); job = getJobMap().getJob(entry); } } else { // Take the ID into account! // entry = new CarteObjectEntry(jobName, id); job = getJobMap().getJob(entry); } if (job != null) { String status = job.getStatus(); int lastLineNr = CentralLogStore.getLastBufferLineNr(); String logText = CentralLogStore.getAppender() .getBuffer(job.getLogChannel().getLogChannelId(), false, startLineNr, lastLineNr).toString(); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING)); SlaveServerJobStatus jobStatus = new SlaveServerJobStatus(jobName, id, status); jobStatus.setFirstLoggingLineNr(startLineNr); jobStatus.setLastLoggingLineNr(lastLineNr); // 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())); jobStatus.setLoggingString(loggingString); // Also set the result object... // jobStatus.setResult(job.getResult()); // might be null try { out.println(jobStatus.getXML()); } catch (KettleException e) { throw new ServletException("Unable to get the job status in XML format", e); } } else { response.setContentType("text/html"); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>" + BaseMessages.getString(PKG, "GetJobStatusServlet.KettleJobStatus") + "</TITLE>"); out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "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, "GetJobStatusServlet.JobStatus") + "</H1>"); try { out.println("<table border=\"1\">"); out.print("<tr> <th>" + BaseMessages.getString(PKG, "GetJobStatusServlet.Jobname") + "</th> <th>" + BaseMessages.getString(PKG, "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=\"" + convertContextPath(StartJobServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "GetJobStatusServlet.StartJob") + "</a>"); out.print("<p>"); } else { out.print("<a href=\"" + convertContextPath(StopJobServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "GetJobStatusServlet.StopJob") + "</a>"); out.print("<p>"); } out.println("<p>"); out.print("<a href=\"" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&xml=y&id=" + id + "\">" + 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(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + id + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.Refresh") + "</a>"); // Put the logging below that. out.println("<p>"); out.println( "<textarea id=\"joblog\" cols=\"120\" rows=\"20\" wrap=\"off\" name=\"Job log\" readonly=\"readonly\">" + logText + "</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, BaseMessages.getString(PKG, "StartJobServlet.Log.SpecifiedJobNotFound", jobName, id))); } else { out.println("<H1>Job '" + jobName + "' could not be found.</H1>"); out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>"); } } }
From source file:org.hyperic.hq.bizapp.server.session.UpdateBossImpl.java
/** * Meant to be called internally by the fetching thread * //from w ww. j ava2s .c om * */ public void fetchReport() { final boolean debug = log.isDebugEnabled(); final StopWatch watch = new StopWatch(); UpdateStatus status = getOrCreateStatus(); Properties req; byte[] reqBytes; if (status.getMode().equals(UpdateStatusMode.NONE)) { return; } req = getRequestInfo(status); try { ByteArrayOutputStream bOs = new ByteArrayOutputStream(); GZIPOutputStream gOs = new GZIPOutputStream(bOs); req.store(gOs, ""); gOs.flush(); gOs.close(); bOs.flush(); bOs.close(); reqBytes = bOs.toByteArray(); } catch (IOException e) { log.warn("Error creating report request", e); return; } if (debug) { log.debug("Generated report. Size=" + reqBytes.length + " report:\n" + req); } try { HttpConfig config = new HttpConfig(HTTP_TIMEOUT_MILLIS, HTTP_TIMEOUT_MILLIS, null, -1); HQHttpClient client = new HQHttpClient(keystoreConf, config, acceptUnverifiedCertificates); HttpPost post = new HttpPost(updateNotifyUrl); post.addHeader("x-hq-guid", req.getProperty("hq.guid")); ByteArrayInputStream bIs = new ByteArrayInputStream(reqBytes); HttpEntity entity = new InputStreamEntity(bIs, reqBytes.length); post.setEntity(entity); if (debug) watch.markTimeBegin("post"); HttpResponse response = client.execute(post); if (debug) watch.markTimeEnd("post"); if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { processReport(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8")); } else { if (debug) { log.debug("fetchReport: " + watch + ", currentReport {" + status.getReport() + "}, latestReport {url=" + updateNotifyUrl + ", statusCode=" + response.getStatusLine().getStatusCode() + ", response=" + EntityUtils.toString(response.getEntity(), "UTF-8") + "}"); } } } catch (ClientProtocolException e) { log.error(e); } catch (IOException e) { log.error(e); } }
From source file:piuk.blockchain.android.ui.TransactionFragment.java
public void update(final MyTransaction tx) { final MyRemoteWallet wallet = ((WalletApplication) activity.getApplication()).getRemoteWallet(); final byte[] serializedTx = tx.unsafeBitcoinSerialize(); Address from = null;/*from w w w . jav a 2 s . co m*/ boolean fromMine = false; try { from = tx.getInputs().get(0).getFromAddress(); fromMine = wallet.isMine(from.toString()); } catch (final ScriptException x) { x.printStackTrace(); } Address to = null; boolean toMine = false; try { to = tx.getOutputs().get(0).getScriptPubKey().getToAddress(); toMine = wallet.isMine(to.toString()); } catch (final ScriptException x) { x.printStackTrace(); } final ContentResolver contentResolver = activity.getContentResolver(); final View view = getView(); final Date time = tx.getUpdateTime(); view.findViewById(R.id.transaction_fragment_time_row) .setVisibility(time != null ? View.VISIBLE : View.GONE); if (time != null) { final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time); viewDate.setText( (DateUtils.isToday(time.getTime()) ? getString(R.string.transaction_fragment_time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time)); } final BigInteger amountSent = tx.getResult(); view.findViewById(R.id.transaction_fragment_amount_sent_row) .setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE); if (amountSent.signum() != 0) { final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent); viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + WalletUtils.formatValue(amountSent)); } final BigInteger amountReceived = tx.getResult(); view.findViewById(R.id.transaction_fragment_amount_received_row) .setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE); if (amountReceived.signum() != 0) { final TextView viewAmountReceived = (TextView) view .findViewById(R.id.transaction_fragment_amount_received); viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + WalletUtils.formatValue(amountReceived)); } final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button); final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label); if (from != null) { String label = null; if (tx instanceof MyTransaction && ((MyTransaction) tx).getTag() != null) label = ((MyTransaction) tx).getTag(); else label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (fromMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(from.toString()); viewFromLabel.setTypeface(Typeface.MONOSPACE); } viewFromLabel.setText(builder.toString()); final String addressStr = from.toString(); viewFromButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewFromLabel.setText(null); } final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button); final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label); if (to != null) { String label = null; if (tx instanceof MyTransaction && ((MyTransaction) tx).getTag() != null) label = ((MyTransaction) tx).getTag(); else label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (toMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(to.toString()); viewToLabel.setTypeface(Typeface.MONOSPACE); } viewToLabel.setText(builder.toString()); final String addressStr = to.toString(); viewToButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewToLabel.setText(null); } final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status); final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType(); if (confidenceType == ConfidenceType.DEAD || confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_dead); else if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_pending); else if (confidenceType == ConfidenceType.BUILDING) viewStatus.setText(R.string.transaction_fragment_status_confirmed); else viewStatus.setText(R.string.transaction_fragment_status_unknown); final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash); viewHash.setText(tx.getHash().toString()); final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length); viewLength.setText(Integer.toString(serializedTx.length)); final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr); try { // encode transaction URI final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(serializedTx); gos.close(); final byte[] gzippedSerializedTx = bos.toByteArray(); final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length; final StringBuilder txStr = new StringBuilder("btctx:"); txStr.append(useCompressioon ? 'Z' : '-'); txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx)); final Bitmap qrCodeBitmap = WalletUtils.getQRCodeBitmap(txStr.toString().toUpperCase(), 512); viewQr.setImageBitmap(qrCodeBitmap); viewQr.setOnClickListener(new OnClickListener() { public void onClick(final View v) { new QrDialog(activity, qrCodeBitmap).show(); } }); } catch (final IOException x) { throw new RuntimeException(x); } }
From source file:org.wso2.carbon.logging.summarizer.scriptCreator.OutputFileHandler.java
public void compressLogFile(String temp) throws IOException { File file = new File(temp); FileOutputStream outputStream = new FileOutputStream(file + ".gz"); GZIPOutputStream gzos = new GZIPOutputStream(outputStream); FileInputStream inputStream = new FileInputStream(temp); BufferedInputStream in = new BufferedInputStream(inputStream); byte[] buffer = new byte[1024]; int i;// w w w. j a va 2 s . c o m while ((i = in.read(buffer)) >= 0) { gzos.write(buffer, 0, i); } in.close(); gzos.close(); }
From source file:org.xenei.bloomgraph.SerializableNode.java
/** * Create a serializable node from a node and limit the buffer size. If the * serialized node is a literal and exceeds the maximum buffer size the data * are compressed before writing and decompressed on reading. * // w w w . j a v a2 s . co m * @param n * the node to wrap. * @param maxBlob * The maximum buffer size. * @throws IOException * on error. */ public SerializableNode(Node n, int maxBlob) throws IOException { this.node = new SoftReference<Node>(n); if (n.equals(Node.ANY)) { fillBuffer(Node.ANY.hashCode(), _ANY, null); } else if (n.isVariable()) { fillBuffer(n.hashCode(), _VAR, encodeString(n.getName())); } else if (n.isURI()) { fillBuffer(n.hashCode(), _URI, encodeString(n.getURI())); } else if (n.isBlank()) { fillBuffer(n.hashCode(), _ANON, encodeString(n.getBlankNodeId().getLabelString())); } else if (n.isLiteral()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); write(os, n.getLiteralLexicalForm()); write(os, n.getLiteralLanguage()); write(os, n.getLiteralDatatypeURI()); os.close(); baos.close(); byte[] value = baos.toByteArray(); if (value.length > maxBlob) { baos = new ByteArrayOutputStream(); GZIPOutputStream dos = new GZIPOutputStream(baos); dos.write(value); dos.close(); fillBuffer(n.hashCode(), (byte) (_LIT | _COMPRESSED), baos.toByteArray()); } else { fillBuffer(n.hashCode(), _LIT, value); } } else { throw new IllegalArgumentException("Unknown node type " + n); } }
From source file:net.sf.ehcache.constructs.web.PageInfoTest.java
/** * @param ungzipped the bytes to be gzipped * @return gzipped bytes//from www .j a v a 2 s.c om */ private byte[] gzip(byte[] ungzipped) throws IOException { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bytes); gzipOutputStream.write(ungzipped); gzipOutputStream.close(); return bytes.toByteArray(); }