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

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

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

GZIPInputStream介绍

暂无

代码示例

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

/**
 * Reads the contents of a file.
 */
public InputStream read() throws IOException {
  if(file.exists())
    try {
      return Files.newInputStream(file.toPath());
    } catch (InvalidPathException e) {
      throw new IOException(e);
    }
  // check if the compressed file exists
  if(gz.exists())
    try {
      return new GZIPInputStream(Files.newInputStream(gz.toPath()));
    } catch (InvalidPathException e) {
      throw new IOException(e);
    }
  // no such file
  throw new FileNotFoundException(file.getName());
}

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

public IRubyObject initialize(ThreadContext context, IRubyObject stream) {
  Ruby runtime = context.runtime;
  realIo = stream;
  try {
    // don't close realIO
    ioInputStream = new IOInputStream(realIo);
    io = new GZIPInputStream(ioInputStream, 512, false);
    // JRUBY-4502
    // CRuby expects to parse gzip header in 'new'.
    io.readHeader();
  } catch (IOException e) {
    RaiseException re = RubyZlib.newGzipFileError(runtime, "not in gzip format");
    byte[] input = io.getAvailIn();
    if (input != null && input.length > 0) {
      RubyException rubye = re.getException();
      rubye.setInstanceVariable("@input", 
          RubyString.newString(runtime, new ByteList(input, 0, input.length)));
    }
    throw re;
  }
  position = 0;
  line = 0;
  bufferedStream = new PushbackInputStream(new BufferedInputStream(io), 512);
  return this;
}

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

@Override
@JRubyMethod
public IRubyObject crc() {
  long crc = 0;
  try {
    crc = io.getCRC();
  } catch (GZIPException e) {
  }
  return getRuntime().newFixnum(crc);
}

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

@Override
@JRubyMethod
public IRubyObject comment() {
  String comment = io.getComment();
  nullFreeComment = getRuntime().newString(comment);
  return super.comment();
}

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

@JRubyMethod
public IRubyObject unused() {
  byte[] tmp = io.getAvailIn();
  
  if (tmp == null) return getRuntime().getNil();
  return RubyString.newString(getRuntime(), tmp);
}

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

@Override
@JRubyMethod
public IRubyObject os_code() {
  int os = io.getOS();
  
  if (os == 255) os = (byte) 0x0b; // NTFS filesystem (NT), because CRuby's test_zlib expect it.
  
  return getRuntime().newFixnum(os & 0xff);
}

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

@Override
@JRubyMethod
public IRubyObject orig_name() {
  String name = io.getName();
  nullFreeOrigName = getRuntime().newString(name);
  return super.orig_name();
}

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

/**
 * Get position within this stream including that has been read by users
 * calling read + what jzlib may have speculatively read in because of
 * buffering.
 *
 * @return number of bytes
 */
private long internalPosition() {
  Inflater inflater = io.getInflater();
  return inflater.getTotalIn() + inflater.getAvailIn();
}

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

public IRubyObject initialize(ThreadContext context, IRubyObject stream) {
  Ruby runtime = context.runtime;
  realIo = stream;
  try {
    // don't close realIO
    ioInputStream = new IOInputStream(realIo);
    io = new GZIPInputStream(ioInputStream, 512, false);
    // JRUBY-4502
    // CRuby expects to parse gzip header in 'new'.
    io.readHeader();
  } catch (IOException e) {
    RaiseException re = RubyZlib.newGzipFileError(runtime, "not in gzip format");
    byte[] input = io.getAvailIn();
    if (input != null && input.length > 0) {
      RubyException rubye = re.getException();
      rubye.setInstanceVariable("@input", 
          RubyString.newString(runtime, new ByteList(input, 0, input.length)));
    }
    throw re;
  }
  position = 0;
  line = 0;
  bufferedStream = new PushbackInputStream(new BufferedInputStream(io), 512);
  return this;
}

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

@Override
@JRubyMethod
public IRubyObject crc() {
  long crc = 0;
  try {
    crc = io.getCRC();
  } catch (GZIPException e) {
  }
  return getRuntime().newFixnum(crc);
}

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

@Override
@JRubyMethod
public IRubyObject comment() {
  String comment = io.getComment();
  nullFreeComment = getRuntime().newString(comment);
  return super.comment();
}

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

@JRubyMethod
public IRubyObject unused() {
  byte[] tmp = io.getAvailIn();
  
  if (tmp == null) return getRuntime().getNil();
  return RubyString.newString(getRuntime(), tmp);
}

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

@Override
@JRubyMethod
public IRubyObject os_code() {
  int os = io.getOS();
  
  if (os == 255) os = (byte) 0x0b; // NTFS filesystem (NT), because CRuby's test_zlib expect it.
  
  return getRuntime().newFixnum(os & 0xff);
}

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

@Override
@JRubyMethod
public IRubyObject orig_name() {
  String name = io.getName();
  nullFreeOrigName = getRuntime().newString(name);
  return super.orig_name();
}

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

/**
 * Get position within this stream including that has been read by users
 * calling read + what jzlib may have speculatively read in because of
 * buffering.
 *
 * @return number of bytes
 */
private long internalPosition() {
  Inflater inflater = io.getInflater();
  return inflater.getTotalIn() + inflater.getAvailIn();
}

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

/**
 * Returns an input stream that reads from the log file.
 * It will use a gzip-compressed log file (log.gz) if that exists.
 *
 * @throws IOException 
 * @return An input stream from the log file. 
 *   If the log file does not exist, the error message will be returned to the output.
 * @since 1.349
 */
public @Nonnull InputStream getLogInputStream() throws IOException {
  File logFile = getLogFile();
  
  if (logFile.exists() ) {
    // Checking if a ".gz" file was return
    try {
      InputStream fis = Files.newInputStream(logFile.toPath());
      if (logFile.getName().endsWith(".gz")) {
        return new GZIPInputStream(fis);
      } else {
        return fis;
      }
    } catch (InvalidPathException e) {
      throw new IOException(e);
    }
  }
  
  String message = "No such file: " + logFile;
  return new ByteArrayInputStream(charset != null ? message.getBytes(charset) : message.getBytes());
}

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

@JRubyMethod(name = "initialize", visibility = PRIVATE, compat = RUBY1_8)
public IRubyObject initialize(ThreadContext context, IRubyObject stream) {
  Ruby runtime = context.runtime;
  realIo = stream;
  try {
    // don't close realIO
    ioInputStream = new IOInputStream(realIo);
    io = new GZIPInputStream(ioInputStream, 512, false);
    // JRUBY-4502
    // CRuby expects to parse gzip header in 'new'.
    io.readHeader();
  } catch (IOException e) {
    RaiseException re = RubyZlib.newGzipFileError(runtime, "not in gzip format");
    if (getRuntime().is1_9()) {
      byte[] input = io.getAvailIn();
      if (input != null && input.length > 0) {
        RubyException rubye = re.getException();
        rubye.setInstanceVariable("@input", 
            RubyString.newString(runtime, new ByteList(input, 0, input.length)));
      }
    }
    throw re;
  }
  position = 0;
  line = 0;
  bufferedStream = new BufferedInputStream(io);
  return this;
}

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

@Override
@JRubyMethod
public IRubyObject crc() {
  long crc = 0;
  try {
    crc = io.getCRC();
  } catch (GZIPException e) {
  }
  return getRuntime().newFixnum(crc);
}

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

@Override
@JRubyMethod
public IRubyObject comment() {
  String comment = io.getComment();
  nullFreeComment = getRuntime().newString(comment);
  return super.comment();
}

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

@JRubyMethod
public IRubyObject unused() {
  byte[] tmp = io.getAvailIn();
  
  if (tmp == null) return getRuntime().getNil();
  return RubyString.newString(getRuntime(), tmp);
}

相关文章