List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:org.wrml.runtime.format.application.schema.json.JsonSchemaLoader.java
public JsonSchema load(final File file) throws IOException { if (file == null) { throw new FileNotFoundException("The JSON schema file is null."); }/* w w w . j a v a2s . c om*/ if (!file.exists()) { throw new FileNotFoundException( "The JSON schema file named \"" + file.getAbsolutePath() + "\" does not exist."); } final InputStream in = FileUtils.openInputStream(file); final JsonSchema jsonSchema = load(in, null); IOUtils.closeQuietly(in); return jsonSchema; }
From source file:jag.sftp.VirtualFileSystem.java
private static String getNFSHomeDirectory() throws FileNotFoundException { try {/*from ww w . ja v a2 s.c om*/ if (Thread.currentThread() instanceof SshThread && SshThread.hasUserContext()) { NativeAuthenticationProvider nap = NativeAuthenticationProvider.getInstance(); return nap.getHomeDirectory(SshThread.getCurrentThreadUser()); } else { throw new FileNotFoundException("There is no user logged in"); } } catch (IOException e) { throw new FileNotFoundException(e.getMessage()); } }
From source file:at.tfr.securefs.util.Main.java
public void parseOpts(String[] args) throws Exception { List<String> argList = Arrays.asList(args); Iterator<String> iter = argList.iterator(); if (args.length == 0) { System.out.println("Usage: [options] <file>"); System.out.println("<file>: file to use for de/encryption"); System.out.println("Options:"); System.out.println("\t-t\tTest using test key with file"); System.out.println("\t-d\tdecrypt file with test key - default"); System.out.println("\t-e\tencrypt file with test key"); System.out.println("\t-s <salt> \tsalt - default: use file name"); System.out.println("\t-b <path> \base path for file access, default use ClassLoader roots"); System.out.println("\t-o <outFile> \tfile to write to, relative to basePath"); System.exit(0);/*from w w w . j av a 2 s . c om*/ } while (iter.hasNext()) { String a = iter.next(); switch (a) { case "-t": test = true; break; case "-d": mode = Cipher.DECRYPT_MODE; break; case "-e": mode = Cipher.ENCRYPT_MODE; break; case "-s": configuration.setSalt(iter.next()); break; case "-b": basePath = new File(iter.next()).toPath(); break; case "-o": outFile = iter.next(); break; default: file = a; } } if (file == null) throw new FileNotFoundException("no file defined"); if (basePath == null) { URL resource = this.getClass().getResource("/" + file); if (resource == null) throw new FileNotFoundException("cannot find basePath for file: " + file); URI uri = resource.toURI(); String absolutePath = new File(uri).getAbsolutePath(); basePath = new File(absolutePath).getParentFile().toPath(); } }
From source file:com.chigix.autosftp.Application.java
public static void watchDir(Path dir) throws Exception { // The monitor will perform polling on the folder every 5 seconds final long pollingInterval = 5 * 1000; File folder = dir.toFile();// w ww . j ava 2s . c o m if (!folder.exists()) { // Test to see if monitored folder exists throw new FileNotFoundException("Directory not found: " + dir); } FileAlterationObserver observer = new FileAlterationObserver(folder); FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval); FileAlterationListener listener = new FileAlterationListenerAdaptor() { // Is triggered when a file is created in the monitored folder @Override public void onFileCreate(File file) { Path relativePath = localPath.toAbsolutePath().normalize() .relativize(file.getAbsoluteFile().toPath().normalize()); System.out.println("File created: " + relativePath); final String destPath = remotePath.resolve(relativePath).normalize().toString().replace('\\', '/'); ArrayList<String> lackDirs = new ArrayList<>(); String tmpParentPath = destPath; while (!tmpParentPath.equals("/") && !tmpParentPath.equals("\\")) { tmpParentPath = new File(tmpParentPath).getParentFile().toPath().toString().replace('\\', '/'); try { sftpChannel.cd(tmpParentPath); } catch (SftpException ex) { if (ex.id == SSH_FX_NO_SUCH_FILE) { lackDirs.add(tmpParentPath); continue; } Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } break; } for (int i = lackDirs.size() - 1; i > -1; i--) { try { sftpChannel.mkdir(lackDirs.get(i)); } catch (SftpException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); System.err.println(destPath + " Creating Fail."); return; } } InputStream fi = null; try { fi = new FileInputStream(file); sftpChannel.put(fi, destPath, 644); } catch (FileNotFoundException ex) { System.out.println("File: " + file.getAbsolutePath() + " not exists."); return; } catch (SftpException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } finally { if (fi != null) { try { fi.close(); } catch (IOException ex) { } } } System.out.println("File Uploaded: " + destPath); } // Is triggered when a file is deleted from the monitored folder @Override public void onFileDelete(File file) { if (file.exists()) { return; } Path relativePath = localPath.toAbsolutePath().normalize() .relativize(file.getAbsoluteFile().toPath().normalize()); System.out.println("File Deleted: " + relativePath); final String destPath = remotePath.resolve(relativePath).normalize().toString().replace('\\', '/'); try { sftpChannel.rm(destPath); } catch (SftpException ex) { if (ex.id == SSH_FX_NO_SUCH_FILE) { } else { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Remote Deleted: " + relativePath); } @Override public void onFileChange(File file) { this.onFileCreate(file); } }; observer.addListener(listener); monitor.addObserver(observer); monitor.start(); }
From source file:net.dmulloy2.ultimatearena.api.ArenaLoader.java
public final ArenaDescription getArenaDescription(File file) throws InvalidArenaException { Validate.notNull(file, "file cannot be null!"); try (Closer closer = new Closer()) { JarFile jar = closer.register(new JarFile(file)); JarEntry entry = jar.getJarEntry("arena.yml"); if (entry == null) throw new InvalidArenaException(new FileNotFoundException("Jar does not contain arena.yml")); InputStream stream = closer.register(jar.getInputStream(entry)); Map<?, ?> map = (Map<?, ?>) yaml.load(stream); String name = (String) map.get("name"); Validate.notNull(name, "Missing required key: name"); Validate.isTrue(name.matches("^[A-Za-z0-9 _.-]+$"), "Name '" + name + "' contains invalid characters"); String main = (String) map.get("main"); Validate.notNull(main, "Missing required key: main"); String version = (String) map.get("version"); Validate.notNull(version, "Missing required key: version"); String author = (String) map.get("author"); if (author == null) author = "Unascribed"; String stylized = (String) map.get("stylized"); if (stylized == null) stylized = name;/* ww w .j ava2s .co m*/ return new ArenaDescription(name, main, stylized, version, author); } catch (InvalidArenaException ex) { throw ex; } catch (Throwable ex) { throw new InvalidArenaException("Failed to read arena.yml from " + file.getName(), ex); } }
From source file:cz.autoclient.league_of_legends.DataLoader.java
public static String stringFromFile(File file) throws FileNotFoundException { char[] buff = new char[(int) file.length()]; try {/*ww w . j ava2 s . c o m*/ (new FileReader(file)).read(buff); } catch (IOException e) { throw new FileNotFoundException("Invalid file."); } return new StringBuilder().append(buff).toString(); }
From source file:jenkins.plugins.ivyreport.IvyAccess.java
/** * Will only copy the file from the repository if its last modified time * exceeds what the instance thinks is the last recorded modified time of * the localFile, which is the local backup ivy file copy. For this to * operate properly for remoting circumstances, the master and slave * instances must be reasonably time synchronized. * //from w w w . j a v a2s . co m * @param source * Workspace root Directory * @param target * The local file to be copied to * @return true iff the file was actually copied * @throws IOException * If unable to access/copy the workspace ivy file * @throws InterruptedException * If interrupted while accessing the workspace ivy file */ private boolean copyIvyFileFromWorkspaceIfNecessary(FilePath source, File target) throws IOException, InterruptedException { boolean copied = false; if (source != null) { // Unless the workspace is non-null we can not // copy a new ivy file // Copy the ivy file from the workspace (possibly at a slave) to the // projects dir (at Master) FilePath backupCopy = new FilePath(target); long flastModified = source.lastModified(); if (flastModified == 0l) throw new FileNotFoundException("Can't stat file " + source); if (flastModified > backupCopy.lastModified()) { source.copyTo(backupCopy); target.setLastModified(flastModified); copied = true; LOGGER.info("Copied the workspace ivy file to backup"); } } return copied; }
From source file:eu.scape_project.archiventory.utils.IOUtils.java
public static byte[] getBytesFromFile(String filePath) throws IOException { File file = new File(filePath); if (!file.exists()) { throw new FileNotFoundException("File not available"); }// ww w . j a v a 2s.c o m InputStream is = null; byte[] bytes = null; try { is = new FileInputStream(file); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IllegalArgumentException("File object is too large"); } bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } } catch (IOException ex) { logger.error("I/O Error", ex); } finally { if (is != null) { try { is.close(); } catch (IOException _) { // ignore } } } return bytes; }
From source file:org.jodconverter.office.OnlineOfficeManagerPoolEntry.java
private static File getFile(final String resourceLocation) throws FileNotFoundException { Validate.notNull(resourceLocation, "Resource location must not be null"); if (resourceLocation.startsWith("classpath:")) { final String path = resourceLocation.substring("classpath:".length()); final String description = "class path resource [" + path + "]"; final ClassLoader cl = getDefaultClassLoader(); final URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path because it does not exist"); }//from www . j a va 2 s .c o m return getFile(url.toString()); } try { // try URL return getFile(new URL(resourceLocation)); } catch (MalformedURLException ex) { // no URL -> treat as file path return new File(resourceLocation); } }
From source file:de.tuebingen.uni.sfs.germanet.api.StaxLoader.java
/** * Loads all synset files or streams (depending on what exists) and then all relation files. * @throws java.io.FileNotFoundException * @throws javax.xml.stream.XMLStreamException *//* ww w .j a v a2s.com*/ protected void load() throws XMLStreamException { if (this.germaNetDir != null) { // load GermaNet from file FilenameFilter filter = new SynsetFilter(); //get only synset files File[] germaNetFiles = germaNetDir.listFiles(filter); try { if (germaNetFiles == null || germaNetFiles.length == 0) { throw new FileNotFoundException( "Unable to load GermaNet from \"" + this.germaNetDir.getPath() + "\""); } // load all synset files first with a SynsetLoader for (File germaNetFile : germaNetFiles) { logger.debug("Loading " + germaNetFile.getName() + "..."); synLoader.loadSynsets(germaNetFile); } filter = new RelationFilter(); //get only relatin files germaNetFiles = germaNetDir.listFiles(filter); // load relations with a RelationLoader for (File germaNetFile : germaNetFiles) { logger.debug("Loading " + germaNetFile.getName() + "..."); relLoader.loadRelations(germaNetFile); } logger.debug("Done."); } catch (FileNotFoundException ex) { Logger.getLogger(StaxLoader.class.getName()).log(Level.SEVERE, null, ex); } } else { // load GermaNet from InputStream list if (germaNetStreams == null || germaNetStreams.isEmpty()) { try { throw new StreamCorruptedException("Unable to load GermaNet from input stream \"" + this.germaNetStreams.toString() + "\""); } catch (StreamCorruptedException ex) { Logger.getLogger(StaxLoader.class.getName()).log(Level.SEVERE, null, ex); } } // load all synset input streams first with a SynsetLoader for (int i = 0; i < germaNetStreams.size(); i++) { if (xmlNames.get(i).endsWith("xml") && (xmlNames.get(i).startsWith("nomen") || xmlNames.get(i).startsWith("verben") || xmlNames.get(i).startsWith("adj"))) { logger.debug("Loading input stream " + xmlNames.get(i) + "..."); synLoader.loadSynsets(germaNetStreams.get(i)); } } // load relations with a RelationLoader for (int i = 0; i < germaNetStreams.size(); i++) { if (xmlNames.get(i).equals("gn_relations.xml")) { logger.debug("Loading input stream " + xmlNames.get(i) + "..."); relLoader.loadRelations(germaNetStreams.get(i)); } } logger.debug("Done."); } }