com.jcraft.jzlib.GZIPOutputStream类的使用及代码示例

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

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

GZIPOutputStream介绍

暂无

代码示例

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

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

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

@Override
@JRubyMethod(name = "close")
public IRubyObject close() {
  if (!closed) {
    try {
      io.close();
      if (realIo.respondsTo("close")) {
        realIo.callMethod(realIo.getRuntime().getCurrentContext(), "close");
      }
    } catch (IOException ioe) {
      throw getRuntime().newIOErrorFromException(ioe);
    }
  }
  
  this.closed = true;
  
  return realIo;
}

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

@JRubyMethod(name = "flush", optional = 1)
public IRubyObject flush(IRubyObject[] args) {
  int flush = JZlib.Z_SYNC_FLUSH;
  
  if (args.length > 0 && !args[0].isNil()) {
    flush = RubyNumeric.fix2int(args[0]);
  }
  
  boolean tmp = io.getSyncFlush();
  try {
    if (flush != 0 /*
         * NO_FLUSH
         */) {
      io.setSyncFlush(true);
    }
    io.flush();
  } catch (IOException ioe) {
    throw getRuntime().newIOErrorFromException(ioe);
  } finally {
    io.setSyncFlush(tmp);
  }
  
  return getRuntime().getNil();
}

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

@JRubyMethod(name = "mtime=", required = 1)
public IRubyObject set_mtime(IRubyObject arg) {
  if (arg instanceof RubyTime) {
    this.mtime = ((RubyTime) arg);
  } else if (arg.isNil()) {
    // ...nothing
  } else {
    this.mtime.setDateTime(new DateTime(RubyNumeric.fix2long(arg) * 1000));
  }
  
  try {
    io.setModifiedTime(this.mtime.to_i().getLongValue());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return getRuntime().getNil();
}

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

@Override
@JRubyMethod(name = "crc")
public IRubyObject crc() {
  long crc = 0L;
  
  try {
    crc = io.getCRC();
  } catch (GZIPException e) {
    // not calculated yet
  }
  
  return getRuntime().newFixnum(crc);
}

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

@JRubyMethod(name = "orig_name=", required = 1)
public IRubyObject set_orig_name(IRubyObject obj) {
  nullFreeOrigName = obj.convertToString();
  ensureNonNull(nullFreeOrigName);
  
  try {
    io.setName(nullFreeOrigName.toString());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return obj;
}

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

@JRubyMethod(name = "comment=", required = 1)
public IRubyObject set_comment(IRubyObject obj) {
  nullFreeComment = obj.convertToString();
  ensureNonNull(nullFreeComment);
  
  try {
    io.setComment(nullFreeComment.toString());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return obj;
}

代码示例来源: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-complete

@Override
public IRubyObject finish() {
  if (!finished) {
    try {
      io.finish();
    } catch (IOException ioe) {
      throw getRuntime().newIOErrorFromException(ioe);
    }
  }
  
  finished = true;
  
  return realIo;
}

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

@JRubyMethod(name = {"pos", "tell"})
public IRubyObject pos() {
  return RubyNumeric.int2fix(getRuntime(), io.getTotalIn());
}

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

@Override
@JRubyMethod(name = "close")
public IRubyObject close() {
  if (!closed) {
    try {
      io.close();
      if (realIo.respondsTo("close")) {
        realIo.callMethod(realIo.getRuntime().getCurrentContext(), "close");
      }
    } catch (IOException ioe) {
      throw getRuntime().newIOErrorFromException(ioe);
    }
  }
  
  this.closed = true;
  
  return realIo;
}

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

@JRubyMethod(name = "flush", optional = 1)
public IRubyObject flush(IRubyObject[] args) {
  int flush = JZlib.Z_SYNC_FLUSH;
  
  if (args.length > 0 && !args[0].isNil()) {
    flush = RubyNumeric.fix2int(args[0]);
  }
  
  boolean tmp = io.getSyncFlush();
  try {
    if (flush != 0 /*
         * NO_FLUSH
         */) {
      io.setSyncFlush(true);
    }
    io.flush();
  } catch (IOException ioe) {
    throw getRuntime().newIOErrorFromException(ioe);
  } finally {
    io.setSyncFlush(tmp);
  }
  
  return getRuntime().getNil();
}

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

@JRubyMethod(name = "mtime=", required = 1)
public IRubyObject set_mtime(IRubyObject arg) {
  if (arg instanceof RubyTime) {
    this.mtime = ((RubyTime) arg);
  } else if (arg.isNil()) {
    // ...nothing
  } else {
    this.mtime.setDateTime(new DateTime(RubyNumeric.fix2long(arg) * 1000));
  }
  
  try {
    io.setModifiedTime(this.mtime.to_i().getLongValue());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return getRuntime().getNil();
}

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

@Override
@JRubyMethod(name = "crc")
public IRubyObject crc() {
  long crc = 0L;
  
  try {
    crc = io.getCRC();
  } catch (GZIPException e) {
    // not calculated yet
  }
  
  return getRuntime().newFixnum(crc);
}

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

@JRubyMethod(name = "orig_name=", required = 1)
public IRubyObject set_orig_name(IRubyObject obj) {
  nullFreeOrigName = obj.convertToString();
  ensureNonNull(nullFreeOrigName);
  
  try {
    io.setName(nullFreeOrigName.toString());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return obj;
}

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

@JRubyMethod(name = "comment=", required = 1)
public IRubyObject set_comment(IRubyObject obj) {
  nullFreeComment = obj.convertToString();
  ensureNonNull(nullFreeComment);
  
  try {
    io.setComment(nullFreeComment.toString());
  } catch (GZIPException e) {
    throw RubyZlib.newGzipFileError(getRuntime(), "header is already written");
  }
  
  return obj;
}

代码示例来源: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.jruby/jruby-core

@Override
public IRubyObject finish() {
  if (!finished) {
    try {
      io.finish();
    } catch (IOException ioe) {
      throw getRuntime().newIOErrorFromException(ioe);
    }
  }
  
  finished = true;
  
  return realIo;
}

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

@JRubyMethod(name = {"pos", "tell"})
public IRubyObject pos() {
  return RubyNumeric.int2fix(getRuntime(), io.getTotalIn());
}

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

@Override
@JRubyMethod(name = "close")
public IRubyObject close() {
  if (!closed) {
    try {
      io.close();
      if (realIo.respondsTo("close")) {
        realIo.callMethod(realIo.getRuntime().getCurrentContext(), "close");
      }
    } catch (IOException ioe) {
      throw getRuntime().newIOErrorFromException(ioe);
    }
  }
  
  this.closed = true;
  
  return getRuntime().getNil();
}

相关文章