List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:net.orpiske.ssps.common.configuration.ConfigurationWrapper.java
/** * Initializes the configuration object//from w w w. j a v a2 s .com * * @param configDir * The configuration directory containing the configuration file * @param fileName * The name of the configuration file * @throws FileNotFoundException * @throws ConfigurationException */ public static void initConfiguration(final String configDir, final String fileName) throws FileNotFoundException, ConfigurationException { if (configDir == null) { throw new FileNotFoundException("The configuration dir was not found"); } config = new PropertiesConfiguration(configDir + File.separator + fileName); // Appends an user config file, if exits ($HOME/.sdm/sdm.properties) String userFilePath = Utils.getSdmDirectoryPath() + File.separator + fileName; File userFile = new File(userFilePath); if (userFile.exists()) { PropertiesConfiguration userConfiguration = new PropertiesConfiguration(userFile); config.append(userConfiguration); } }
From source file:net.erdfelt.android.sdkfido.sdks.SourceOriginsLoader.java
public static SourceOrigins load() throws IOException { String resourcePath = "sdks-ng.xml"; URL url = SourceOriginsLoader.class.getResource(resourcePath); if (url == null) { throw new FileNotFoundException("Unable to find resource: " + resourcePath); }/* w w w . ja v a 2 s . c om*/ return load(url); }
From source file:Main.java
private static InputStream createInputStream(String src) throws FileNotFoundException { if (src.startsWith(PREFIX_JAR)) { String name = src.substring(PREFIX_JAR.length()); InputStream inputStream = Thread.currentThread().getClass().getResourceAsStream(name); if (inputStream == null) { throw new FileNotFoundException("resource not found: " + src); }/* ww w . j a va 2 s. co m*/ return inputStream; } else if (src.startsWith(PREFIX_FILE)) { File file = new File(src.substring(PREFIX_FILE.length())); if (!file.exists()) { throw new IllegalArgumentException("file does not exist: " + src); } else if (!file.isFile()) { throw new IllegalArgumentException("not a file: " + src); } else if (!file.canRead()) { throw new IllegalArgumentException("cannot read file: " + src); } return new FileInputStream(file); } throw new IllegalArgumentException("invalid bitmap source: " + src); }
From source file:com.github.ibole.infrastructure.security.key.PemUtils.java
private static byte[] parsePEMFile(File pemFile) throws IOException { if (!pemFile.isFile() || !pemFile.exists()) { throw new FileNotFoundException( String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath())); }/*from www .j a v a2s .c o m*/ PemReader reader = null; PemObject pemObject; try { reader = new PemReader(new FileReader(pemFile)); pemObject = reader.readPemObject(); } finally { IOUtils.closeQuietly(reader); } return pemObject.getContent(); }
From source file:eu.serco.dhus.config.PropertiesLoader.java
public static Properties loadProperties(String propFileName) { InputStream inputStream = null; try {/*from ww w . j av a 2 s . c om*/ rulesProps = new Properties(); inputStream = PropertiesLoader.class.getClassLoader().getResourceAsStream(propFileName); if (inputStream != null) { rulesProps.load(inputStream); } else { logger.error("property file '" + propFileName + "' not found in the classpath"); throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); } } catch (Exception e) { logger.error("Exception: " + e); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { logger.error("Error closing InputStream for properties file: " + e); e.printStackTrace(); } } return rulesProps; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectorUtilities.java
/** * Look in the current theme directory to find a selection image for this * Locale./* ww w . j a v a2 s .co m*/ * * Images are expected at a resource path like * /[themeDir]/i18n/images/select_locale_[locale_code].* * * For example, /themes/wilma/i18n/images/select_locale_en.png * /themes/wilma/i18n/images/select_locale_en.JPEG * /themes/wilma/i18n/images/select_locale_en.gif * * To create a proper URL, prepend the context path. */ public static String getImageUrl(VitroRequest vreq, Locale locale) throws FileNotFoundException { String filename = "select_locale_" + locale + "."; String themeDir = vreq.getAppBean().getThemeDir(); String imageDirPath = "/" + themeDir + "i18n/images/"; ServletContext ctx = vreq.getSession().getServletContext(); @SuppressWarnings("unchecked") Set<String> resourcePaths = ctx.getResourcePaths(imageDirPath); if (resourcePaths != null) { for (String resourcePath : resourcePaths) { if (resourcePath.contains(filename)) { String fullPath = vreq.getContextPath() + resourcePath; log.debug("Found image for " + locale + " at '" + fullPath + "'"); return fullPath; } } } throw new FileNotFoundException("Can't find an image for " + locale); }
From source file:net.erdfelt.android.sdkfido.sdks.SourceOriginsLoader.java
public static SourceOrigins load(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException("Unable to find file: " + file); }//from www . java2 s .co m return load(file.toURI().toURL()); }
From source file:onl.area51.filesystem.http.client.HttpUtils.java
public static void retrieve(char[] path, Function<char[], String> remoteUri, Supplier<FileSystemIO> delegate, Supplier<String> userAgent) throws IOException { if (path == null || path.length == 0) { throw new FileNotFoundException("/"); }//w w w.java 2 s. co m String uri = remoteUri.apply(path); if (uri != null) { LOG.log(Level.FINE, () -> "Retrieving " + uri); HttpGet get = new HttpGet(uri); get.setHeader(USER_AGENT, userAgent.get()); try (CloseableHttpClient client = HttpClients.createDefault()) { try (CloseableHttpResponse response = client.execute(get)) { int returnCode = response.getStatusLine().getStatusCode(); LOG.log(Level.FINE, () -> "ReturnCode " + returnCode + ": " + response.getStatusLine().getReasonPhrase()); switch (returnCode) { case 200: case 304: FileSystemUtils.copyFromRemote(() -> response.getEntity().getContent(), delegate.get(), path); return; default: } } } } throw new FileNotFoundException(String.valueOf(path)); }
From source file:edu.northwestern.bioinformatics.studycalendar.restlets.ClasspathResourceRepresentation.java
@Override public InputStream getStream() throws IOException { ClassPathResource res = new ClassPathResource(resourceName); if (!res.exists()) { throw new FileNotFoundException("Could not find " + resourceName); }/*from w w w .jav a2 s . c o m*/ return res.getInputStream(); }
From source file:com.sap.prd.mobile.ios.mios.ScriptRunner.java
private static File copyScript(String script, File workingDirectory) throws IOException { if (!workingDirectory.exists()) if (!workingDirectory.mkdirs()) throw new IOException("Cannot create directory '" + workingDirectory + "'."); final File scriptFile = new File(workingDirectory, getScriptFileName(script)); scriptFile.deleteOnExit();/*from ww w .j a va 2s.co m*/ OutputStream os = null; InputStream is = null; try { is = ScriptRunner.class.getResourceAsStream(script); if (is == null) throw new FileNotFoundException(script + " not found."); os = FileUtils.openOutputStream(scriptFile); IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } Forker.forkProcess(System.out, null, "chmod", "755", scriptFile.getCanonicalPath()); return scriptFile; }