List of usage examples for org.springframework.core.io Resource getInputStream
InputStream getInputStream() throws IOException;
From source file:edu.unc.lib.dl.schematron.SchematronValidator.java
/** * Check whether a given document conforms to a known schema. * * @param resource/*from w w w. j a v a2s . com*/ * a Spring resource that retrieves an XML stream * @param schema * name of schema to use * @return true if document conforms to schema */ public boolean isValid(Resource resource, String schema) throws IOException { Source source = new StreamSource(resource.getInputStream()); return this.isValid(source, schema); }
From source file:edu.unc.lib.dl.schematron.SchematronValidator.java
/** * This is the lowest level validation call, which returns an XML validation * report in schematron output format. (see http://purl.oclc.org/dsdl/svrl) * * @param resource/*www . ja v a 2 s .co m*/ * any type of Spring resource * @param schema * name of schema to use * @return schematron output document * @throws IOException * when resource cannot be read */ public Document validate(Resource resource, String schema) throws IOException { Source source = new StreamSource(resource.getInputStream()); return this.validate(source, schema); }
From source file:org.jasig.cas.extension.clearpass.integration.uportal.PasswordCachingCasAssertionSecurityContextFactory.java
public PasswordCachingCasAssertionSecurityContextFactory() { final Resource resource = new ClassPathResource(DEFAULT_PORTAL_SECURITY_PROPERTY_FILE, getClass().getClassLoader()); final Properties securityProperties = new Properties(); InputStream inputStream = null; try {//from w w w . j a va 2 s . c o m inputStream = resource.getInputStream(); securityProperties.load(inputStream); this.clearPassUrl = securityProperties.getProperty(CLEARPASS_CAS_URL_PROPERTY); } catch (final Exception e) { throw new RuntimeException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (final IOException e) { //nothing to do } } } }
From source file:com.wavemaker.commons.classloader.ThrowawayFileClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (this.classPath == null) { throw new ClassNotFoundException("invalid search root: " + this.classPath); } else if (name == null) { throw new ClassNotFoundException(MessageResource.NULL_CLASS.getMessage()); }/*from w ww .j ava 2 s . co m*/ String classNamePath = name.replace('.', '/') + ".class"; byte[] fileBytes = null; try { InputStream is = null; JarFile jarFile = null; for (Resource entry : this.classPath) { if (entry.getFilename().toLowerCase().endsWith(".jar")) { jarFile = new JarFile(entry.getFile()); ZipEntry ze = jarFile.getEntry(classNamePath); if (ze != null) { is = jarFile.getInputStream(ze); break; } else { jarFile.close(); } } else { Resource classFile = entry.createRelative(classNamePath); if (classFile.exists()) { is = classFile.getInputStream(); break; } } } if (is != null) { try { fileBytes = IOUtils.toByteArray(is); is.close(); } finally { if (jarFile != null) { jarFile.close(); } } } } catch (IOException e) { throw new ClassNotFoundException(e.getMessage(), e); } if (name.contains(".")) { String packageName = name.substring(0, name.lastIndexOf('.')); if (getPackage(packageName) == null) { definePackage(packageName, "", "", "", "", "", "", null); } } Class<?> ret; if (fileBytes == null) { ret = ClassLoaderUtils.loadClass(name, this.parentClassLoader); } else { ret = defineClass(name, fileBytes, 0, fileBytes.length); } if (ret == null) { throw new ClassNotFoundException( "Couldn't find class " + name + " in expected classpath: " + this.classPath); } return ret; }
From source file:de.metas.procurement.webui.ActiveMQBrokerConfiguration.java
/** * @return embedded ActiveMQ broker or <code>null</code> *//* w ww .j a va2s . co m*/ @Bean public BrokerService brokerService() throws Exception { if (!runEmbeddedBroker) { logger.info("Skip creating an ActiveMQ broker service"); return null; } final BrokerService brokerService = new BrokerService(); if (useSSL) { final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); { final KeyStore keystore = KeyStore.getInstance("JKS"); final Resource keyStoreResource = Application.getContext().getResource(keyStoreFileResourceURL); final InputStream keyStoreStream = keyStoreResource.getInputStream(); keystore.load(keyStoreStream, keyStorePassword.toCharArray()); kmf.init(keystore, keyStorePassword.toCharArray()); } final TrustManagerFactory tmf = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); { final KeyStore trustStore = KeyStore.getInstance("JKS"); final Resource trustStoreResource = Application.getContext().getResource(trustStoreFileResourceURL); final InputStream trustStoreStream = trustStoreResource.getInputStream(); trustStore.load(trustStoreStream, trustStorePassword.toCharArray()); tmf.init(trustStore); } final SslContext sslContext = new SslContext(kmf.getKeyManagers(), tmf.getTrustManagers(), null); brokerService.setSslContext(sslContext); } // // "client" Connector { final TransportConnector connector = new TransportConnector(); connector.setUri(new URI(brokerUrl.trim())); brokerService.addConnector(connector); } // // "Network of brokers" connector if (isSet(networkConnector_discoveryAddress)) { final DiscoveryNetworkConnector discoveryNetworkConnector = new DiscoveryNetworkConnector( new URI(networkConnector_discoveryAddress.trim())); discoveryNetworkConnector.setDuplex(true); // without this, we can send to the other broker, but won't get reposnses if (isSet(networkConnector_userName)) { discoveryNetworkConnector.setUserName(networkConnector_userName.trim()); } if (isSet(networkConnector_password)) { discoveryNetworkConnector.setPassword(networkConnector_password.trim()); } // we need to set ConduitSubscriptions to false, // see section "Conduit subscriptions and consumer selectors" on http://activemq.apache.org/networks-of-brokers.html discoveryNetworkConnector.setConduitSubscriptions(false); logger.info("Adding network connector: {}", networkConnector_discoveryAddress); brokerService.addNetworkConnector(discoveryNetworkConnector); } brokerService.setBrokerName(embeddedBrokerName); brokerService.start(); logger.info("Embedded JMS broker started on URL " + brokerUrl); return brokerService; }
From source file:org.eclipse.hono.authorization.impl.InMemoryAuthorizationService.java
private void load(final Resource source, final StringBuilder target) throws IOException { char[] buffer = new char[4096]; int bytesRead = 0; try (Reader reader = new InputStreamReader(source.getInputStream(), UTF_8)) { while ((bytesRead = reader.read(buffer)) > 0) { target.append(buffer, 0, bytesRead); }/*from w w w . ja v a 2 s . com*/ } }
From source file:ru.jts_dev.gameserver.parser.data.item.ItemDatasHolder.java
@PostConstruct private void parse() throws IOException { log.info("Loading data file: itemdata.txt"); final Resource file = context.getResource("scripts/itemdata.txt"); try (InputStream is = file.getInputStream()) { final ANTLRInputStream input = new ANTLRInputStream(is); final ItemDatasLexer lexer = new ItemDatasLexer(input); final CommonTokenStream tokens = new CommonTokenStream(lexer); final ItemDatasParser parser = new ItemDatasParser(tokens); parser.getInterpreter().setPredictionMode(PredictionMode.SLL); parser.setErrorHandler(new BailErrorStrategy()); parser.setProfile(false);/* www. j a va 2 s. c o m*/ long start = System.nanoTime(); final ParseTree tree = parser.file(); log.info("ParseTime: " + (System.nanoTime() - start) / 1_000_000); final ParseTreeWalker walker = new ParseTreeWalker(); start = System.nanoTime(); walker.walk(this, tree); log.info("WalkTime: " + (System.nanoTime() - start) / 1_000_000); } }
From source file:py.una.pol.karaku.menu.server.MenuServerLogic.java
/** * Retorna el men del sistema.//from w w w . ja v a 2s . com * * @return Men del sistema actual */ public List<Menu> getCurrentSystemMenu() { try { Resource resource = new ClassPathResource(util.get(KARAKU_MENU_LOCATION_KEY)); BufferedReader reader = new BufferedReader( new InputStreamReader(resource.getInputStream(), CharEncoding.ISO_8859_1)); Unmarshaller um = JAXBContext.newInstance(Menu.class).createUnmarshaller(); Menu m = (Menu) um.unmarshal(reader); configMenu(m); if (skip(m)) { return m.getItems(); } return Arrays.asList(m); } catch (UnsupportedEncodingException e) { throw new KarakuRuntimeException("Cant open the menu (wrong encoding)", e); } catch (IOException e) { throw new KarakuRuntimeException("Cant open the menu (file not found)", e); } catch (JAXBException e) { throw new KarakuRuntimeException("Cant open the menu (wrong XML)", e); } }
From source file:org.mongeez.reader.FormattedJavascriptChangeSetReader.java
private List<ChangeSet> parse(Resource file) throws IOException, ParseException { List<ChangeSet> changeSets = new ArrayList<ChangeSet>(); BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), cs)); try {/* w w w .j av a2 s. c om*/ String line = reader.readLine(); parseFileHeader(file, line); ChangeSet changeSet = null; StringBuilder scriptBody = null; line = reader.readLine(); while (line != null) { ChangeSet newChangeSet = parseChangeSetStart(line); if (newChangeSet != null) { addScriptToChangeSet(changeSet, scriptBody); changeSet = newChangeSet; scriptBody = new StringBuilder(); ChangeSetReaderUtil.populateChangeSetResourceInfo(changeSet, file); changeSets.add(changeSet); } else if (scriptBody != null) { scriptBody.append(line); scriptBody.append('\n'); } else if (!line.trim().isEmpty() && !line.startsWith(LINE_COMMENT)) { throw new ParseException(file + " has content outside of a changeset. " + "To start a changeset, add a comment in the format:\n" + LINE_COMMENT + "changeset author:id", 0); } // Silently ignore whitespace-only and comment-only lines line = reader.readLine(); } addScriptToChangeSet(changeSet, scriptBody); } finally { try { reader.close(); } catch (IOException ignore) { } } return changeSets; }
From source file:com.wavemaker.common.util.ThrowawayFileClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { if (this.classPath == null) { throw new ClassNotFoundException("invalid search root: " + this.classPath); } else if (name == null) { throw new ClassNotFoundException(MessageResource.NULL_CLASS.getMessage()); }//w ww . j av a 2 s.com String classNamePath = name.replace('.', '/') + ".class"; byte[] fileBytes = null; try { InputStream is = null; JarFile jarFile = null; for (Resource entry : this.classPath) { if (entry.getFilename().toLowerCase().endsWith(".jar")) { jarFile = new JarFile(entry.getFile()); ZipEntry ze = jarFile.getEntry(classNamePath); if (ze != null) { is = jarFile.getInputStream(ze); break; } else { jarFile.close(); } } else { Resource classFile = entry.createRelative(classNamePath); if (classFile.exists()) { is = classFile.getInputStream(); break; } } } if (is != null) { try { fileBytes = IOUtils.toByteArray(is); is.close(); } finally { if (jarFile != null) { jarFile.close(); } } } } catch (IOException e) { throw new ClassNotFoundException(e.getMessage(), e); } if (name.contains(".")) { String packageName = name.substring(0, name.lastIndexOf('.')); if (getPackage(packageName) == null) { definePackage(packageName, "", "", "", "", "", "", null); } } Class<?> ret; if (fileBytes == null) { ret = ClassLoaderUtils.loadClass(name, this.parentClassLoader); } else { ret = defineClass(name, fileBytes, 0, fileBytes.length); } if (ret == null) { throw new ClassNotFoundException( "Couldn't find class " + name + " in expected classpath: " + this.classPath); } return ret; }