public OutputStream compress(OutputStream out) throws IOException { return new GZIPOutputStream(new BufferedOutputStream(out)); } };
public void run() { try { try (InputStream in = read(); OutputStream os = Files.newOutputStream(gz.toPath()); OutputStream out = new GZIPOutputStream(os)) { org.apache.commons.io.IOUtils.copy(in, out); } // if the compressed file is created successfully, remove the original file.delete(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to compress "+file,e); gz.delete(); // in case a processing is left in the middle } } });
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream<T> caw = new ConsoleAnnotationOutputStream<>( w, createAnnotator(Stapler.getCurrentRequest()), context, charset); long r = super.writeLogTo(start,caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym))); oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close(); StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp!=null) rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); return r; }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (OutputStream gzos = new GZIPOutputStream(buf); ObjectOutputStream oos = JenkinsJVM.isJenkinsJVM() ? AnonymousClassWarnings.checkingObjectOutputStream(gzos) : new ObjectOutputStream(gzos)) { oos.writeObject(this); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); try { buf2.write(PREAMBLE); if (JenkinsJVM.isJenkinsJVM()) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE byte[] mac = MAC.mac(buf.toByteArray()); dos.writeInt(- mac.length); // negative to differentiate from older form dos.write(mac); } dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
OutputStream zipos = new GZIPOutputStream(cipheros); OutputStreamWriter w = new OutputStreamWriter(zipos, "UTF-8")) { o.write(w);
public OutputStream compress(OutputStream out) throws IOException { return new GZIPOutputStream(new BufferedOutputStream(out)); } };
public void run() { try { try (InputStream in = read(); OutputStream os = Files.newOutputStream(gz.toPath()); OutputStream out = new GZIPOutputStream(os)) { org.apache.commons.io.IOUtils.copy(in, out); } // if the compressed file is created successfully, remove the original file.delete(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to compress "+file,e); gz.delete(); // in case a processing is left in the middle } } });
public void activate() throws IOException { if (stream==null) { super.setHeader("Content-Encoding", "gzip"); stream = new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), stream); } }
public void activate() throws IOException { if (stream==null) { super.setHeader("Content-Encoding", "gzip"); stream = new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), stream); } }
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream( w, createAnnotator(Stapler.getCurrentRequest()), context, charset); long r = super.writeLogTo(start,caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym))); oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close(); StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp!=null) rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); return r; }
public Writer getCompressedWriter(HttpServletRequest req) throws IOException { if (mode!=null) return getWriter(); if(acceptsGzip(req)) return getWriter(); // compression not available if (CompressionFilter.activate(req)) return getWriter(); // CompressionFilter will set up compression. no need to do anything // CompressionFilter not available, so do it on our own. // see CompressionFilter for why this is not desirable setHeader("Content-Encoding","gzip"); return recordOutput(new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(super.getOutputStream()),getCharacterEncoding()))); }
public Writer getCompressedWriter(HttpServletRequest req) throws IOException { if (mode!=null) return getWriter(); if(acceptsGzip(req)) return getWriter(); // compression not available if (CompressionFilter.activate(req)) return getWriter(); // CompressionFilter will set up compression. no need to do anything // CompressionFilter not available, so do it on our own. // see CompressionFilter for why this is not desirable setHeader("Content-Encoding","gzip"); return recordOutput(new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(super.getOutputStream()),getCharacterEncoding()))); }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf))) { oos.writeObject(this); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); try { buf2.write(PREAMBLE); if (Jenkins.getInstanceOrNull() != null) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE byte[] mac = MAC.mac(buf.toByteArray()); dos.writeInt(- mac.length); // negative to differentiate from older form dos.write(mac); } dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
private IRubyObject initializeCommon(IRubyObject stream, int level) { realIo = (RubyObject) stream; try { // the 15+16 here is copied from a Deflater default constructor Deflater deflater = new Deflater(level, 15+16, false); final IOOutputStream ioOutputStream = new IOOutputStream(realIo, false, false) { /** * Customize IOOutputStream#write(byte[], int, int) to create a defensive copy of the byte array * that GZIPOutputStream hands us. * * That byte array is a reference to one of GZIPOutputStream's internal byte buffers. * The base IOOutputStream#write(byte[], int, int) uses the bytes it is handed to back a * copy-on-write ByteList. So, without this defensive copy, those two classes overwrite each * other's bytes, corrupting our output. */ @Override public void write(byte[] bytes, int off, int len) throws IOException { byte[] bytesCopy = new byte[len]; System.arraycopy(bytes, off, bytesCopy, 0, len); super.write(bytesCopy, 0, len); } }; io = new GZIPOutputStream(ioOutputStream, deflater, 512, false); return this; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } }
private IRubyObject initializeCommon(IRubyObject stream, int level) { realIo = (RubyObject) stream; try { // the 15+16 here is copied from a Deflater default constructor Deflater deflater = new Deflater(level, 15+16, false); final IOOutputStream ioOutputStream = new IOOutputStream(realIo, false, false) { /** * Customize IOOutputStream#write(byte[], int, int) to create a defensive copy of the byte array * that GZIPOutputStream hands us. * * That byte array is a reference to one of GZIPOutputStream's internal byte buffers. * The base IOOutputStream#write(byte[], int, int) uses the bytes it is handed to back a * copy-on-write ByteList. So, without this defensive copy, those two classes overwrite each * other's bytes, corrupting our output. */ @Override public void write(byte[] bytes, int off, int len) throws IOException { byte[] bytesCopy = new byte[len]; System.arraycopy(bytes, off, bytesCopy, 0, len); super.write(bytesCopy, 0, len); } }; io = new GZIPOutputStream(ioOutputStream, deflater, 512, false); return this; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } }
public OutputStream getCompressedOutputStream(HttpServletRequest req) throws IOException { if (mode!=null) // we already made the call and created OutputStream/Writer return getOutputStream(); if(acceptsGzip(req)) return getOutputStream(); // compression not applicable here if (CompressionFilter.activate(req)) return getOutputStream(); // CompressionFilter will set up compression. no need to do anything // CompressionFilter not available, so do it on our own. // see CompressionFilter for why this is not desirable setHeader("Content-Encoding","gzip"); return recordOutput(new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), super.getOutputStream())); }
private IRubyObject initializeCommon(IRubyObject stream, int level) { realIo = (RubyObject) stream; try { // the 15+16 here is copied from a Deflater default constructor Deflater deflater = new Deflater(level, 15+16, false); io = new GZIPOutputStream(new IOOutputStream(realIo, false, false), deflater, 512, false); return this; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } }
private IRubyObject initializeCommon(IRubyObject stream, int level) { realIo = (RubyObject) stream; try { // the 15+16 here is copied from a Deflater default constructor Deflater deflater = new Deflater(level, 15+16, false); io = new GZIPOutputStream(new IOOutputStream(realIo, false, false), deflater, 512, false); return this; } catch (IOException ioe) { throw getRuntime().newIOErrorFromException(ioe); } }
public OutputStream getCompressedOutputStream(HttpServletRequest req) throws IOException { if (mode!=null) // we already made the call and created OutputStream/Writer return getOutputStream(); if(acceptsGzip(req)) return getOutputStream(); // compression not applicable here if (CompressionFilter.activate(req)) return getOutputStream(); // CompressionFilter will set up compression. no need to do anything // CompressionFilter not available, so do it on our own. // see CompressionFilter for why this is not desirable setHeader("Content-Encoding","gzip"); return recordOutput(new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), super.getOutputStream())); }
OutputStream zipos = new GZIPOutputStream(cipheros); OutputStreamWriter w = new OutputStreamWriter(zipos, "UTF-8")) { o.write(w);