List of usage examples for java.util.zip DeflaterOutputStream DeflaterOutputStream
public DeflaterOutputStream(OutputStream out)
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new deflated nbt output stream for given stream. * * @param outputStream stream to be used. * * @return created NbtOutputStream.// w w w .j av a2 s . c om */ public static NbtOutputStream getDeflated(final OutputStream outputStream) { return new NbtOutputStream(new DeflaterOutputStream(outputStream)); }
From source file:com.moviejukebox.plugin.OpenSubtitlesPlugin.java
private static boolean subtitleUpload(Movie movie, File[] movieFile, File[] subtitleFile) { try {/*from www. j a v a 2s . c om*/ String ret; String xml; String idmovieimdb = movie.getId(ImdbPlugin.IMDB_PLUGIN_ID); if (StringUtils.isNotBlank(idmovieimdb) && idmovieimdb.length() >= 6) { idmovieimdb = String.valueOf(NumberUtils.toInt(idmovieimdb.substring(2))); } String[] subfilename = new String[movieFile.length]; String[] subhash = new String[movieFile.length]; String[] subcontent = new String[movieFile.length]; String[] moviehash = new String[movieFile.length]; String[] moviebytesize = new String[movieFile.length]; String[] movietimems = new String[movieFile.length]; String[] movieframes = new String[movieFile.length]; String[] moviefps = new String[movieFile.length]; String[] moviefilename = new String[movieFile.length]; for (int i = 0; i < movieFile.length; i++) { subfilename[i] = subtitleFile[i].getName(); subhash[i] = ""; subcontent[i] = ""; moviehash[i] = getHash(movieFile[i]); moviebytesize[i] = String.valueOf(movieFile[i].length()); movietimems[i] = ""; movieframes[i] = ""; moviefps[i] = String.valueOf(movie.getFps()); moviefilename[i] = movieFile[i].getName(); byte[] s; try (FileInputStream fisSubtitleFile = new FileInputStream(subtitleFile[i])) { s = new byte[fisSubtitleFile.available()]; fisSubtitleFile.read(s); } MessageDigest md = MessageDigest.getInstance("MD5"); md.update(s); subhash[i] = hashstring(md.digest()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOS = new DeflaterOutputStream(baos)) { deflaterOS.write(s); deflaterOS.finish(); subcontent[i] = tuBase64(baos.toByteArray()); } } // Check if upload of this subtitle is required xml = generateXMLRPCTUS(subhash, subfilename, moviehash, moviebytesize, movietimems, movieframes, moviefps, moviefilename); ret = sendRPC(xml); String alreadyindb = getIntValue("alreadyindb", ret); if (!"0".equals(alreadyindb)) { LOG.debug("Subtitle already in db for {}", movie.getBaseName()); return Boolean.TRUE; } LOG.debug("Upload Subtitle for {}", movie.getBaseName()); // Upload the subtitle xml = generateXMLRPCUS(idmovieimdb, subhash, subcontent, subfilename, moviehash, moviebytesize, movietimems, movieframes, moviefps, moviefilename); sendRPC(xml); return Boolean.TRUE; } catch (NumberFormatException | IOException | NoSuchAlgorithmException ex) { LOG.error("Upload Failed: {}", ex.getMessage()); return Boolean.FALSE; } }
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new deflated nbt output stream for given file. * * @param file file to be used.//from w ww.j a va 2 s . c o m * * @return created NbtOutputStream. * * @throws IOException if any file operation failed. */ public static NbtOutputStream getDeflated(final File file) throws IOException { createFile(file); return new NbtOutputStream(new DeflaterOutputStream(new FileOutputStream(file, false))); }
From source file:net.e2.bw.servicereg.ldap.ServiceInstanceLdapService.java
/** Converts coverage to compressed json */ public static byte[] compressCoverage(List<Area> coverage) { if (coverage != null && coverage.size() > 0) { try {//from www .j a v a 2 s . c om ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(new CoverageWrapper(coverage)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream out = new DeflaterOutputStream(baos); out.write(json.getBytes("UTF-8")); out.close(); return baos.toByteArray(); } catch (Exception ignored) { } } return null; }
From source file:br.gov.lexml.server.LexMLOAIHandler.java
/** * Get a response Writer depending on acceptable encodings * /* w ww. java 2s . co m*/ * @param request the servlet's request information * @param response the servlet's response information * @exception IOException an I/O error occurred */ public static Writer getWriter(final HttpServletRequest request, final HttpServletResponse response) throws IOException { Writer out; String encodings = request.getHeader("Accept-Encoding"); if (debug) { log.debug("encodings=" + encodings); } if (encodings != null && encodings.indexOf("gzip") != -1) { response.setHeader("Content-Encoding", "gzip"); out = new OutputStreamWriter(new GZIPOutputStream(response.getOutputStream()), "UTF-8"); } else if (encodings != null && encodings.indexOf("deflate") != -1) { response.setHeader("Content-Encoding", "deflate"); out = new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"); } else { out = response.getWriter(); } return out; }
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new deflated nbt output stream for given file. * * @param file file to be used.//w w w .j a va 2 s.co m * @param append if new data should be appended to existing one. * * @return created NbtOutputStream. * * @throws IOException if any file operation failed. */ public static NbtOutputStream getDeflated(final File file, final boolean append) throws IOException { createFile(file); return new NbtOutputStream(new DeflaterOutputStream(new FileOutputStream(file, append))); }
From source file:org.oclc.oai.server.OAIHandler.java
/** * Get a response Writer depending on acceptable encodings * * @param request the servlet's request information * @param response the servlet's response information * @throws IOException an I/O error occurred *//*from ww w . j a v a 2 s .co m*/ public static Writer getWriter(HttpServletRequest request, HttpServletResponse response) throws IOException { Writer out; String encodings = request.getHeader("Accept-Encoding"); if (debug) { System.out.println("encodings=" + encodings); } if (encodings != null && encodings.indexOf("gzip") != -1) { // System.out.println("using gzip encoding"); // log.debug("using gzip encoding"); response.setHeader("Content-Encoding", "gzip"); out = new OutputStreamWriter(new GZIPOutputStream(response.getOutputStream()), "UTF-8"); // } else if (encodings != null && encodings.indexOf("compress") != -1) { // // System.out.println("using compress encoding"); // response.setHeader("Content-Encoding", "compress"); // ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); // zos.putNextEntry(new ZipEntry("dummy name")); // out = new OutputStreamWriter(zos, "UTF-8"); } else if (encodings != null && encodings.indexOf("deflate") != -1) { // System.out.println("using deflate encoding"); // log.debug("using deflate encoding"); response.setHeader("Content-Encoding", "deflate"); out = new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"); } else { // log.debug("using no encoding"); out = response.getWriter(); } return out; }
From source file:de.burlov.amazon.s3.dirsync.DirSync.java
/** * Prepariert eine Datei zum Hochladen. Sie wird komprimiert und verschluesselt * //from w w w .ja va 2s .c o m * @param source * @return * @throws IOException */ private File prepareFileForUpload(File source, String s3key) throws IOException { File tmp = File.createTempFile("dirsync", ".tmp"); tmp.deleteOnExit(); InputStream in = null; OutputStream out = null; try { in = new FileInputStream(source); out = new DeflaterOutputStream( new CryptOutputStream(new FileOutputStream(tmp), cipher, getDataEncryptionKey())); IOUtils.copy(in, out); in.close(); out.close(); return tmp; } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:nl.nn.adapterframework.util.JdbcUtil.java
public static OutputStream getBlobOutputStream(IDbmsSupport dbmsSupport, Object blobUpdateHandle, final ResultSet rs, int columnIndex, boolean compressBlob) throws IOException, JdbcException, SQLException { OutputStream result;// w w w.j av a2 s . c om OutputStream out = dbmsSupport.getBlobOutputStream(rs, columnIndex, blobUpdateHandle); if (compressBlob) { result = new DeflaterOutputStream(out); } else { result = out; } return result; }
From source file:nl.nn.adapterframework.util.JdbcUtil.java
public static Writer getBlobWriter(IDbmsSupport dbmsSupport, Object blobUpdateHandle, final ResultSet rs, int columnIndex, String charset, boolean compressBlob) throws IOException, JdbcException, SQLException { Writer result;/*from w ww . jav a 2s. com*/ OutputStream out = dbmsSupport.getBlobOutputStream(rs, columnIndex, blobUpdateHandle); if (charset == null) { charset = Misc.DEFAULT_INPUT_STREAM_ENCODING; } if (compressBlob) { result = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(out), charset)); } else { result = new BufferedWriter(new OutputStreamWriter(out, charset)); } return result; }