List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialInitializerBean.java
private Properties retrieveModuleConfigs() throws IOException { Properties prop = new Properties(); InputStream properties = SpatialInitializerBean.class.getClassLoader().getResourceAsStream(PROP_FILE_NAME); if (properties != null) { prop.load(properties);/*from w w w . j av a 2s . c o m*/ return prop; } else { throw new FileNotFoundException("Property file '" + PROP_FILE_NAME + "' not found in the classpath"); } }
From source file:hudson.plugins.emailext.plugins.content.AbstractEvalContent.java
protected InputStream getFileInputStream(String fileName, String extension) throws FileNotFoundException { InputStream inputStream;/*from w w w .java 2 s .c o m*/ if (fileName.startsWith("managed:")) { String managedFileName = fileName.substring(8); try { inputStream = getManagedFile(managedFileName); } catch (NoClassDefFoundError e) { inputStream = null; } if (inputStream == null) { throw new FileNotFoundException(String.format("Managed file '%s' not found", managedFileName)); } return inputStream; } String fileExt = FilenameUtils.getExtension(fileName); // add default extension if needed if (fileExt.equals("")) { fileName += extension; } inputStream = getClass().getClassLoader() .getResourceAsStream("hudson/plugins/emailext/templates/" + fileName); if (inputStream == null) { File templateFile = new File(scriptsFolder(), fileName); // the file may have an extension, but not the correct one if (!templateFile.exists()) { fileName += extension; templateFile = new File(scriptsFolder(), fileName); } inputStream = new FileInputStream(templateFile); } return inputStream; }
From source file:io.cloudine.rhq.plugins.worker.ResourceUtils.java
/** * ? URL? {@link java.net.URL}? ./*from ww w. java 2 s .c o m*/ * * @param resourceLocation ? URL * @return ?? {@link java.net.URL} ? * @throws java.io.FileNotFoundException ?? ? */ public static URL getURL(String resourceLocation) throws FileNotFoundException { if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); URL url = ClassUtils.getDefaultClassLoader().getResource(path); if (url == null) { String description = "CLASSPATH [" + path + "]"; throw new FileNotFoundException(description + "? URL? ? . URL? ?? ?."); } return url; } try { // URL ? return new URL(resourceLocation); } catch (MalformedURLException e) { // no URL -> ? try { return new URL(FILE_URL_PREFIX + resourceLocation); } catch (MalformedURLException mue) { throw new FileNotFoundException(" [" + resourceLocation + "]? URL? ??? ? ? ."); } } }
From source file:hu.bme.mit.trainbenchmark.benchmark.fourstore.driver.FourStoreDriver.java
@Override public void read(final String modelPathWithoutExtension) throws IOException { final String modelPath = modelPathWithoutExtension + getExtension(); final File modelFile = new File(modelPath); if (!modelFile.exists()) { throw new FileNotFoundException(modelPath); }//w ww. jav a 2s . c om UnixUtils.execResourceScript("4s-import.sh", modelFile.getAbsolutePath(), environment, showCommandOutput); }
From source file:org.jboss.windup.reporting.ReportEngine.java
/** * Main processing method. //w w w .j a v a 2s. c om * @param inputLocation * @param outputLocation * @throws IOException */ public void process(File inputLocation, File outputLocation) throws IOException { if (!inputLocation.exists()) { throw new FileNotFoundException("ArchiveMetadata not found: " + inputLocation); } if (settings.isSource()) { //validate input and output. if (!inputLocation.exists() || !inputLocation.isDirectory()) { throw new IllegalArgumentException("Source input must be directory."); } if (outputLocation == null) { String outputName = inputLocation.getName() + "-doc"; String outputPathLoc = inputLocation.getParentFile().getAbsolutePath(); outputPathLoc = outputPathLoc + File.separator + outputName; //create output path... outputLocation = new File(outputPathLoc); LOG.info("Creating output path: " + outputLocation.getAbsolutePath()); LOG.info(" - To overwrite this in the future, use the -output parameter."); } if (!outputLocation.exists()) { FileUtils.forceMkdir(outputLocation); } ArchiveMetadata am = windupEngine.processSourceDirectory(inputLocation, outputLocation); generateReport(am, outputLocation); } //if this isn't a source run, then we should run it as archive mode. else { if (inputLocation.isDirectory()) { batchInputDirectory(inputLocation); } else { // single archive processing. if (outputLocation == null) { //generate output based on input. outputLocation = generateArchiveOutputLocation(inputLocation); ArchiveMetadata amd = windupEngine.processArchive(inputLocation, outputLocation); generateReport(amd, outputLocation); } else { ArchiveMetadata amd = windupEngine.processArchive(inputLocation, outputLocation); generateReport(amd, outputLocation); } } } }
From source file:com.espirit.moddev.cli.testcommands.AbstractIntegrationTest.java
protected File getFirstSpiritFileSyncFolder(final File directory) throws FileNotFoundException { checkIsDirectory(directory);//from www. ja v a 2 s . c om final Collection<File> directories = FileUtils.listFilesAndDirs(testFolder.getRoot(), new NotFileFilter(TrueFileFilter.INSTANCE), DirectoryFileFilter.DIRECTORY); for (final File candidate : directories) { if (candidate.getName().equals(".FirstSpirit")) { return candidate; } } throw new FileNotFoundException( "Cannot find .FirstSpirit folder in directory " + directory.getAbsolutePath()); }
From source file:edu.lternet.pasta.datapackagemanager.dataserver.DataServerServlet.java
/** * Process a data download HEAD request using information that was generated * by the Data Package Manager service.//from www . j av a 2s . c o m */ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException { String dataToken = request.getParameter("dataToken"); String size = request.getParameter("size"); String objectName = request.getParameter("objectName"); if (dataToken == null || dataToken.isEmpty() || size == null || size.isEmpty() || objectName == null || objectName.isEmpty()) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { /* * Find out which directory the temporary data files are being * placed in by the Data Package Manager */ PropertiesConfiguration options = ConfigurationListener.getOptions(); String tmpDir = options.getString("datapackagemanager.tmpDir"); if (tmpDir == null || tmpDir.equals("")) { throw new ServletException("datapackagemanager.tmpDir property value was not specified."); } try { // reads input file from an absolute path String filePath = String.format("%s/%s", tmpDir, dataToken); File downloadFile = new File(filePath); if (!downloadFile.exists()) { String message = String.format("File not found: %s", filePath); throw new FileNotFoundException(message); } ServletContext context = getServletContext(); // gets MIME type of the file String mimeType = context.getMimeType(filePath); if (mimeType == null) { // set to binary type if MIME mapping not found mimeType = "application/octet-stream"; } // modifies response response.setContentType(mimeType); long length = Long.parseLong(size); if (length <= Integer.MAX_VALUE) { response.setContentLength((int) length); } else { response.addHeader("Content-Length", Long.toString(length)); } // forces download String headerKey = "Content-Disposition"; String headerValue = String.format("attachment; filename=\"%s\"", objectName); response.setHeader(headerKey, headerValue); } catch (FileNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:fr.landel.utils.io.InternalFileSystemUtils.java
/** * Copy a file.//from w w w. ja v a 2s.com * * @param src * The source file name * @param dest * The destination file name * @param removeSource * Remove the source after copy * @throws IOException * Exception thrown if problems occurs during coping */ protected static void copyFile(final File src, final File dest, final boolean removeSource) throws IOException { int bufferReadSize; final byte[] buffer = new byte[BUFFER_SIZE]; final File target; if (dest.isDirectory()) { target = new File(dest, src.getName()); } else { target = dest; } if (InternalFileSystemUtils.createDirectory(target.getParentFile())) { if (!src.getAbsolutePath().equals(dest.getAbsolutePath())) { final BufferedInputStream bis = IOStreamUtils.createBufferedInputStream(src); final BufferedOutputStream bos = IOStreamUtils.createBufferedOutputStream(target); while ((bufferReadSize = bis.read(buffer, 0, BUFFER_SIZE)) >= 0) { bos.write(buffer, 0, bufferReadSize); } CloseableManager.close(target); CloseableManager.close(src); if (removeSource && !src.delete()) { throw new IOException("Cannot remove the source file"); } } } else { throw new FileNotFoundException("destination directory doesn't exist and cannot be created"); } }
From source file:jenkins.model.RunIdMigrator.java
/** * Reverses the migration, in case you want to revert to the older format. * @param args one parameter, {@code $JENKINS_HOME} *//*from ww w.j ava 2 s.co m*/ public static void main(String... args) throws Exception { if (args.length != 1) { throw new Exception("pass one parameter, $JENKINS_HOME"); } File root = new File(args[0]); File jobs = new File(root, "jobs"); if (!jobs.isDirectory()) { throw new FileNotFoundException("no such $JENKINS_HOME " + root); } new RunIdMigrator().unmigrateJobsDir(jobs); }
From source file:eu.annocultor.common.Utils.java
public static List<File> expandFileTemplateFrom(File dir, String... pattern) throws IOException { List<File> files = new ArrayList<File>(); for (String p : pattern) { File fdir = new File(new File(dir, FilenameUtils.getFullPathNoEndSeparator(p)).getCanonicalPath()); if (!fdir.isDirectory()) throw new IOException("Error: " + fdir.getCanonicalPath() + ", expanded from directory " + dir.getCanonicalPath() + " and pattern " + p + " does not denote a directory"); if (!fdir.canRead()) throw new IOException("Error: " + fdir.getCanonicalPath() + " is not readable"); FileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(p)); File[] list = fdir.listFiles(fileFilter); if (list == null) throw new IOException("Error: " + fdir.getCanonicalPath() + " does not denote a directory or something else is wrong"); if (list.length == 0) throw new IOException("Error: no files found, template " + p + " from dir " + dir.getCanonicalPath() + " where we recognised " + fdir.getCanonicalPath() + " as path and " + fileFilter + " as file mask"); for (File file : list) { if (!file.exists()) { throw new FileNotFoundException( "File not found: " + file + " resolved to " + file.getCanonicalPath()); }//from ww w . j a v a 2 s. c o m } files.addAll(Arrays.asList(list)); } return files; }