List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:azkaban.jobtype.ReportalDataCollector.java
@Override protected void runReportal() throws Exception { System.out.println("Reportal Data Collector: Initializing"); String outputFileSystem = props.getString("reportal.output.filesystem", "local"); String outputBase = props.getString("reportal.output.dir", "/tmp/reportal"); String execId = props.getString(CommonJobProperties.EXEC_ID); int jobNumber = prop.getInt("reportal.job.number"); List<Exception> exceptions = new ArrayList<Exception>(); for (int i = 0; i < jobNumber; i++) { InputStream tempStream = null; IStreamProvider outputProvider = null; OutputStream persistentStream = null; try {/*from w w w . ja va2 s. co m*/ String jobTitle = prop.getString("reportal.job." + i); System.out.println("Reportal Data Collector: Job name=" + jobTitle); String tempFileName = jobTitle + ".csv"; // We add the job index to the beginning of the job title to allow us to sort the files correctly. String persistentFileName = i + "-" + tempFileName; String subPath = "/" + execId + "/" + persistentFileName; String locationFull = (outputBase + subPath).replace("//", "/"); String locationTemp = ("./reportal/" + tempFileName).replace("//", "/"); File tempOutput = new File(locationTemp); if (!tempOutput.exists()) { throw new FileNotFoundException("File: " + tempOutput.getAbsolutePath() + " does not exist."); } // Copy file to persistent saving location System.out.println("Reportal Data Collector: Saving output to persistent storage"); System.out .println("Reportal Data Collector: FS=" + outputFileSystem + ", Location=" + locationFull); // Open temp file tempStream = new BufferedInputStream(new FileInputStream(tempOutput)); // Open file from HDFS if specified outputProvider = ReportalUtil.getStreamProvider(outputFileSystem); persistentStream = outputProvider.getFileOutputStream(locationFull); // Copy it IOUtils.copy(tempStream, persistentStream); } catch (Exception e) { System.out.println("Reportal Data Collector: Data collection failed. " + e.getMessage()); e.printStackTrace(); exceptions.add(e); } finally { IOUtils.closeQuietly(tempStream); IOUtils.closeQuietly(persistentStream); try { outputProvider.cleanUp(); } catch (IOException e) { e.printStackTrace(); } } } if (exceptions.size() > 0) { throw new CompositeException(exceptions); } System.out.println("Reportal Data Collector: Ended successfully"); }
From source file:de.jcup.egradle.core.process.SimpleProcessExecutor.java
@Override public int execute(ProcessConfiguration wdProvider, EnvironmentProvider envProvider, ProcessContext processContext, String... commands) throws IOException { notNull(wdProvider, "'wdProvider' may not be null"); notNull(envProvider, "'envProvider' may not be null"); String wd = wdProvider.getWorkingDirectory(); /* Working directory */ File workingDirectory = null; if (StringUtils.isNotBlank(wd)) { workingDirectory = new File(wd); }/*ww w . ja va2s .co m*/ if (workingDirectory != null) { if (!workingDirectory.exists()) { throw new FileNotFoundException("Working directory does not exist:" + workingDirectory); } } /* Create process with dedicated environment */ ProcessBuilder pb = new ProcessBuilder(commands); Map<String, String> env = envProvider.getEnvironment(); /* init environment */ if (env != null) { Map<String, String> pbEnv = pb.environment(); for (String key : env.keySet()) { pbEnv.put(key, env.get(key)); } } /* init working directory */ pb.directory(workingDirectory); pb.redirectErrorStream(true); Date started = new Date(); Process p = startProcess(pb); ProcessTimeoutTerminator timeoutTerminator = null; if (timeOutInSeconds != ENDLESS_RUNNING) { timeoutTerminator = new ProcessTimeoutTerminator(p, outputHandler, timeOutInSeconds); timeoutTerminator.start(); } ProcessCancelTerminator cancelTerminator = new ProcessCancelTerminator(p, processContext.getCancelStateProvider()); Thread cancelCheckThread = new Thread(cancelTerminator, "process-cancel-terminator"); cancelCheckThread.start(); handleProcessStarted(envProvider, p, started, workingDirectory, commands); handleOutputStreams(p, timeoutTerminator, processContext.getCancelStateProvider()); /* wait for execution */ try { while (isAlive(p)) { waitFor(p); } } catch (InterruptedException e) { /* ignore */ } /* done */ int exitValue = p.exitValue(); handleProcessEnd(p); return exitValue; }
From source file:io.wcm.caravan.commons.httpclient.impl.helpers.CertificateLoader.java
/** * Get key manager factory//w w w .j a va2s .com * @param keyStoreFilename Keystore file name * @param storeProperties store properties * @return Key manager factory * @throws IOException * @throws GeneralSecurityException */ public static KeyManagerFactory getKeyManagerFactory(String keyStoreFilename, StoreProperties storeProperties) throws IOException, GeneralSecurityException { InputStream is = getResourceAsStream(keyStoreFilename); if (is == null) { throw new FileNotFoundException("Certificate file not found: " + getFilenameInfo(keyStoreFilename)); } try { return getKeyManagerFactory(is, storeProperties); } finally { try { is.close(); } catch (IOException ex) { // ignore } } }
From source file:edu.northwestern.bioinformatics.studycalendar.osgi.OsgiLayerIntegratedTestHelper.java
private synchronized static File findProjectRootDirectory() throws FileNotFoundException { if (projectRoot == null) { File buildfile;//ww w . j av a2s.com projectRoot = new File("."); do { buildfile = new File(projectRoot, "buildfile"); if (buildfile.exists()) { return projectRoot; } projectRoot = new File(projectRoot, ".."); } while (projectRoot.exists() && projectRoot.isDirectory()); projectRoot = null; throw new FileNotFoundException( String.format("Could not find project directory. Started from %s and walked up to %s.", new File("."), projectRoot)); } return projectRoot; }
From source file:com.asakusafw.runtime.stage.AbstractCleanupStageClient.java
@Override protected int execute(String[] args) throws IOException, InterruptedException { Configuration conf = getConf(); Path path = getPath(conf);/* ww w. j a v a 2s .com*/ FileSystem fileSystem = FileSystem.get(path.toUri(), conf); String info = MessageFormat.format("batchId={0}, flowId={1}, executionId={2}, operationId={3}, path={4}", //$NON-NLS-1$ getBatchId(), getFlowId(), getExecutionId(), getOperationId(), path); try { LOG.info(MessageFormat.format("Searching for cleanup target: {0}", info)); long start = System.currentTimeMillis(); if (RuntimeContext.get().isSimulation()) { LOG.info(MessageFormat.format( "Skip deleting cleanup target because current execution is in simulation mode: {0}", info)); } else { FileStatus stat = fileSystem.getFileStatus(path); if (stat == null) { throw new FileNotFoundException(path.toString()); } LOG.info(MessageFormat.format("Start deleting cleanup target: {0}", info)); if (fileSystem.delete(path, true) == false) { throw new IOException("FileSystem.delete() returned false"); } } long end = System.currentTimeMillis(); LOG.info(MessageFormat.format("Finish deleting cleanup target: {0}, elapsed={1}ms", info, end - start)); return 0; } catch (FileNotFoundException e) { LOG.warn(MessageFormat.format("Cleanup target is missing: {0}", info)); return 0; } catch (IOException e) { LOG.warn(MessageFormat.format("Failed to delete cleanup target: {0}", info), e); return 1; } finally { FileSystem.closeAll(); } }
From source file:fm.last.moji.local.LocalMojiFile.java
@Override public long length() throws IOException { if (!file.exists()) { throw new FileNotFoundException(file.getCanonicalPath()); }/*from w ww .j av a 2s . c o m*/ return file.length(); }
From source file:com.ikon.util.impexp.RepositoryExporter.java
/** * Performs a recursive repository content export with metadata *///w ww . java2 s . co m public static ImpExpStats exportDocuments(String token, String fldPath, File fs, String metadata, boolean history, Writer out, InfoDecorator deco) throws PathNotFoundException, AccessDeniedException, RepositoryException, FileNotFoundException, IOException, DatabaseException, ParseException, NoSuchGroupException, MessagingException { log.debug("exportDocuments({}, {}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, fs, metadata, history, out, deco }); ImpExpStats stats; try { FileLogger.info(BASE_NAME, "Start repository export from ''{0}'' to ''{1}''", fldPath, fs.getPath()); if (fs.exists()) { firstTime = true; stats = exportDocumentsHelper(token, fldPath, fs, metadata, history, out, deco); } else { throw new FileNotFoundException(fs.getPath()); } FileLogger.info(BASE_NAME, "Repository export finalized"); } catch (PathNotFoundException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "PathNotFoundException ''{0}''", e.getMessage()); throw e; } catch (AccessDeniedException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "AccessDeniedException ''{0}''", e.getMessage()); throw e; } catch (FileNotFoundException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "FileNotFoundException ''{0}''", e.getMessage()); throw e; } catch (RepositoryException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "RepositoryException ''{0}''", e.getMessage()); throw e; } catch (IOException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "IOException ''{0}''", e.getMessage()); throw e; } catch (DatabaseException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "DatabaseException ''{0}''", e.getMessage()); throw e; } catch (ParseException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "ParseException ''{0}''", e.getMessage()); throw e; } catch (NoSuchGroupException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "NoSuchGroupException ''{0}''", e.getMessage()); throw e; } catch (MessagingException e) { log.error(e.getMessage(), e); FileLogger.error(BASE_NAME, "MessagingException ''{0}''", e.getMessage()); throw e; } log.debug("exportDocuments: {}", stats); return stats; }
From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java
File findPackagedArtifact(File startingDirectory) throws IOException { if (!isMavenProjectDirectory(startingDirectory)) { throw new IllegalStateException(startingDirectory + " does not contain a pom.xml file"); }/*from www. ja va2s . c o m*/ File rootMavenProjectDir = findRootMavenProjectDir(startingDirectory.getCanonicalFile()); if (log.isTraceEnabled()) log.trace("Starting local artifact search from " + rootMavenProjectDir.getAbsolutePath()); File found = findInDirectoryTree(artifactName, rootMavenProjectDir); if (found == null) { throw new FileNotFoundException( "Cannot find the artifact <" + artifactName + "> with groupId <" + groupId + ">"); } return found; }
From source file:com.chiorichan.plugin.loader.JavaPluginLoader.java
public Plugin loadPlugin(File file) throws InvalidPluginException { Validate.notNull(file, "File cannot be null"); if (!file.exists()) { throw new InvalidPluginException(new FileNotFoundException(file.getPath() + " does not exist")); }/* w ww .j a v a 2s .c o m*/ PluginDescriptionFile description; try { description = getPluginDescription(file); } catch (InvalidDescriptionException ex) { throw new InvalidPluginException(ex); } File dataFolder = new File(file.getParentFile(), description.getName()); File oldDataFolder = getDataFolder(file); // Found old data folder if (dataFolder.equals(oldDataFolder)) { // They are equal -- nothing needs to be done! } else if (dataFolder.isDirectory() && oldDataFolder.isDirectory()) { PluginManager.getLogger().log(Level.INFO, String.format("While loading %s (%s) found old-data folder: %s next to the new one: %s", description.getName(), file, oldDataFolder, dataFolder)); } else if (oldDataFolder.isDirectory() && !dataFolder.exists()) { if (!oldDataFolder.renameTo(dataFolder)) { throw new InvalidPluginException( "Unable to rename old data folder: '" + oldDataFolder + "' to: '" + dataFolder + "'"); } PluginManager.getLogger().log(Level.INFO, String.format("While loading %s (%s) renamed data folder: '%s' to '%s'", description.getName(), file, oldDataFolder, dataFolder)); } if (dataFolder.exists() && !dataFolder.isDirectory()) { throw new InvalidPluginException( String.format("Projected datafolder: '%s' for %s (%s) exists and is not a directory", dataFolder, description.getName(), file)); } List<String> depend = description.getDepend(); if (depend == null) { depend = ImmutableList.<String>of(); } for (String pluginName : depend) { if (loaders == null) { throw new UnknownDependencyException(pluginName); } PluginClassLoader current = loaders.get(pluginName); if (current == null) { throw new UnknownDependencyException(pluginName); } } PluginClassLoader loader; try { loader = new PluginClassLoader(this, getClass().getClassLoader(), description, dataFolder, file); } catch (InvalidPluginException ex) { throw ex; } catch (Throwable ex) { throw new InvalidPluginException(ex); } loaders.put(description.getName(), loader); return loader.plugin; }
From source file:hd3gtv.mydmam.auth.AuthenticationBackend.java
public static void refreshConfiguration() throws Exception { if (Configuration.global.isElementExists("auth") == false) { throw new NullPointerException("Can't found \"auth\" element in configuration"); }// w ww .j a v a 2 s. c o m if (Configuration.global.isElementKeyExists("auth", "backend") == false) { throw new NullPointerException("Can't found \"auth/backend\" element in configuration"); } List<LinkedHashMap<String, ?>> elements = Configuration.global.getListMapValues("auth", "backend"); if (elements == null) { throw new NullPointerException("No items for \"auth/backend\" element in configuration"); } force_select_domain = Configuration.global.getValueBoolean("auth", "force_select_domain"); authenticators = new ArrayList<Authenticator>(elements.size()); authenticators_domains = new ArrayList<String>(elements.size()); LinkedHashMap<String, ?> configuration_element; File auth_file; for (int pos = 0; pos < elements.size(); pos++) { configuration_element = elements.get(pos); String element_source = (String) configuration_element.get("source"); if (element_source.equals("local")) { String path = (String) configuration_element.get("path"); auth_file = new File(path); if (auth_file.exists() == false) { if (auth_file.isAbsolute() == false) { if (auth_file.getParentFile().getName().equals("conf") & Configuration .getGlobalConfigurationDirectory().getParentFile().getName().equals("conf")) { /** * SQLite file is located in Play conf directory, and Play /app.d/ is also located in conf directory. * We consider that conf directory is the same. */ auth_file = new File(Configuration.getGlobalConfigurationDirectory().getParent() + File.separator + auth_file.getName()); } } } if (auth_file.exists() == false) { throw new FileNotFoundException(path); } String masterkey = (String) configuration_element.get("masterkey"); authenticators.add(new AuthenticatorLocalsqlite(auth_file, masterkey)); String label = (String) configuration_element.get("label"); authenticators_domains.add(label); } else if (element_source.equals("ad")) { String domain = (String) configuration_element.get("domain"); String server = (String) configuration_element.get("server"); int port = (Integer) configuration_element.get("port"); authenticators.add(new AuthenticatorActivedirectory(domain, server, port)); authenticators_domains.add(domain); } else { Log2.log.error("Can't import \"auth/backend\" " + (pos + 1) + " configuration item", null, new Log2Dump("item", configuration_element.toString())); } } if (authenticators.isEmpty()) { throw new NullPointerException("No authentication backend is correctly set"); } }