/** * 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()); }
/** * 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()); }
private ConsoleAnnotator<T> createAnnotator(StaplerRequest req) throws IOException { try { String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null; if (base64!=null) { Cipher sym = PASSING_ANNOTATOR.decrypt(); ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream( new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)), Jenkins.getInstance().pluginManager.uberClassLoader); try { long timestamp = ois.readLong(); if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp)) // don't deserialize something too old to prevent a replay attack return (ConsoleAnnotator)ois.readObject(); } finally { ois.close(); } } } catch (ClassNotFoundException e) { throw new IOException(e); } // start from scratch return ConsoleAnnotator.initial(context); }
public InputStream extract(InputStream _in) throws IOException { HeadBufferingStream in = new HeadBufferingStream(_in,SIDE_BUFFER_SIZE); try { return new GZIPInputStream(in, 8192, true); } catch (IOException e) { // various people reported "java.io.IOException: Not in GZIP format" here, so diagnose this problem better in.fillSide(); throw new IOException(e.getMessage()+"\nstream="+Util.toHexString(in.getSideBuffer()),e); } } public OutputStream compress(OutputStream out) throws IOException {
try (ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)), jenkins != null ? jenkins.pluginManager.uberClassLoader : ConsoleNote.class.getClassLoader(), ClassFilter.DEFAULT)) {
public GzipAwareSession(File file) throws IOException { this.gz = new GZIPInputStream(Files.newInputStream(file.toPath(), StandardOpenOption.READ)); }
public GzipAwareSession(File file) throws IOException { this.gz = new GZIPInputStream(Files.newInputStream(file.toPath(), StandardOpenOption.READ)); }
public InputStream getLogInputStream() throws IOException { File logFile = getLogFile(); if (logFile != null && logFile.exists()) { // Checking if a ".gz" file was return FileInputStream fis = new FileInputStream(logFile); if (logFile.getName().endsWith(".gz")) { return new GZIPInputStream(fis); } else { return fis; } } String message = "No such file: " + logFile; return new ByteArrayInputStream(message.getBytes(Charsets.UTF_8)); }
public static byte[] maybe_decompress(byte[] bytes) { if (bytes.length == 0) { return bytes; } if (bytes[0] != 0x1f) { return bytes; } try { InputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes)); ByteArrayOutputStream out = new ByteArrayOutputStream(); int symbol; while ((symbol = in.read()) != -1) { out.write(symbol); } in.close(); bytes = out.toByteArray(); } catch (IOException e) { e.printStackTrace(); } return bytes; }
/** * 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()); }
/** * Returns an input stream that reads from the log file. * It will use a gzip-compressed log file (log.gz) if that exists. * * @return An input stream from the log file. * If the log file does not exist, the error message will be returned to the output. * @throws IOException if things go wrong */ @Nonnull public InputStream getLogInputStream() throws IOException { File logFile = getLogFile(); if (logFile.exists()) { // Checking if a ".gz" file was return FileInputStream fis = new FileInputStream(logFile); if (logFile.getName().endsWith(".gz")) { return new GZIPInputStream(fis); } else { return fis; } } String message = "No such file: " + logFile; return new ByteArrayInputStream(message.getBytes(Charsets.UTF_8)); }
/** * 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()); }
/** * Returns an input stream that reads from the log file. * It will use a gzip-compressed log file (log.gz) if that exists. * * @return An input stream from the log file. * If the log file does not exist, the error message will be returned to the output. * @throws IOException if things go wrong */ @Nonnull public InputStream getLogInputStream() throws IOException { File logFile = getLogFile(); if (logFile.exists()) { // Checking if a ".gz" file was return FileInputStream fis = new FileInputStream(logFile); if (logFile.getName().endsWith(".gz")) { return new GZIPInputStream(fis); } else { return fis; } } String message = "No such file: " + logFile; return new ByteArrayInputStream(message.getBytes(Charsets.UTF_8)); }
private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException { try { String base64 = req!=null ? req.getHeader("X-ConsoleAnnotator") : null; if (base64!=null) { Cipher sym = PASSING_ANNOTATOR.decrypt(); ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream( new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)), Jenkins.getInstance().pluginManager.uberClassLoader); try { long timestamp = ois.readLong(); if (TimeUnit.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp)) // don't deserialize something too old to prevent a replay attack return (ConsoleAnnotator)ois.readObject(); } finally { ois.close(); } } } catch (ClassNotFoundException e) { throw new IOException(e); } // start from scratch return ConsoleAnnotator.initial(context==null ? null : context.getClass()); }
public InputStream extract(InputStream _in) throws IOException { HeadBufferingStream in = new HeadBufferingStream(_in,SIDE_BUFFER_SIZE); try { return new GZIPInputStream(in, 8192, true); } catch (IOException e) { // various people reported "java.io.IOException: Not in GZIP format" here, so diagnose this problem better in.fillSide(); throw new IOException(e.getMessage()+"\nstream="+Util.toHexString(in.getSideBuffer()),e); } } public OutputStream compress(OutputStream out) throws IOException {
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; }
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; }
/** * add a spec (Ruby Object) to the specs.4.8 indices. */ private void addSpecToIndex(IRubyObject spec) throws IOException { SpecsHelper specs = gateway.newSpecsHelper(); for (SpecsIndexType type : SpecsIndexType.values()) { SpecsIndexZippedFile specsIndex = ensureSpecsIndexZippedFile(type); try (InputStream in = new GZIPInputStream(store.getInputStream(specsIndex))) { try (InputStream result = specs.addSpec(spec, in, type)) { // if nothing was added the content is NULL if (result != null) { store.update(IOUtil.toGzipped(result), specsIndex); } } } } }
@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; }
@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; }