List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:cc.solr.lucene.store.hdfs.HdfsFileReader.java
public HdfsFileReader(FileSystem fileSystem, Path path, int bufferSize) throws IOException { if (!fileSystem.exists(path)) { throw new FileNotFoundException(path.toString()); }/*from ww w .jav a2 s. c o m*/ FileStatus fileStatus = fileSystem.getFileStatus(path); _hdfsLength = fileStatus.getLen(); _inputStream = fileSystem.open(path, bufferSize); // read meta blocks _inputStream.seek(_hdfsLength - 16); int numberOfBlocks = _inputStream.readInt(); _length = _inputStream.readLong(); int version = _inputStream.readInt(); if (version != VERSION) { throw new RuntimeException("Version of file [" + version + "] does not match reader [" + VERSION + "]"); } _inputStream.seek(_hdfsLength - 16 - (numberOfBlocks * 24)); // 3 longs per // block _metaBlocks = new ArrayList<HdfsMetaBlock>(numberOfBlocks); for (int i = 0; i < numberOfBlocks; i++) { HdfsMetaBlock hdfsMetaBlock = new HdfsMetaBlock(); hdfsMetaBlock.readFields(_inputStream); _metaBlocks.add(hdfsMetaBlock); } seek(0); }
From source file:uk.co.threeonefour.ifictionary.svc.GameServiceImpl.java
@Override public InputStream getFile(Long gameId) throws IOException { GameInfo gameInfo = gameInfoDao.get(gameId); if (gameInfo != null) { return gameFileDao.read(gameInfo.getFileId()); }// w ww . ja va 2s . co m throw new FileNotFoundException("" + gameId); }
From source file:com.hypersocket.server.handlers.impl.FileContentHandler.java
protected File resolveFile(String path) throws FileNotFoundException { for (File p : baseDirs) { File f = new File(p, path); if (log.isDebugEnabled()) { log.debug("Attempting to resolve " + f.getAbsolutePath()); }// w w w.ja v a2 s . co m if (f.exists()) { if (log.isDebugEnabled()) { log.debug("Resolved " + f.getAbsolutePath()); } return f; } } throw new FileNotFoundException("Unable to resolve path " + path); }
From source file:com.lazerycode.selenium.filedownloader.CheckFileHash.java
/** * Performs a expectedFileHash check on a File. * * @return//from w ww . j a va 2 s.c o m * @throws IOException */ public boolean hasAValidHash() throws IOException { if (this.fileToCheck == null) throw new FileNotFoundException("File to check has not been set!"); if (this.expectedFileHash == null || this.typeOfOfHash == null) throw new NullPointerException("Hash details have not been set!"); String actualFileHash = ""; boolean isHashValid = false; switch (this.typeOfOfHash) { case MD5: actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) isHashValid = true; break; case SHA1: actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) isHashValid = true; break; } // LOG.info("Filename = '" + this.fileToCheck.getName() + "'"); // LOG.info("Expected Hash = '" + this.expectedFileHash + "'"); //LOG.info("Actual Hash = '" + actualFileHash + "'"); return isHashValid; }
From source file:com.github.jknack.amd4j.ClasspathResourceLoader.java
@Override public String load(final ResourceURI uri) throws IOException { return process(uri, new StreamHandler<String>() { @Override//w w w. j a v a 2s. c o m public String handle(final InputStream in) throws IOException { if (in == null) { throw new FileNotFoundException("classpath:" + uri); } return IOUtils.toString(in, "UTF-8"); } }); }
From source file:net.leegorous.jsc.JavaScriptDocument.java
protected static Set configClasspath(File file, String content) throws FileNotFoundException { if (!file.isDirectory()) { file = file.getParentFile();//from w w w . j a v a 2 s . c o m } Matcher m = CLASSPATH_PATTERN.matcher(content); Set cp = null; if (m.find()) { cp = new HashSet(); do { String str = m.group(1); String path = FilenameUtils.concat(file.getAbsolutePath(), str); File p = new File(path); if (p.exists() && p.isDirectory()) { cp.add(p); } else { throw new FileNotFoundException(path + " from " + file.getAbsolutePath() + " + " + str); } } while (m.find()); } return cp; }
From source file:net.dmulloy2.ultimatearena.api.ArenaLoader.java
protected final ArenaType loadArenaType(File file) throws InvalidArenaException { Validate.notNull(file, "file cannot be null!"); if (!file.exists()) throw new InvalidArenaException(new FileNotFoundException(file.getPath() + " does not exist")); ArenaDescription description = getArenaDescription(file); ArenaClassLoader loader;//from w w w .ja v a 2s . c o m try { loader = loadClasses(description.getName(), file); } catch (MalformedURLException ex) { throw new InvalidArenaException("Failed to load classes from file " + file.getName(), ex); } Class<?> jarClass; try { jarClass = Class.forName(description.getMain(), true, loader); } catch (ClassNotFoundException ex) { throw new InvalidArenaException("Cannot find main class '" + description.getMain() + "'", ex); } Class<? extends ArenaType> clazz; try { clazz = jarClass.asSubclass(ArenaType.class); } catch (ClassCastException ex) { throw new InvalidArenaException("Main class '" + jarClass.getName() + "' does not extend ArenaType", ex); } try { ArenaType type = clazz.newInstance(); type.initialize(plugin, description, loader, file, new File(plugin.getDataFolder(), type.getName())); return type; } catch (Throwable ex) { throw new InvalidArenaException("Failed to create and initialize instance", ex); } }
From source file:atg.tools.dynunit.test.util.FileUtil.java
public static void copyDirectory(@NotNull String srcDir, @NotNull String dstDir, @NotNull final List<String> excludes) throws IOException { logger.entry(srcDir, dstDir, excludes); Validate.notEmpty(srcDir);// www . ja v a 2 s . c o m Validate.notEmpty(dstDir); final File source = new File(srcDir); if (!source.exists()) { throw logger.throwing(new FileNotFoundException(srcDir)); } final File destination = new File(dstDir); FileUtils.copyDirectory(source, destination, new FileFilter() { @Override public boolean accept(final File file) { return excludes.contains(file.getName()); } }); logger.exit(); }
From source file:org.cleverbus.admin.services.log.LogParser.java
public File[] getLogFiles(final DateTime date) throws FileNotFoundException { File logFolder = new File(logFolderPath); if (!logFolder.exists() || !logFolder.canRead()) { throw new FileNotFoundException("there is no readable log folder - " + logFolderPath); }/*ww w. ja v a 2 s .c o m*/ final String logDateFormatted = FILE_DATE_FORMAT.print(date); final long dateMillis = date.getMillis(); File[] files = logFolder.listFiles(new FileFilter() { @Override public boolean accept(File file) { String name = file.getName(); return name.endsWith(FILE_EXTENSION) // it's a log file && name.contains(logDateFormatted) // it contains the date in the name && file.lastModified() >= dateMillis; // and it's not older than the search date } }); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); if (files.length == 0) { Log.debug("No log files ending with {}, containing {}, modified after {}, at {}", FILE_EXTENSION, logDateFormatted, date, logFolderPath); } else { Log.debug("Found log files for {}: {}", date, files); } return files; }
From source file:com.sap.prd.mobile.ios.mios.PListAccessor.java
public String getStringValue(String key) throws IOException { if (!plist.exists()) { throw new FileNotFoundException("The Plist " + plist.getAbsolutePath() + " does not exist."); }/* w w w . j a va 2 s .c o m*/ try { String command = "/usr/libexec/PlistBuddy -c \"Print :" + key + "\" \"" + plist.getAbsolutePath() + "\""; System.out.println("[INFO] PlistBuddy Print command is: '" + command + "'."); String[] args = new String[] { "bash", "-c", command }; Process p = Runtime.getRuntime().exec(args); p.waitFor(); int exitValue = p.exitValue(); if (exitValue == 0) { InputStream is = p.getInputStream(); try { return new Scanner(is, Charset.defaultCharset().name()).useDelimiter("\\Z").next(); } finally { closeQuietly(is); } } String errorMessage = "<n/a>"; try { errorMessage = new Scanner(p.getErrorStream(), Charset.defaultCharset().name()).useDelimiter("\\Z") .next(); } catch (Exception ex) { System.out.println("[ERROR] Exception caught during retrieving error message of command '" + command + "': " + ex); } if (errorMessage.contains(":" + key + "\", Does Not Exist")) { // ugly string parsing above, but no other known way ... return null; } throw new IllegalStateException( "Execution of \"" + StringUtils.join(args, " ") + "\" command failed. Error message is: " + errorMessage + ". Return code was: '" + exitValue + "'."); } catch (InterruptedException e) { throw new RuntimeException(e); } }