/** * Reads the contents of a resource as a string. * * @param resource * @return Contents of the resource. * @throws IOException */ public static String getContent(String resource) throws IOException { InputStream is = openResource(resource); try{ return IOUtils.toString(is, "UTF-8"); } finally { IOUtils.closeQuietly(is); } }
/** * Opens a resource * @param resource * @return An input stream for the given named resource * @throws FileNotFoundException */ public static InputStream openResource(String resource) throws FileNotFoundException { ClassLoader cl = ResourceLoader.class.getClassLoader(); try { return openResource(cl, resource); } catch (FileNotFoundException e) { // If we cannot find the resource using the current classes class loader // try the current threads cl = Thread.currentThread().getContextClassLoader(); return openResource(cl, resource); } }
/** * Opens a resource * @param resource * @return An input stream for the given named resource * @throws FileNotFoundException */ public static InputStream openResource(String resource) throws FileNotFoundException { ClassLoader cl = ResourceLoader.class.getClassLoader(); try { return openResource(cl, resource); } catch (FileNotFoundException e) { // If we cannot find the resource using the current classes class loader // try the current threads cl = Thread.currentThread().getContextClassLoader(); return openResource(cl, resource); } }
/** * Reads the contents of a resource as a string. * * @param resource * @return Contents of the resource. * @throws IOException */ public static String getContent(String resource) throws IOException { InputStream is = openResource(resource); try { return IOUtils.toString(is, "UTF-8"); } finally { IOUtils.closeQuietly(is); } }
/** * Reads the contents of a resource as a string. * * @param resource * @return Contents of the resource. * @throws IOException */ public static String getContent(String resource) throws IOException { InputStream is = openResource(resource); try { return IOUtils.toString(is, "UTF-8"); } finally { IOUtils.closeQuietly(is); } }
/** * Reads the contents of a resource as a string. * * @param resource * @return Contents of the resource. * @throws IOException */ public static String getContent(String resource) throws IOException { InputStream is = openResource(resource); try{ return IOUtils.toString(is, "UTF-8"); } finally { IOUtils.closeQuietly(is); } }
/** * Opens a resource * @param resource * @return An input stream for the given named resource * @throws FileNotFoundException */ public static InputStream openResource(String resource) throws FileNotFoundException { ClassLoader cl = ResourceLoader.class.getClassLoader(); try { return openResource(cl, resource); } catch (FileNotFoundException e) { // If we cannot find the resource using the current classes class loader // try the current threads cl = Thread.currentThread().getContextClassLoader(); return openResource(cl, resource); } }
/** * Reads the contents of a resource as a string. * * @param resource * @return Contents of the resource. * @throws IOException */ public static String getContent(String resource) throws IOException { InputStream is = openResource(resource); try { return IOUtils.toString(is, "UTF-8"); } finally { IOUtils.closeQuietly(is); } }
/** * Opens a given path as either a resource or a file, depending on the path * name. * * If path starts with res://, we interpret it as a resource. * Otherwise we attempt to load it as a file. * @param path * @return The opened input stream */ public static InputStream open(String path) throws IOException { if (path.startsWith("res://")) { return openResource(path.substring(6)); } File file = new File(path); return new FileInputStream(file); }
/** * Opens a given path as either a resource or a file, depending on the path * name. * * If path starts with res://, we interpret it as a resource. * Otherwise we attempt to load it as a file. * @param path * @return The opened input stream */ public static InputStream open(String path) throws IOException { if (path.startsWith("res://")) { return openResource(path.substring(6)); } File file = new File(path); return new FileInputStream(file); }
/** * Initializes the JsonDbOpensocialService using Guice * * @param jsonLocation location of the json data provided by the shindig.canonical.json.db parameter * @param converter an injected BeanConverter * @throws java.lang.Exception if any */ @Inject public JsonDbOpensocialService(@Named("shindig.canonical.json.db") String jsonLocation, @Named("shindig.bean.converter.json") BeanConverter converter, @Named("shindig.contextroot") String contextroot) throws Exception { String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8"); this.db = new JSONObject(content.replace("%contextroot%", contextroot)); this.converter = converter; }
/** * Initializes the JsonDbOpensocialService using Guice * * @param jsonLocation location of the json data provided by the shindig.canonical.json.db parameter * @param converter an injected BeanConverter * @throws java.lang.Exception if any */ @Inject public JsonDbOpensocialService(@Named("shindig.canonical.json.db") String jsonLocation, @Named("shindig.bean.converter.json") BeanConverter converter) throws Exception { String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8"); this.db = new JSONObject(content); this.converter = converter; }
@Inject public OAuth2DataServiceImpl( @Named("shindig.canonical.json.db") String jsonLocation, @Named("shindig.bean.converter.json") BeanConverter converter, @Named("shindig.contextroot") String contextroot) throws Exception { String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8"); content = content.replace("%contextRoot%", contextroot); this.oauthDB = new JSONObject(content).getJSONObject("oauth2"); this.converter = converter; this.clients = Lists.newArrayList(); this.authCodes = Maps.newHashMap(); this.accessTokens = Maps.newHashMap(); loadClientsFromCanonical(); }
@Inject public OAuth2DataServiceImpl( @Named("shindig.canonical.json.db") String jsonLocation, @Named("shindig.bean.converter.json") BeanConverter converter, @Named("shindig.contextroot") String contextroot) throws Exception { String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8"); content = content.replace("%contextRoot%", contextroot); this.oauthDB = new JSONObject(content).getJSONObject("oauth2"); this.converter = converter; this.clients = Lists.newArrayList(); this.authCodes = Maps.newHashMap(); this.accessTokens = Maps.newHashMap(); loadClientsFromCanonical(); }
public RpcSwfServlet(String swfResource) { try { InputStream is = ResourceLoader.openResource(swfResource); if (is == null) { throw new RuntimeException("Failed to locate Flash SWF"); } this.swfBytes = IOUtils.toByteArray(is); this.hash = HashUtil.checksum(swfBytes); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Opens a given path as either a resource or a file, depending on the path * name. * * If path starts with res://, we interpret it as a resource. * If path starts with file://, or path has no prefix, we interpret it as a file. * @param path * @return The opened input stream */ public static InputStream open(String path) throws IOException { if (path.startsWith(RESOURCE_PREFIX)) { return openResource(path.substring(RESOURCE_PREFIX.length())); } else if (path.startsWith(FILE_PREFIX)) { path = path.substring(FILE_PREFIX.length()); } File file = new File(path); return new FileInputStream(file); }
/** * Opens a given path as either a resource or a file, depending on the path * name. * * If path starts with res://, we interpret it as a resource. * If path starts with file://, or path has no prefix, we interpret it as a file. * @param path * @return The opened input stream */ public static InputStream open(String path) throws IOException { if (path.startsWith(RESOURCE_PREFIX)) { return openResource(path.substring(RESOURCE_PREFIX.length())); } else if (path.startsWith(FILE_PREFIX)) { path = path.substring(FILE_PREFIX.length()); } File file = new File(path); return new FileInputStream(file); }
/** * Initializes the JsonDbOpensocialService using Guice * * @param jsonLocation location of the json data provided by the shindig.canonical.json.db parameter * @param converter an injected BeanConverter * @throws java.lang.Exception if any */ @Inject public JsonDbOpensocialService(@Named("shindig.canonical.json.db") String jsonLocation, @Named("shindig.bean.converter.json") BeanConverter converter, @Named("shindig.contextroot") String contextroot) throws Exception { String content = IOUtils.toString(ResourceLoader.openResource(jsonLocation), "UTF-8"); this.db = new JSONObject(content.replace("%contextroot%", contextroot)); this.converter = converter; }
private Properties readPropertyFile(String propertyFile) { Properties properties = new Properties(); InputStream is = null; try { is = ResourceLoader.openResource(propertyFile); properties.load(is); } catch (IOException e) { throw new CreationException(Arrays.asList( new Message("Unable to load properties: " + propertyFile))); } finally { IOUtils.closeQuietly( is ); } return properties; }
private Properties readPropertyFile(String propertyFile) { Properties properties = new Properties(); InputStream is = null; try { is = ResourceLoader.openResource(propertyFile); properties.load(is); } catch (IOException e) { throw new CreationException(Arrays.asList( new Message("Unable to load properties: " + propertyFile))); } finally { IOUtils.closeQuietly( is ); } return properties; }