List of usage examples for java.util.zip Deflater BEST_SPEED
int BEST_SPEED
To view the source code for java.util.zip Deflater BEST_SPEED.
Click Source Link
From source file:org.apache.sling.reqanalyzer.impl.RequestAnalyzerWebConsole.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getRequestURI().endsWith(RAW_FILE_MARKER) || req.getRequestURI().endsWith(ZIP_FILE_MARKER)) { InputStream input = null; OutputStream output = null; try {//from w w w . j a v a 2s . com input = new FileInputStream(this.logFile); output = resp.getOutputStream(); if (req.getRequestURI().endsWith(ZIP_FILE_MARKER)) { ZipOutputStream zip = new ZipOutputStream(output); zip.setLevel(Deflater.BEST_SPEED); ZipEntry entry = new ZipEntry(this.logFile.getName()); entry.setTime(this.logFile.lastModified()); entry.setMethod(ZipEntry.DEFLATED); zip.putNextEntry(entry); output = zip; resp.setContentType("application/zip"); } else { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); resp.setHeader("Content-Length", String.valueOf(this.logFile.length())); // might be bigger than } resp.setDateHeader("Last-Modified", this.logFile.lastModified()); IOUtils.copy(input, output); } catch (IOException ioe) { throw new ServletException("Cannot create copy of log file", ioe); } finally { IOUtils.closeQuietly(input); if (output instanceof ZipOutputStream) { ((ZipOutputStream) output).closeEntry(); ((ZipOutputStream) output).finish(); } } resp.flushBuffer(); } else if (req.getRequestURI().endsWith(WINDOW_MARKER)) { if (canOpenSwingGui(req)) { showWindow(); } String target = req.getRequestURI(); target = target.substring(0, target.length() - WINDOW_MARKER.length()); resp.sendRedirect(target); resp.flushBuffer(); } else { super.service(req, resp); } }
From source file:com.thoughtworks.go.agent.UrlBasedArtifactsRepository.java
@Override public void upload(StreamConsumer console, File file, String destPath, String buildId) { if (!file.exists()) { String message = "Failed to find " + file.getAbsolutePath(); consumeLineWithPrefix(console, message); throw bomb(message); }/*from w w w . j a v a 2 s . c o m*/ int publishingAttempts = 0; Throwable lastException = null; while (publishingAttempts < PUBLISH_MAX_RETRIES) { File tmpDir = null; try { publishingAttempts++; tmpDir = FileUtil.createTempFolder(); File dataToUpload = new File(tmpDir, file.getName() + ".zip"); zipUtil.zip(file, dataToUpload, Deflater.BEST_SPEED); long size; if (file.isDirectory()) { size = FileUtils.sizeOfDirectory(file); } else { size = file.length(); } consumeLineWithPrefix(console, format("Uploading artifacts from %s to %s", file.getAbsolutePath(), getDestPath(destPath))); String normalizedDestPath = normalizePath(destPath); String url = getUploadUrl(buildId, normalizedDestPath, publishingAttempts); int statusCode = httpService.upload(url, size, dataToUpload, artifactChecksums(file, normalizedDestPath)); if (statusCode == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE) { String message = format( "Artifact upload for file %s (Size: %s) was denied by the server. This usually happens when server runs out of disk space.", file.getAbsolutePath(), size); consumeLineWithPrefix(console, message); LOGGER.error( "[Artifact Upload] Artifact upload was denied by the server. This usually happens when server runs out of disk space."); publishingAttempts = PUBLISH_MAX_RETRIES; throw bomb(message + ". HTTP return code is " + statusCode); } if (statusCode < HttpServletResponse.SC_OK || statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES) { throw bomb( "Failed to upload " + file.getAbsolutePath() + ". HTTP return code is " + statusCode); } return; } catch (Throwable e) { String message = "Failed to upload " + file.getAbsolutePath(); LOGGER.error(message, e); consumeLineWithPrefix(console, message); lastException = e; } finally { FileUtil.deleteFolder(tmpDir); } } if (lastException != null) { throw new RuntimeException(lastException); } }
From source file:com.thoughtworks.go.publishers.GoArtifactsManipulator.java
public void publish(DefaultGoPublisher goPublisher, String destPath, File source, JobIdentifier jobIdentifier) { if (!source.exists()) { String message = "Failed to find " + source.getAbsolutePath(); goPublisher.taggedConsumeLineWithPrefix(PUBLISH_ERR, message); bomb(message);/*from w w w. ja va 2 s . c o m*/ } int publishingAttempts = 0; Throwable lastException = null; while (publishingAttempts < PUBLISH_MAX_RETRIES) { File tmpDir = null; try { publishingAttempts++; tmpDir = FileUtil.createTempFolder(); File dataToUpload = new File(tmpDir, source.getName() + ".zip"); zipUtil.zip(source, dataToUpload, Deflater.BEST_SPEED); long size = 0; if (source.isDirectory()) { size = FileUtils.sizeOfDirectory(source); } else { size = source.length(); } goPublisher.taggedConsumeLineWithPrefix(PUBLISH, "Uploading artifacts from " + source.getAbsolutePath() + " to " + getDestPath(destPath)); String normalizedDestPath = FilenameUtils.separatorsToUnix(destPath); String url = urlService.getUploadUrlOfAgent(jobIdentifier, normalizedDestPath, publishingAttempts); int statusCode = httpService.upload(url, size, dataToUpload, artifactChecksums(source, normalizedDestPath)); if (statusCode == HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE) { String message = String.format( "Artifact upload for file %s (Size: %s) was denied by the server. This usually happens when server runs out of disk space.", source.getAbsolutePath(), size); goPublisher.taggedConsumeLineWithPrefix(PUBLISH_ERR, message); LOGGER.error( "[Artifact Upload] Artifact upload was denied by the server. This usually happens when server runs out of disk space."); publishingAttempts = PUBLISH_MAX_RETRIES; bomb(message + ". HTTP return code is " + statusCode); } if (statusCode < HttpServletResponse.SC_OK || statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES) { bomb("Failed to upload " + source.getAbsolutePath() + ". HTTP return code is " + statusCode); } return; } catch (Throwable e) { String message = "Failed to upload " + source.getAbsolutePath(); LOGGER.error(message, e); goPublisher.taggedConsumeLineWithPrefix(PUBLISH_ERR, message); lastException = e; } finally { FileUtils.deleteQuietly(tmpDir); } } if (lastException != null) { throw new RuntimeException(lastException); } }
From source file:org.deidentifier.arx.gui.worker.WorkerSave.java
@Override public void run(final IProgressMonitor arg0) throws InvocationTargetException, InterruptedException { arg0.beginTask(Resources.getMessage("WorkerSave.0"), 8); //$NON-NLS-1$ File temp = null;//from w ww . j av a 2s. c om try { temp = File.createTempFile("arx", "deid"); final FileOutputStream f = new FileOutputStream(temp); final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(f)); zip.setLevel(Deflater.BEST_SPEED); model.createConfig(); writeMetadata(model, zip); arg0.worked(1); writeModel(model, zip); arg0.worked(1); writeInput(model, zip); arg0.worked(1); writeOutput(model, zip); arg0.worked(1); writeConfiguration(model, zip); arg0.worked(1); final Map<String, Integer> map = writeLattice(model, zip); arg0.worked(1); writeClipboard(model, map, zip); arg0.worked(1); writeFilter(model, zip); zip.close(); arg0.worked(1); FileUtils.copyFile(temp, new File(path)); FileUtils.deleteQuietly(temp); } catch (final Exception e) { error = e; arg0.done(); FileUtils.deleteQuietly(temp); return; } arg0.done(); }
From source file:org.apache.felix.webconsole.internal.misc.ConfigurationRender.java
/** * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from ww w .j a v a 2s . c om protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getPathInfo().endsWith(".txt")) { response.setContentType("text/plain; charset=utf-8"); ConfigurationWriter pw = new PlainTextConfigurationWriter(response.getWriter()); printConfigurationStatus(pw, ConfigurationPrinter.MODE_TXT); pw.flush(); } else if (request.getPathInfo().endsWith(".zip")) { String type = getServletContext().getMimeType(request.getPathInfo()); if (type == null) { type = "application/x-zip"; } response.setContentType(type); ZipOutputStream zip = new ZipOutputStream(response.getOutputStream()); zip.setLevel(Deflater.BEST_SPEED); zip.setMethod(ZipOutputStream.DEFLATED); final ConfigurationWriter pw = new ZipConfigurationWriter(zip); printConfigurationStatus(pw, ConfigurationPrinter.MODE_ZIP); pw.flush(); addAttachments(pw, ConfigurationPrinter.MODE_ZIP); zip.finish(); } else if (request.getPathInfo().endsWith(".nfo")) { WebConsoleUtil.setNoCache(response); response.setContentType("text/html; charset=utf-8"); String name = request.getPathInfo(); name = name.substring(name.lastIndexOf('/') + 1); name = name.substring(0, name.length() - 4); name = WebConsoleUtil.urlDecode(name); ConfigurationWriter pw = new HtmlConfigurationWriter(response.getWriter()); pw.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""); pw.println(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); pw.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); pw.println("<head><title>dummy</title></head><body><div>"); Collection printers = getConfigurationPrinters(); for (Iterator i = printers.iterator(); i.hasNext();) { final PrinterDesc desc = (PrinterDesc) i.next(); if (desc.label.equals(name)) { printConfigurationPrinter(pw, desc, ConfigurationPrinter.MODE_WEB); pw.println("</div></body></html>"); return; } } response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid configuration printer: " + name); } else { super.doGet(request, response); } }
From source file:org.apache.flex.compiler.internal.embedding.transcoders.JPEGTranscoder.java
public static byte[] deflate(byte[] buf) throws IOException { Deflater deflater = new Deflater(Deflater.BEST_SPEED); DAByteArrayOutputStream out = new DAByteArrayOutputStream(); DeflaterOutputStream deflaterStream = new DeflaterOutputStream(out, deflater); try {/* w ww . jav a 2 s . com*/ deflaterStream.write(buf, 0, buf.length); deflaterStream.finish(); deflater.end(); } finally { IOUtils.closeQuietly(deflaterStream); } return out.getDirectByteArray(); }
From source file:com.alibaba.otter.node.etl.common.pipe.impl.http.archive.ArchiveBean.java
/** * /*w w w.ja v a 2 s .c o m*/ */ @SuppressWarnings("resource") private boolean doPack(final File targetArchiveFile, List<FileData> fileDatas, final ArchiveRetriverCallback<FileData> callback) { // ? if (true == targetArchiveFile.exists() && false == NioUtils.delete(targetArchiveFile, 3)) { throw new ArchiveException( String.format("[%s] exist and delete failed", targetArchiveFile.getAbsolutePath())); } boolean exist = false; ZipOutputStream zipOut = null; Set<String> entryNames = new HashSet<String>(); BlockingQueue<Future<ArchiveEntry>> queue = new LinkedBlockingQueue<Future<ArchiveEntry>>(); // ? ExecutorCompletionService completionService = new ExecutorCompletionService(executor, queue); final File targetDir = new File(targetArchiveFile.getParentFile(), FilenameUtils.getBaseName(targetArchiveFile.getPath())); try { // FileUtils.forceMkdir(targetDir); zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetArchiveFile))); zipOut.setLevel(Deflater.BEST_SPEED); // ?? for (final FileData fileData : fileDatas) { if (fileData.getEventType().isDelete()) { continue; // delete?? } String namespace = fileData.getNameSpace(); String path = fileData.getPath(); boolean isLocal = StringUtils.isBlank(namespace); String entryName = null; if (true == isLocal) { entryName = FilenameUtils.getPath(path) + FilenameUtils.getName(path); } else { entryName = namespace + File.separator + path; } // ???? if (entryNames.contains(entryName) == false) { entryNames.add(entryName); } else { continue; } final String name = entryName; if (true == isLocal && !useLocalFileMutliThread) { // ?? queue.add(new DummyFuture(new ArchiveEntry(name, callback.retrive(fileData)))); } else { completionService.submit(new Callable<ArchiveEntry>() { public ArchiveEntry call() throws Exception { // ?? InputStream input = null; OutputStream output = null; try { input = callback.retrive(fileData); if (input instanceof LazyFileInputStream) { input = ((LazyFileInputStream) input).getInputSteam();// ?stream } if (input != null) { File tmp = new File(targetDir, name); NioUtils.create(tmp.getParentFile(), false, 3);// ? output = new FileOutputStream(tmp); NioUtils.copy(input, output);// ? return new ArchiveEntry(name, new File(targetDir, name)); } else { return new ArchiveEntry(name); } } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } } }); } } for (int i = 0; i < entryNames.size(); i++) { // ? ArchiveEntry input = null; InputStream stream = null; try { input = queue.take().get(); if (input == null) { continue; } stream = input.getStream(); if (stream == null) { continue; } if (stream instanceof LazyFileInputStream) { stream = ((LazyFileInputStream) stream).getInputSteam();// ?stream } exist = true; zipOut.putNextEntry(new ZipEntry(input.getName())); NioUtils.copy(stream, zipOut);// ? zipOut.closeEntry(); } finally { IOUtils.closeQuietly(stream); } } if (exist) { zipOut.finish(); } } catch (Exception e) { throw new ArchiveException(e); } finally { IOUtils.closeQuietly(zipOut); try { FileUtils.deleteDirectory(targetDir);// } catch (IOException e) { // ignore } } return exist; }
From source file:mergedoc.core.MergeManager.java
/** * ????<br>/*from ww w . j a v a 2 s . c o m*/ * @throws MergeDocException ?????? * @throws SAXException SAX ???? * @throws IOException ???? */ public void execute() throws MergeDocException, SAXException, IOException { if (workingState.isCanceled()) { return; } ArchiveInputStream in = null; ZipOutputStream out = null; try { in = ArchiveInputStream.create(pref.getInputArchive()); out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(pref.getOutputArchive()))); out.setLevel(Deflater.BEST_SPEED); long start = System.currentTimeMillis(); merge(in, out); long end = System.currentTimeMillis(); workingState.setWorkTime((end - start) / 1000); } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:org.diorite.impl.world.io.anvil.AnvilRegion.java
private NbtOutputStream getOutputStream(final int x, final int z, final byte version) throws IOException { this.checkBounds(x, z); if (version == VERSION_GZIP) { return new NbtOutputStream(new BufferedOutputStream(new GZIPOutputStream(new ChunkBuffer(x, z)))); }/*from w w w . jav a 2 s. c o m*/ if (version == VERSION_DEFLATE) { return new NbtOutputStream(new BufferedOutputStream( new DeflaterOutputStream(new ChunkBuffer(x, z), new Deflater(Deflater.BEST_SPEED)))); } throw new RuntimeException("Unknown version: " + version); }
From source file:org.apache.tez.common.TezCommonUtils.java
@Private public static Deflater newBestSpeedDeflater() { return new Deflater(Deflater.BEST_SPEED, NO_WRAP); }