com.jcraft.jzlib.GZIPOutputStream.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中com.jcraft.jzlib.GZIPOutputStream.<init>()方法的一些代码示例,展示了GZIPOutputStream.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GZIPOutputStream.<init>()方法的具体详情如下:
包路径:com.jcraft.jzlib.GZIPOutputStream
类名称:GZIPOutputStream
方法名:<init>

GZIPOutputStream.<init>介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

public OutputStream compress(OutputStream out) throws IOException {
    return new GZIPOutputStream(new BufferedOutputStream(out));
  }
};

代码示例来源:origin: jenkinsci/jenkins

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
    }
  }
});

代码示例来源:origin: jenkinsci/jenkins

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;
}

代码示例来源:origin: jenkinsci/jenkins

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;
}

代码示例来源:origin: jenkinsci/jenkins

OutputStream zipos = new GZIPOutputStream(cipheros);
 OutputStreamWriter w = new OutputStreamWriter(zipos, "UTF-8")) {
o.write(w);

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public OutputStream compress(OutputStream out) throws IOException {
    return new GZIPOutputStream(new BufferedOutputStream(out));
  }
};

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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
    }
  }
});

代码示例来源:origin: org.kohsuke.stapler/stapler

public void activate() throws IOException {
  if (stream==null) {
    super.setHeader("Content-Encoding", "gzip");
    stream = new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), stream);
  }
}

代码示例来源:origin: stapler/stapler

public void activate() throws IOException {
  if (stream==null) {
    super.setHeader("Content-Encoding", "gzip");
    stream = new FilterServletOutputStream(new GZIPOutputStream(super.getOutputStream()), stream);
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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;
}

代码示例来源:origin: stapler/stapler

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())));
}

代码示例来源:origin: org.kohsuke.stapler/stapler

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())));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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;
}

代码示例来源:origin: org.jruby/jruby-complete

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);
  }
}

代码示例来源:origin: org.jruby/jruby-core

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);
  }
}

代码示例来源:origin: org.kohsuke.stapler/stapler

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()));
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

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);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

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);
  }
}

代码示例来源:origin: stapler/stapler

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()));
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

OutputStream zipos = new GZIPOutputStream(cipheros);
 OutputStreamWriter w = new OutputStreamWriter(zipos, "UTF-8")) {
o.write(w);

相关文章