/** * 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()); }
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; }
@Override @JRubyMethod public IRubyObject crc() { long crc = 0; try { crc = io.getCRC(); } catch (GZIPException e) { } return getRuntime().newFixnum(crc); }
@Override @JRubyMethod public IRubyObject comment() { String comment = io.getComment(); nullFreeComment = getRuntime().newString(comment); return super.comment(); }
@JRubyMethod public IRubyObject unused() { byte[] tmp = io.getAvailIn(); if (tmp == null) return getRuntime().getNil(); return RubyString.newString(getRuntime(), tmp); }
@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); }
@Override @JRubyMethod public IRubyObject orig_name() { String name = io.getName(); nullFreeOrigName = getRuntime().newString(name); return super.orig_name(); }
/** * 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(); }
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; }
@Override @JRubyMethod public IRubyObject crc() { long crc = 0; try { crc = io.getCRC(); } catch (GZIPException e) { } return getRuntime().newFixnum(crc); }
@Override @JRubyMethod public IRubyObject comment() { String comment = io.getComment(); nullFreeComment = getRuntime().newString(comment); return super.comment(); }
@JRubyMethod public IRubyObject unused() { byte[] tmp = io.getAvailIn(); if (tmp == null) return getRuntime().getNil(); return RubyString.newString(getRuntime(), tmp); }
@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); }
@Override @JRubyMethod public IRubyObject orig_name() { String name = io.getName(); nullFreeOrigName = getRuntime().newString(name); return super.orig_name(); }
/** * 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(); }
/** * 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()); }
@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; }
@Override @JRubyMethod public IRubyObject crc() { long crc = 0; try { crc = io.getCRC(); } catch (GZIPException e) { } return getRuntime().newFixnum(crc); }
@Override @JRubyMethod public IRubyObject comment() { String comment = io.getComment(); nullFreeComment = getRuntime().newString(comment); return super.comment(); }
@JRubyMethod public IRubyObject unused() { byte[] tmp = io.getAvailIn(); if (tmp == null) return getRuntime().getNil(); return RubyString.newString(getRuntime(), tmp); }