List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:org.openmrs.module.facilitydata.util.BaseFacilityDataContextSensitiveTest.java
/** * Overrides superclass by specifying default values for common columns if needed * @see BaseModuleContextSensitiveTest#executeDataSet(String) *//* w ww.ja v a 2 s .c o m*/ @Override public void executeDataSet(String datasetFilename) throws Exception { // try to get the given filename from the cache IDataSet xmlDataSetToRun = cachedDatasets.get(datasetFilename); // if we didn't find it in the cache, load it if (xmlDataSetToRun == null) { File file = new File(datasetFilename); InputStream fileInInputStreamFormat = null; if (file.exists()) { fileInInputStreamFormat = new FileInputStream(datasetFilename); } else { fileInInputStreamFormat = getClass().getClassLoader().getResourceAsStream(datasetFilename); if (fileInInputStreamFormat == null) { throw new FileNotFoundException("Unable to find '" + datasetFilename + "' in the classpath"); } } StringReader reader = null; try { String xmlFile = IOUtils.toString(fileInInputStreamFormat); StringBuilder openmrsObjectText = new StringBuilder(); openmrsObjectText.append("uuid=\"" + UUID.randomUUID().toString() + "\" "); openmrsObjectText.append("creator=\"1\" date_created=\"2005-08-07 00:00:00.0\" "); openmrsObjectText.append("changed_by=\"1\" date_changed=\"2007-10-24 14:51:53.0\" "); StringBuilder metadataObjectText = new StringBuilder(openmrsObjectText); metadataObjectText.append(" retired=\"false\" retired_reason=\"\""); StringBuilder dataObjectText = new StringBuilder(openmrsObjectText); dataObjectText.append(" voided=\"false\" void_reason=\"\""); xmlFile = xmlFile.replace("[METADATA]", metadataObjectText.toString()); xmlFile = xmlFile.replace("[DATA]", dataObjectText.toString()); reader = new StringReader(xmlFile); FlatXmlDataSet flatXml = new FlatXmlDataSet(reader, false, true, false); ReplacementDataSet replacementDataSet = new ReplacementDataSet(flatXml); replacementDataSet.addReplacementObject("[NULL]", null); xmlDataSetToRun = replacementDataSet; } finally { IOUtils.closeQuietly(fileInInputStreamFormat); IOUtils.closeQuietly(reader); } } cachedDatasets.put(datasetFilename, xmlDataSetToRun); executeDataSet(xmlDataSetToRun); }
From source file:Main.java
public static void forceDelete(File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file);/* ww w . j av a 2 s. c o m*/ } else { boolean filePresent = file.exists(); if (!file.delete()) { if (!filePresent) { throw new FileNotFoundException("File does not exist: " + file); } String message = "Unable to delete file: " + file; throw new IOException(message); } } }
From source file:com.cyclopsgroup.waterview.jelly.taglib.JellyScriptTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//*from w w w. j a v a 2 s. c o m*/ protected void processTag(XMLOutput output) throws Exception { requireAttribute("type"); requireAttribute("path"); Script script = null; if (StringUtils.equals(getType(), "system")) { JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); script = je.getScript(getPath()); } else if (StringUtils.equals(getType(), "classpath")) { URL resource = getClass().getClassLoader().getResource(getPath()); if (resource != null) { script = context.compileScript(resource); } } else if (StringUtils.equals(getType(), "file")) { File file = new File(getPath()); if (file.exists()) { script = context.compileScript(file.toURL()); } } else { throw new JellyTagException("Type must be system|classpath|file, default value is system"); } if (script == null) { throw new FileNotFoundException("Resource " + getPath() + " is not found in " + getType()); } JellyContext jc = new JellyContext(getContext()); if (script != null) { script.run(jc, output); output.flush(); } }
From source file:de.uzk.hki.da.repository.ElasticsearchMetadataIndex.java
@Override public void prepareAndIndexMetadata(String indexName, String id, String edmContent) throws RepositoryException, FileNotFoundException { if (edmJsonFrame == null) throw new IllegalStateException("Frames must not be null"); if (!new File(edmJsonFrame).exists()) throw new FileNotFoundException(edmJsonFrame + " does not exist."); RdfToJsonLdConverter converter = new RdfToJsonLdConverter(edmJsonFrame); Map<String, Object> json = null; try {/*from w ww. j a v a2 s . co m*/ json = converter.convert(edmContent); } catch (Exception e) { throw new RuntimeException("An error occured during metadata conversion", e); } @SuppressWarnings("unchecked") List<Object> graph = (List<Object>) json.get("@graph"); for (Object object : graph) { logger.trace("Preparing json graph for indexing in elasticsearch: \n{}", JSONUtils.toPrettyString(object)); createIndexEntryForGraphObject(indexName, edmJsonFrame, object, id); } }
From source file:org.wrml.runtime.EngineConfiguration.java
public final static EngineConfiguration load(final File fileOrDirectory) throws IOException { File configFile = fileOrDirectory; if (fileOrDirectory == null) { // Check the system property String fileName = PropertyUtil.getSystemProperty(WRML_CONFIGURATION_FILE_PATH_PROPERTY_NAME); if (fileName != null) { configFile = FileUtils.getFile(fileName); } else {//from www .j av a2 s. c o m // Look in the local directory for the configuration file with the default name configFile = FileUtils.getFile(new File("."), DEFAULT_WRML_CONFIGURATION_FILE_NAME); if (!configFile.exists()) { configFile = FileUtils.getFile(FileUtils.getUserDirectory(), DEFAULT_WRML_CONFIGURATION_FILE_NAME); } } } else if (fileOrDirectory.isDirectory()) { // Named a directory (assume default file name) configFile = FileUtils.getFile(fileOrDirectory, DEFAULT_WRML_CONFIGURATION_FILE_NAME); } if (!configFile.exists()) { throw new FileNotFoundException("The path \"" + configFile.getAbsolutePath() + "\" does not exist."); } LOGGER.trace("loading EngineConfiguration from '{}'...", configFile); final InputStream in = FileUtils.openInputStream(configFile); final EngineConfiguration config = EngineConfiguration.load(in); IOUtils.closeQuietly(in); LOGGER.debug("loaded EngineConfiguration from '{}'", configFile); return config; }
From source file:de.tuebingen.uni.sfs.germanet.api.StaxLoader.java
/** * Constructs a <code>StaxLoader</code> for data files in directory * <code>germanetDirectory</code> and existing <code>GermaNet</code> object * <code>germaNet</code>./*from w w w . j a v a 2 s . co m*/ * @param germanetDirectory location of GermaNet data files * @param germaNet <code>GermaNet</code> object to load into * @throws java.io.FileNotFoundException */ protected StaxLoader(File germaNetDir, GermaNet germaNet) throws FileNotFoundException { this.germaNetDir = germaNetDir; this.germaNetStreams = null; this.synLoader = new SynsetLoader(germaNet); this.relLoader = new RelationLoader(germaNet); this.xmlNames = null; if (!germaNetDir.isDirectory()) { throw new FileNotFoundException("Unable to load GermaNet from \"" + germaNetDir + "\""); } }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.RuntimeProvider.java
public File getFile(String aFilename) throws IOException { install();/*www .j av a2s.c o m*/ File file = new File(getWorkspace(), aFilename); if (!file.exists()) { throw new FileNotFoundException("File not found in workspace: [" + aFilename + "]"); } return file; }
From source file:com.autentia.tnt.listener.StartupListener.java
public void contextInitialized(ServletContextEvent sce) { try {// w ww . ja v a 2 s . c o m // Dump traces now as if nothing had happended before log.info("--------------------------------------------------------------------------------"); log.info("contextInitialized - starting up application"); log.info("contextInitialized - saving Spring's context for use by all application"); // Save Spring context SpringUtils.configure(WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext())); // Get configuration directory String cfgDir = ConfigurationUtil.getDefault().getConfigDir(); log.info("contextInitialized - configuration directory set to '" + cfgDir + "'"); // Normalized cfgDir if (cfgDir.endsWith("/") || cfgDir.endsWith("\\")) { cfgDir = cfgDir.substring(0, cfgDir.length() - 1); } // Check configuration directory if (!new File(cfgDir).isDirectory()) { throw new FileNotFoundException(cfgDir); } // Configure LOG4J String log4jProperties = cfgDir + FILE_LOG4J; if (!new File(log4jProperties).exists()) { throw new FileNotFoundException(log4jProperties); } PropertyConfigurator.configure(log4jProperties); log.info("contextInitialized - configuring LOG4J system with file " + log4jProperties); // Try to create essential directories File uploadPath = new File(ConfigurationUtil.getDefault().getUploadPath()); log.info("contextInitialized - checking upload directory " + uploadPath.getAbsolutePath()); uploadPath.mkdirs(); if (!uploadPath.isDirectory()) { throw new FileNotFoundException(uploadPath.getAbsolutePath()); } // Load reports if (ConfigurationUtil.getDefault().getLoadingReportOnLoad() > 0) { log.info("contextInitialized - loading reports in report manager"); ReportManager.getReportManager(); } else { log.info("contextInitialized - loading reports on startup disabled"); } // Check database log.info("contextInitialized - checking database version"); ApplicationLock.refresh(); } catch (FileNotFoundException e) { log.fatal("contextInitialized - configuration dir or file not found (" + e.getMessage() + "): application will not be started", e); throw new IllegalStateException("Config dir or file not found", e); } /* Moved to Spring catch( ConfigurationException e ) { log.fatal("contextInitialized - error reading application configuration: application will not be started",e); throw new IllegalStateException("Error reading applocation configuration",e); } */ }
From source file:com.slytechs.file.snoop.SnoopFileCapture.java
/** * Creates a new file by creating an empty file, then writting a block header * into it and then closes the created file. The file has to be reopened as a * normal file if you need access to its contents. * /*from ww w . j a v a 2 s. c o m*/ * @param file * file to create * @param mode * TODO * @param filter * TODO * @param order * byte ordering for all the headers within the file * @throws FileNotFoundException * unable to find parent directory inorder to create a new file * @throws IOException * any IO errors * @throws FileFormatException */ public static SnoopFile createFile(final File file, final FileMode mode, Filter<ProtocolFilterTarget> filter) throws FileNotFoundException, IOException, FileFormatException { if (logger.isDebugEnabled()) { logger.debug(file.getName() + ", mode=" + mode + (filter == null ? "" : filter)); } // Create empty file? if (file.createNewFile() == false) { throw new FileNotFoundException("Unable to create new file [" + file.getName() + "]"); } SnoopFile capture = new SnoopFileCapture(FileMode.ReadWrite); /* * Open up in READONLY MODE since file is empty anyway, nothing to override, * we will append memory cache based segments and flush them out. */ final FileEditor editor = new FileEditorImpl(file, FileMode.ReadWrite, headerReader, ByteOrder.BIG_ENDIAN, filter, (RawIteratorBuilder) capture); SnoopBlockRecordImpl.createBlock(capture, editor); editor.close(); // Flush and close capture = new SnoopFileCapture(file, mode, null); return capture; }
From source file:de.teamgrit.grit.util.config.Configuration.java
/** * Loads the configuration from the specified File. * //from ww w.j av a2 s.com * @param file * the file the config is stored in * @throws ConfigurationException * if the configuration file can't be read. * @throws FileNotFoundException * if the file can't be found */ public Configuration(File file) throws ConfigurationException, FileNotFoundException { LOGGER.info("Loading configuration from file: " + file.getAbsolutePath()); if (!file.exists()) { LOGGER.warning("Could not find configuration file: " + file.getAbsolutePath()); throw new FileNotFoundException(file.getAbsolutePath()); } m_configXML = file; m_config = new XMLConfiguration(file); // set xpath engine for more powerful queries m_config.setExpressionEngine(new XPathExpressionEngine()); loadToMember(); // save(); }