@Override public InputStream getInputStream() throws IOException { return this.delegate.getInputStream(); }
public void copyTo(OutputStream outputStream) throws IOException { try (InputStream in = source.getInputStream()) { IOUtils.copy(in, outputStream); } }
public String getMd5() { try (InputStream input = source.getInputStream()) { MessageDigest digester = MessageDigest.getInstance("MD5"); try (DigestInputStream digest = new DigestInputStream(input, digester)) { IOUtils.copy(digest, new NullOutputStream()); } return Hex.encodeHexString(digester.digest()).toLowerCase(); } catch (Exception e) { throw new RuntimeException(e); } }
public void copyTo(File output) throws IOException { try (InputStream in = source.getInputStream()) { FileUtils.copyToFile(in, output); } } }
@Override public void matched (URI uri) throws Exception { LOG.debug("Search of {}",uri); if (uri.toString().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { InputStream in = Resource.newResource(uri).getInputStream(); if (in==null) return; JarInputStream jar_in = new JarInputStream(in); try { JarEntry entry = jar_in.getNextJarEntry(); while (entry!=null) { processEntry(uri, entry); entry = jar_in.getNextJarEntry(); } } finally { jar_in.close(); } } } }
public void parse () throws Exception { if (_root == null) { try { XmlParser parser = ensureParser(); _root = parser.parse(_xml.getInputStream()); _dtd = parser.getDTD(); } finally { _xml.close(); } } }
private Server buildServerOrApplyConfiguration(String jettyConfiguration, Server server) throws Exception { // try local file first Resource jettyConfigurationFile = Resource.newResource(jettyConfiguration); if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) { // fallback to classpath jettyConfigurationFile = Resource.newClassPathResource(jettyConfiguration); if (jettyConfigurationFile == null || !jettyConfigurationFile.exists()) { throw new FileNotFoundException("Unable to find jetty configuration file either locally or on classpath '" + jettyConfiguration + "'"); } } logger.info("Applying jetty configuration '{}'", jettyConfigurationFile); try (InputStream is = jettyConfigurationFile.getInputStream()) { XmlConfiguration configuration = new XmlConfiguration(is); // create or apply to existing if (server == null) { return (Server)configuration.configure(); } else { return (Server)configuration.configure(server); } } }
@Override public InputStream getInputStream() throws IOException { if(_resources==null) throw new IllegalStateException("*resources* not set."); for(Resource r : _resources) { InputStream is = r.getInputStream(); if(is!=null) return is; } return null; }
public static KeyStore getKeyStore(Resource store, String storeType, String storeProvider, String storePassword) throws Exception { KeyStore keystore = null; if (store != null) { Objects.requireNonNull(storeType, "storeType cannot be null"); if (storeProvider != null) { keystore = KeyStore.getInstance(storeType, storeProvider); } else { keystore = KeyStore.getInstance(storeType); } if (!store.exists()) throw new IllegalStateException("no valid keystore"); try (InputStream inStream = store.getInputStream()) { keystore.load(inStream, storePassword == null ? null : storePassword.toCharArray()); } } return keystore; }
@Override protected void doStart() throws Exception { Properties properties = new Properties(); Resource resource = Resource.newResource(_config); properties.load(resource.getInputStream()); _targetName = properties.getProperty("targetName"); LOG.debug("Target Name {}", _targetName); super.doStart(); }
/** * @param out the output stream to write to * @param start First byte to write * @param count Bytes to write or -1 for all of them. * @throws IOException if unable to copy the Resource to the output */ public void writeTo(OutputStream out,long start,long count) throws IOException { try (InputStream in = getInputStream()) { in.skip(start); if (count<0) IO.copy(in,out); else IO.copy(in,out,count); } }
public static Collection<? extends CRL> loadCRL(String crlPath) throws Exception { Collection<? extends CRL> crlList = null; if (crlPath != null) { InputStream in = null; try { in = Resource.newResource(crlPath).getInputStream(); crlList = CertificateFactory.getInstance("X.509").generateCRLs(in); } finally { if (in != null) { in.close(); } } } return crlList; }
try (InputStream in = resource.getInputStream())
properties.load(config.getInputStream());
public static ByteBuffer toBuffer(Resource resource,boolean direct) throws IOException { int len=(int)resource.length(); if (len<0) throw new IllegalArgumentException("invalid resource: "+String.valueOf(resource)+" len="+len); ByteBuffer buffer = direct?BufferUtil.allocateDirect(len):BufferUtil.allocate(len); int pos=BufferUtil.flipToFill(buffer); if (resource.getFile()!=null) BufferUtil.readFrom(resource.getFile(),buffer); else { try (InputStream is = resource.getInputStream();) { BufferUtil.readFrom(is,len,buffer); } } BufferUtil.flipToFlush(buffer,pos); return buffer; }
@Override public InputStream getInputStream() throws IOException { return _resource.getInputStream(); }
private void loadProperties() throws FileNotFoundException, IOException { if (_map.isEmpty() && _file!=null) { Properties properties = new Properties(); properties.load(_file.getInputStream()); for (Map.Entry<Object, Object> entry : properties.entrySet()) _map.put(entry.getKey().toString(),String.valueOf(entry.getValue())); } } }
@Override protected void doStart() throws Exception { Properties properties = new Properties(); Resource resource = Resource.newResource(_config); properties.load(resource.getInputStream()); _targetName = properties.getProperty("targetName"); LOG.debug("Target Name {}", _targetName); super.doStart(); }
@Override protected void doStart() throws Exception { Properties properties = new Properties(); Resource resource = Resource.newResource(_config); properties.load(resource.getInputStream()); _targetName = properties.getProperty("targetName"); LOG.debug("Target Name {}", _targetName); super.doStart(); }
public InputStream getInputStream() throws IOException { Buffer indirect = getIndirectBuffer(); if (indirect!=null && indirect.array()!=null) return new ByteArrayInputStream(indirect.array(),indirect.getIndex(),indirect.length()); return _resource.getInputStream(); }