/** * INTERNAL: Same as getInputStream(null, name); * * @since 3.4.3 */ public static InputStream getInputStream(String name) throws IOException { return getInputStream(null, name); }
@Override public InputStream getResourceAsStream(String path) { InputStream stream = null; String fullpath = rootpath + path; try { stream = StreamUtils.getInputStream(fullpath); } catch (IOException e) { logger.warn("Cannot locate file: " + fullpath); } return stream; }
protected InputStream getInputStream(String property, String filename) throws IOException { String _filename = properties.get(property); if (_filename == null) { _filename = "classpath:net/ontopia/topicmaps/impl/rdbms/config/" + filename; } else { log.debug(filename + ": using file '" + _filename + "'"); } return StreamUtils.getInputStream(_filename); }
private static File getTransferredTestInputFile(String filein, File fileout) throws IOException, FileNotFoundException { if (fileout.exists()) { // file has already been transferred, return as is return fileout; } // transfer test data from resource to file InputStream streamin = StreamUtils.getInputStream(filein); FileOutputStream streamout = new FileOutputStream(fileout); IOUtils.copy(streamin, streamout); streamout.close(); streamin.close(); return fileout; }
/** * PUBLIC: Creates a reader bound to the given URI. */ public OSLSchemaReader(String uri) throws MalformedURLException, IOException { source = uri.startsWith("classpath:") ? new InputSource(StreamUtils.getInputStream(uri)) : new InputSource(uri); base_address = new URILocator(uri); }
/** * INTERNAL: Reads the database schema definition from the specified file. */ public static Project loadProject(String filename) throws IOException, SAXException { return loadProject(StreamUtils.getInputStream(filename)); } public static Project loadProject(InputStream istream) throws IOException, SAXException {
/** * INTERNAL: Compares the contents of a file and a resource that will be loaded from classpath */ public static boolean compareFileToResource(String fileName, String resourceName) throws IOException { try (FileInputStream in1 = new FileInputStream(fileName); InputStream in2 = StreamUtils.getInputStream(resourceName)) { return IOUtils.contentEquals(in1, in2); } }
/** * INTERNAL: Compares the contents of a file and a resource that will be loaded from classpath */ public static boolean compareFileToResource(File file, String resourceName) throws IOException { try (FileInputStream in1 = new FileInputStream(file); InputStream in2 = StreamUtils.getInputStream(resourceName)) { return IOUtils.contentEquals(in1, in2); } } }
private Properties loadProperties() throws IOException { File basedir = mapping.getBaseDirectory(); InputStream is = StreamUtils.getInputStream(basedir, propfile); if (is == null) throw new DB2TMException("Couldn't find properties file '" + propfile + "'"); Properties props = new Properties(); props.load(is); is.close(); return props; }
private Properties loadProperties() throws IOException { File basedir = mapping.getBaseDirectory(); InputStream is = StreamUtils.getInputStream(basedir, propfile); if (is == null) throw new DB2TMException("Couldn't find properties file '" + propfile + "'"); Properties props = new Properties(); props.load(is); is.close(); return props; }
public static Reader makeReader(LocatorIF locator, EncodingSnifferIF sniffer) throws IOException { return makeReader(StreamUtils.getInputStream(locator.getExternalForm()), null, sniffer); }
/** * INTERNAL: Creates a storage definition that reads its settings * from the specified property file. */ public RDBMSStorage(String propfile) throws IOException { // TODO: attempt to load props from CLASSPATH (file: oks.rdbms.props) if (propfile == null) throw new NullPointerException("Property file cannot be null. Please set the 'net.ontopia.topicmaps.impl.rdbms.PropertyFile' property."); // Load properties from file InputStream istream = StreamUtils.getInputStream(propfile); if (istream == null) throw new OntopiaRuntimeException("Property file '" + propfile + "' was not found."); if (log.isDebugEnabled()) log.info("Loading properties file from: " + propfile); init(PropertyUtils.toMap(PropertyUtils.loadProperties(istream))); }
public TopicMapIF transformRequest(String transformId, InputStream xmlstream, LocatorIF base) throws Exception { InputStream xsltstream = StreamUtils.getInputStream("classpath:" + transformId + ".xsl"); if (xsltstream == null) throw new ServletException("Could not find style sheet '" + transformId + ".xsl'"); // set up source and target streams // Source xmlSource = new StreamSource(xmlstream); Source xmlSource = new StreamSource(xmlstream); Source xsltSource = new StreamSource(xsltstream); // the factory pattern supports different XSLT processors TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(xsltSource); CharArrayWriter cw = new CharArrayWriter(); trans.transform(xmlSource, new StreamResult(cw)); CharArrayReader cr = new CharArrayReader(cw.toCharArray()); TopicMapStoreIF store = new InMemoryTopicMapStore(); TopicMapIF topicmap = store.getTopicMap(); store.setBaseAddress(base); XTMTopicMapReader xr = new XTMTopicMapReader(cr, base); xr.setValidation(false); xr.importInto(topicmap); return topicmap; }
final String classpathPrefix = "file:classpath:"; // IncludeTag adds file: prefix funcs = (location.toString().startsWith(classpathPrefix)) ? reader.read(StreamUtils.getInputStream(location.toString().substring(classpathPrefix.length()))) : reader.read(location.openConnection().getInputStream()); resourceLastModReadIn = getModificationDate();
protected RDBMSStorage createStorage() throws IOException { if (storage == null) { if (propfile != null) this.storage = new RDBMSStorage(propfile); else if (properties != null) this.storage = new RDBMSStorage(properties); else throw new OntopiaRuntimeException("propertyFile property must be specified on source with id '" + getId() + "'."); if (queryfile != null) { InputStream stream = StreamUtils.getInputStream(queryfile); if (stream == null) throw new IOException("Could not find query file " + queryfile); storage.getQueryDeclarations().loadQueries(stream); } } return storage; }
public static void checkDatabasePresence() throws IOException, SQLException, SAXException { if (System.getProperty("net.ontopia.topicmaps.impl.rdbms.PropertyFile") != null) { // PropertyFile has been set, check is ok return; } // PropertyFile has not been set, fall back to in-memory H2 database final String propertiesLocation = "classpath:net/ontopia/topicmaps/impl/rdbms/rdbms.h2.props"; final String schemaLocation = "classpath:net/ontopia/topicmaps/impl/rdbms/config/schema.xml"; // Load database properties Properties databaseProperties = new Properties(); databaseProperties.load(StreamUtils.getInputStream(propertiesLocation)); // Load topic map database schema DefaultConnectionFactory cfactory = new DefaultConnectionFactory(databaseProperties, false); Project project = DatabaseProjectReader.loadProject(schemaLocation); GenericSQLProducer producer = DDLExecuter.getSQLProducer(project, new String[]{"h2", "generic"}); // Inject database schema Connection conn = cfactory.requestConnection(); producer.executeCreate(conn); conn.commit(); conn.close(); // All is done, set rdbms.PropertyFile to H2 System.setProperty("net.ontopia.topicmaps.impl.rdbms.PropertyFile", propertiesLocation); }
@Test public void testImport() throws Exception { OccurrenceIF occ = tm1.getBuilder().makeOccurrence(foo1, foo1, "foo"); // concurrent import causing a merge MergeUtils.mergeInto(tm1, new LTMTopicMapReader( StreamUtils.getInputStream("classpath:net/ontopia/topicmaps/impl/rdbms/issue499.ltm"), URILocator.create("foo:bar")) .read()); store2.commit(); store1.commit(); occ = (OccurrenceIF) tm1.getObjectById(occ.getObjectId()); check(tm1, occ.getType(), "Occurrence", "type"); check(tm1, occ.getTopic(), "Occurrence", "topic"); // check(tm1, occ.getReifier(), "Occurrence", "reifier"); }