/** * INTERNAL: Same as getInputStream(null, name); * * @since 3.4.3 */ public static InputStream getInputStream(String name) throws IOException { return getInputStream(null, name); }
public int add(InputStream data, int length) throws ContentStoreException { try { content.put(new Integer(nextKey), StreamUtils.read(data, length)); return nextKey++; } catch (IOException e) { throw new ContentStoreException(e); } }
public static byte[] getContent(String file_or_url) { File file = new File(file_or_url); if (file.exists()) { try { return StreamUtils.readAndClose(new FileInputStream(file)); } catch (IOException e) { // ignore } } // try file_or_url as URL return null; }
/** * PUBLIC: Given the file name or URL of a topic map, returns a * topic map reader of the right class. Uses the file extension to * determine what reader to create. Supports '.xtm', and '.ltm'. */ public static TopicMapReaderIF getReader (String filename_or_url) { try { return getReader(StreamUtils.getResource(filename_or_url)); } catch (IOException ioe) { throw new OntopiaRuntimeException(ioe); } }
public synchronized int add(InputStream data, int length) throws ContentStoreException { checkOpen(); int key = getNewKey(); File file = getFileForKey(key); if (file.exists()) throw new ContentStoreException("Content store corrupted: file already " + "exists for key " + key + "."); try { // verify that container directory exists if (!file.getParentFile().exists()) file.getParentFile().mkdir(); // store data OutputStream out = new FileOutputStream(file); StreamUtils.transfer(data, out); out.close(); } catch (IOException e) { throw new ContentStoreException("Error writing data to content store.", e); } // integrity check if (file.length() != length) throw new ContentStoreException("Stored entry for key " + key + " of wrong " + "size. Given length was " + length + ", but " + "resulting entry was " + file.length()); return key; }
log.debug(MSG_FILE_LOADED_THROUGH_CLASS_LOADER + name); } else if (name.startsWith(FILE_PREFIX)) { File f = makeFile(basedir, name.substring(FILE_PREFIX.length())); if (f.exists()) { log.debug(MSG_FILE_LOADED_FROM_FILE_SYSTEM + name); return new URL(name).openStream(); } else { File f = makeFile(basedir, name); if (f.exists()) { log.debug(MSG_FILE_LOADED_FROM_FILE_SYSTEM + name);
URL url = (clusterProps != null ? StreamUtils.getResource(clusterProps) : null); if (url == null) { if (clusterProps == null) {
StreamUtils.transfer(istream, ostream); istream.close(); } catch (IOException e) {
@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; }
public synchronized void joinCluster() { try { System.out.println("Joining cluster: '" + clusterId + "'"); try { URL url = (clusterProps != null ? StreamUtils.getResource(clusterProps) : null); if (url == null) { if (clusterProps == null) { log.debug("Using default cluster properties."); this.channel = new JChannel(); } else { log.debug("Using cluster properties as given: '" + clusterProps + "'"); this.channel = new JChannel(clusterProps); } } else { log.debug("Using cluster properties in: '" + url + "'"); this.channel = new JChannel(url); } } catch (Exception e) { throw new OntopiaRuntimeException("Problems occurred while loading JGroups properties from " + clusterProps, e); } this.channel.setReceiver(this); this.channel.connect(clusterId); } catch (Exception e) { throw new OntopiaRuntimeException("Could not connect to cluster '" + clusterId + "'.", e); } }
@Override public void onSubmit() { FileUpload upload = uploadField.getFileUpload(); if (upload != null) { try { Reader input = new InputStreamReader(new Base64.InputStream(upload.getInputStream(), Base64.ENCODE), "utf-8"); FieldInstance fieldInstance = fieldValueModel.getFieldInstanceModel().getFieldInstance(); StringWriter swriter = new StringWriter(); StreamUtils.transfer(input, swriter); String value = swriter.toString(); fieldInstance.addValue(value, getLifeCycleListener()); fieldValueModel.setExistingValue(value); uploaded = true; } catch (IOException e) { e.printStackTrace(); } } }
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); }