List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:com.dianping.resource.io.util.ResourceUtils.java
/** * Resolve the given resource location to a {@code java.net.URL}. * <p>Does not check whether the URL actually exists; simply returns * the URL that the given location would correspond to. * @param resourceLocation the resource location to resolve: either a * "classpath:" pseudo URL, a "file:" URL, or a plain file path * @return a corresponding URL object/*from ww w . j av a 2 s .c o m*/ * @throws java.io.FileNotFoundException if the resource cannot be resolved to a URL */ public static URL getURL(String resourceLocation) throws FileNotFoundException { Assert.notNull(resourceLocation, "Resource location must not be null"); if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); ClassLoader cl = ClassUtils.getDefaultClassLoader(); URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { String description = "class path resource [" + path + "]"; throw new FileNotFoundException( description + " cannot be resolved to URL because it does not exist"); } return url; } try { // try URL return new URL(resourceLocation); } catch (MalformedURLException ex) { // no URL -> treat as file path try { return new File(resourceLocation).toURI().toURL(); } catch (MalformedURLException ex2) { throw new FileNotFoundException("Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path"); } } }
From source file:com.dianping.resource.io.PathResource.java
/** * This implementation opens a InputStream for the underlying file. * @see java.nio.file.spi.FileSystemProvider#newInputStream(java.nio.file.Path, java.nio.file.OpenOption...) */// ww w. ja va2s .c o m @Override public InputStream getInputStream() throws IOException { if (!exists()) { throw new FileNotFoundException(getPath() + " (No such file or directory)"); } if (Files.isDirectory(this.path)) { throw new FileNotFoundException(getPath() + " (Is a directory)"); } return Files.newInputStream(this.path); }
From source file:it.cnr.isti.thematrix.mapping.utils.TempFileManager.java
/** * Delete all temporary files registered so far and forget them. In case an error is returned, processing is * interrupted; the file triggering the error is the first of the list; it should be safe to call the method can be * called again.// w ww. j av a 2s. co m * * @throws SecurityException */ public static void deleteAllFiles() throws SecurityException, FileNotFoundException { for (String name : filenameList) { File f = new File(name); if (!f.exists()) throw new FileNotFoundException("Temporary file " + name + " not found for deletion"); else { LogST.logP(2, "Deleting Temporary File " + name); f.delete(); // filenameList.remove(name); error: we don't have the reference to the iterator here... } } filenameList = new ArrayList<String>(); }
From source file:de.fiz.ddb.aas.util.AasConfiguration.java
/** * Get an InputStream for the given file. * * @param filename The name of the file. * @return The InputStream or null if the file could not be located. * @throws FileNotFoundException If access to the specified file fails. */// w w w . ja va 2s .c o m private static InputStream getInputStream(final String filename) throws IOException, FileNotFoundException { final ResourcePatternResolver applicationContext = new ClassPathXmlApplicationContext(new String[] {}); final Resource[] resource = applicationContext.getResources("classpath*:" + filename); if (resource.length == 0) { throw new FileNotFoundException("Unable to find file '" + filename + "' in classpath."); } return resource[0].getInputStream(); }
From source file:com.xafero.vee.cmd.MainApp.java
private static void execute(String fileName) throws FileNotFoundException, ScriptException { File file = (new File(fileName)).getAbsoluteFile(); if (!file.exists()) throw new FileNotFoundException("There's no file named '" + file + "'!"); String extension = Files.getExtension(file); ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByExtension(extension); Bindings env = engine.createBindings(); inject(env, file);/* w w w .jav a2s .com*/ try { Object result = engine.eval(new FileReader(file), env); if (result != null) System.out.println(result.toString()); } catch (ScriptException e) { throw e; } }
From source file:de.decidr.model.commands.tenant.CreateWorkflowModelCommand.java
/** * Creates the DWDL xml data for a new, empty workflow model using the * template found in the resources folder. * /* ww w. jav a2s .c o m*/ * @param tenantName * name of the tenant that owns the workflow model - required to * set the target namespace. * @param id * id of the new workflow model. * @param name * name of the new workflow model * @return raw xml data of the new workflow model (created by unmarshalling * the template then marshalling it again) * @throws IOException */ protected byte[] createNewWorkflowModelXml(String tenantName, Long id, String name) throws IOException { if ((tenantName == null) || (tenantName.isEmpty())) { throw new IllegalArgumentException("Tenant name cannot be null or empty"); } if (id == null) { throw new IllegalArgumentException("Workflow model id cannot be null"); } if (name == null) { throw new IllegalArgumentException("Workflow model name cannot be null"); } /** * Modify the template where necessary */ InputStream templateStream = null; templateStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("templates/NewWorkflowModel.template.xml"); if (templateStream == null) { throw new FileNotFoundException("New workflow model template was not found."); } byte[] template = IOUtils.toByteArray(templateStream); TWorkflow workflowModel = XmlTools.unmarshalJaxbEntity(template, TWorkflow.class); workflowModel.setName(name); workflowModel.setTargetNamespace(StringConventions.getWorkflowTargetNamespace(id)); workflowModel.setId(id); return XmlTools.marshalJaxbEntityIntoByteArray(new ObjectFactory().createWorkflow(workflowModel)); }
From source file:com.jaeksoft.searchlib.index.ObjectStorageDirectory.java
private ObjectMeta getObjectMeta(final String name) throws IOException { try {// w ww . ja va 2 s. c o m ObjectMeta meta = SwiftProtocol.headObject(httpDownloader, swiftToken, container, name); if (meta == null) throw new FileNotFoundException("File not found: " + name); return meta; } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } }
From source file:monasca.common.middleware.HttpClientPoolFactory.java
private static KeyStore loadKeystore(String type, String keyStore, String keyPass) throws Exception { final KeyStore ks = KeyStore.getInstance("jks"); if ((keyStore != null) && !keyStore.isEmpty()) { File keystoreFile = new File(keyStore); if (!keystoreFile.canRead()) { throw new FileNotFoundException(String.format("%s '%s' is not readable", type, keyStore)); }//www. ja v a2 s . c o m try (FileInputStream is1 = new FileInputStream(keystoreFile)) { ks.load(is1, keyPass.toCharArray()); } catch (Exception e) { String errorMessage = String.format("Unable to open %s '%s': %s", type, keyStore, e.getMessage()); logger.error(errorMessage); throw new Exception(errorMessage, e); } } else { ks.load(null, null); } return ks; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageError.java
/** * Read the error message from the file errorlog.<transaction>.txt in the * "metadata" directory for the given package identifier. * /* ww w . ja v a2 s. co m*/ * @param packageId * The data package identifier * @param transaction * The transaction identifier * @return The error message * @throws FileNotFoundException */ public String readError(String transaction) throws FileNotFoundException { String error = null; String errorPath = errorDir + "/"; String errorName = transaction + ".txt"; File file = new File(errorPath + errorName); if (!file.exists()) { String gripe = "The error file " + errorName + " was not found!"; throw new FileNotFoundException(gripe); } try { error = FileUtils.readFileToString(file, "UTF-8"); } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } return error; }
From source file:cn.org.rapid_framework.generator.util.ResourceHelper.java
/** * Resolve the given resource location to a <code>java.net.URL</code>. * <p>Does not check whether the URL actually exists; simply returns * the URL that the given location would correspond to. * @param resourceLocation the resource location to resolve: either a * "classpath:" pseudo URL, a "file:" URL, or a plain file path * @return a corresponding URL object/* w ww. j av a 2s . c o m*/ * @throws FileNotFoundException if the resource cannot be resolved to a URL */ public static URL getURL(String resourceLocation) throws FileNotFoundException { if (resourceLocation == null) throw new IllegalArgumentException("Resource URL must not be null"); if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); URL url = ClassHelper.getDefaultClassLoader().getResource(path); if (url == null) { String description = "class path resource [" + path + "]"; throw new FileNotFoundException( description + " cannot be resolved to URL because it does not exist"); } return url; } try { // try URL return new URL(resourceLocation); } catch (MalformedURLException ex) { // no URL -> treat as file path try { return new File(resourceLocation).toURI().toURL(); } catch (MalformedURLException ex2) { throw new FileNotFoundException("Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path"); } } }