List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:org.motechproject.mobile.imp.serivce.oxd.FormDefinitionServiceImpl.java
public void init() throws Exception { for (String resource : getOxdFormDefResources()) { int index = resource.lastIndexOf("/"); String studyName = resource.substring(index + 1); List<File> fileList = getFileList(resource); if (fileList == null || fileList.isEmpty()) throw new FileNotFoundException(" No files in the directory " + resource); List<Integer> formIdList = new ArrayList<Integer>(); for (File fileName : fileList) { String formDefinition = getFileContent(fileName.getAbsolutePath()); Integer extractedFormId = extractFormId(formDefinition); formMap.put(extractedFormId, formDefinition); formIdList.add(extractedFormId); }/*w w w. java2 s .c o m*/ studyForms.put(studyName, formIdList); studies.add(studyName); } }
From source file:com.facebook.presto.accumulo.examples.TpcHBatchWriter.java
@Override public int run(AccumuloConfig config, CommandLine cmd) throws Exception { Path orders = new Path(cmd.getOptionValue(ORDERS_OPT)); final FileSystem fs = FileSystem.get(new Configuration()); if (!fs.exists(orders)) { throw new FileNotFoundException(format("File %s does not exist or is a directory", orders)); }/*from w ww.j a va2s . c o m*/ ZooKeeperInstance inst = new ZooKeeperInstance(config.getInstance(), config.getZooKeepers()); Connector conn = inst.getConnector(config.getUsername(), new PasswordToken(config.getPassword())); validateTable(conn, DATA_TABLE); validateTable(conn, INDEX_TABLE); BatchWriterConfig bwc = new BatchWriterConfig(); MultiTableBatchWriter mtbw = conn.createMultiTableBatchWriter(bwc); BatchWriter mainWrtr = mtbw.getBatchWriter(DATA_TABLE); BatchWriter indexWrtr = mtbw.getBatchWriter(INDEX_TABLE); long numTweets = 0; long numIndex = 0; System.out.println(format("Reading from file: %s", orders)); BufferedReader rdr = new BufferedReader(new InputStreamReader(fs.open(orders))); // For each record in the file String line; while ((line = rdr.readLine()) != null) { // Split the line into fields String[] fields = line.split("\\|"); if (fields.length < 9) { System.err.println(format("Record does not contain at least nine fields:\n%s", line)); continue; } // Parse out the fields from strings Long orderkey = Long.parseLong(fields[0]); Long custkey = Long.parseLong(fields[1]); String orderstatus = fields[2]; Double totalprice = Double.parseDouble(fields[3]); Date orderdate = sdformat.parse(fields[4]); String orderpriority = fields[5]; String clerk = fields[6]; Long shippriority = Long.parseLong(fields[7]); String comment = fields[8]; // Create mutation for the row Mutation mutation = new Mutation(encode(orderkey)); mutation.put(CF, CUSTKEY, encode(custkey)); mutation.put(CF, ORDERSTATUS, encode(orderstatus)); mutation.put(CF, TOTALPRICE, encode(totalprice)); mutation.put(CF, ORDERDATE, encode(orderdate)); mutation.put(CF, ORDERPRIORITY, encode(orderpriority)); mutation.put(CF, CLERK, encode(clerk)); mutation.put(CF, SHIPPRIORITY, encode(shippriority)); mutation.put(CF, COMMENT, encode(comment)); mainWrtr.addMutation(mutation); ++numTweets; // Create index mutation for the clerk Mutation idxClerk = new Mutation(encode(clerk)); idxClerk.put(CF, encode(orderkey), EMPTY_BYTES); indexWrtr.addMutation(idxClerk); ++numIndex; } rdr.close(); // Send the mutations to Accumulo and release resources mtbw.close(); // Display how many tweets were inserted into Accumulo System.out.println(format("%d tweets Mutations inserted", numTweets)); System.out.println(format("%d index Mutations inserted", numIndex)); return 0; }
From source file:com.zyeeda.framework.template.internal.FreemarkerTemplateServiceProvider.java
private void init(org.apache.commons.configuration.Configuration config) throws Exception { String repoRoot = config.getString(TEMPLATE_REPOSITORY_ROOT, DEFAULT_TEMPLATE_REPOSITORY_ROOT); logger.debug("template repository root = {}", repoRoot); this.repoRoot = new File(this.configSvc.getApplicationRoot(), repoRoot); if (!this.repoRoot.exists()) { throw new FileNotFoundException(this.repoRoot.toString()); }/*w w w . jav a 2s . c o m*/ this.dateFormat = config.getString(DATE_FORMAT, DEFAULT_DATE_FORMAT); this.timeFormat = config.getString(TIME_FORMAT, DEFAULT_TIME_FORMAT); this.datetimeFormat = config.getString(DATETIME_FORMAT, DEFAULT_DATETIME_FORMAT); logger.debug("template root = {}", this.repoRoot); logger.debug("date format = {}", this.dateFormat); logger.debug("time format = {}", this.timeFormat); logger.debug("datetime format = {}", this.dateFormat); }
From source file:de.jcup.egradle.codeassist.dsl.FilesystemFileLoader.java
@Override public Set<Plugin> loadPlugins() throws IOException { if (dslFolder == null) { throw new DSLFolderNotSetException(); }//from w ww . j av a 2 s . com if (!dslFolder.exists()) { throw new DSLFolderNotValidException("DSL folder does not exist:" + dslFolder); } if (!dslFolder.isDirectory()) { throw new DSLFolderNotValidException("DSL folder ist not a directory:" + dslFolder); } File sourceFile = new File(dslFolder, "plugins.xml"); if (!sourceFile.exists()) { throw new FileNotFoundException("Did not found:" + sourceFile); } try (InputStream stream = new FileInputStream(sourceFile)) { XMLPlugins xmlPlugins = pluginsImporter.importPlugins(stream); Set<Plugin> plugins = xmlPlugins.getPlugins(); return plugins; } }
From source file:com.yifanlu.PSXperiaTool.PSXperiaTool.java
private void checkData(File dataDir) throws IllegalArgumentException, IOException { nextStep("Checking to make sure all files are there."); if (!mDataDir.exists()) throw new FileNotFoundException("Cannot find data directory!"); File filelist = new File(mDataDir, "/config/filelist.txt"); if (!filelist.exists()) throw new FileNotFoundException("Cannot find list to validate files!"); InputStream fstream = new FileInputStream(filelist); BufferedReader reader = new BufferedReader(new InputStreamReader(fstream)); String line;/*from w w w .j av a2 s . com*/ while ((line = reader.readLine()) != null) { if (line.isEmpty()) continue; File check = new File(mDataDir, line); if (!check.exists()) throw new IllegalArgumentException("Cannot find required data file: " + line); } Properties config = new Properties(); config.loadFromXML(new FileInputStream(new File(mDataDir, "/config/config.xml"))); Logger.info("Using data from " + config.getProperty("game_name", "Unknown Game") + " " + config.getProperty("game_region") + " Version " + config.getProperty("game_version", "Unknown") + ", CRC32: " + config.getProperty("game_crc32", "Unknown")); Logger.debug("Done checking data."); }
From source file:fr.esiea.esieaddress.controllers.importation.CSVImportCtrl.java
@RequestMapping(method = RequestMethod.POST) @ResponseBody//from w w w. j a v a 2 s. com @Secured("ROLE_USER") public void upload(MultipartHttpServletRequest files, final HttpServletRequest request) throws DaoException, ServiceException, FileNotFoundException { LOGGER.info("[IMPORT] Start to import contact"); //TODO Make it less verbose and may use a buffer to make it safer Map<String, MultipartFile> multipartFileMap = files.getMultiFileMap().toSingleValueMap(); Set<String> fileNames = multipartFileMap.keySet(); for (String fileName : fileNames) { MultipartFile multipartFile = multipartFileMap.get(fileName); String originalFilename = multipartFile.getOriginalFilename(); if (checkFileName(originalFilename) && multipartFile.getSize() < FILE_SIZE_MAX) { InputStream inputStream = null; try { inputStream = multipartFile.getInputStream(); } catch (IOException e) { throw new FileNotFoundException(e.toString()); } try (Reader contactsFile = new InputStreamReader(inputStream)) { Map<String, Object> modelErrors = new HashMap<>(); LOGGER.debug("[IMPORT] File is reading"); Collection<Contact> contacts = csvService.ReadContactCSV(contactsFile); for (Contact contact : contacts) { try { contactCrudService.insert(contact); } catch (ValidationException e) { Object modelError = e.getModel(); LOGGER.warn("found an error in contact " + modelError); modelErrors.put(contact.getId(), (Map) modelError); } } if (!modelErrors.isEmpty()) throw new ValidationException(modelErrors); } catch (IOException e) { throw new FileNotFoundException(e.toString()); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { LOGGER.error("[IMPORT] Impossible to close the file " + inputStream.toString()); } } } } }
From source file:eu.stratosphere.core.fs.local.LocalFileSystem.java
@Override public FileStatus getFileStatus(Path f) throws IOException { final File path = pathToFile(f); if (path.exists()) { return new LocalFileStatus(pathToFile(f), this); } else {/*from w ww . ja v a2 s.com*/ throw new FileNotFoundException("File " + f + " does not exist or the user running " + "Stratosphere ('" + System.getProperty("user.name") + "') has insufficient permissions to access it."); } }
From source file:com.autentia.tnt.upload.impl.DefaultUploader.java
/** */ public String version(String id, String oldFile, UploadedFile newFile) throws IOException { final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-hhmmss"); if (!exists(id, oldFile)) { throw new FileNotFoundException(oldFile + " doesn't exists!"); }// w ww . j a v a 2 s . c om if (oldFile == null) { store(id, newFile); return newFile.getName(); } final String versioned = oldFile.substring(0, oldFile.lastIndexOf('.')) + "_" + sdf.format(new Date()) + oldFile.substring(oldFile.lastIndexOf('.')); byte[] buffer = new byte[65536]; int nr; InputStream in = null; OutputStream out = null; try { in = newFile.getInputStream(); out = new FileOutputStream(getFilePath(id) + FileUtil.getFileName(versioned)); while ((nr = in.read(buffer)) != -1) { out.write(buffer, 0, nr); } } finally { if (in != null) { try { in.close(); } catch (IOException ioex) { // Ignored } } if (out != null) { try { out.close(); } catch (IOException ioex) { // Ignored } } } return versioned; }
From source file:ca.bitwit.postcard.PostcardAdaptor.java
/** * Cordova Plugin Overrides/*w w w. j a v a 2 s.c o m*/ */ public PostcardAdaptor(Activity activity, WebView webView) { Log.d("PostcardApplication", "Initialized"); NetworksManager.INSTANCE.adaptor = this; this.activity = activity; this.webView = webView; Context context = activity.getApplicationContext(); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.addJavascriptInterface(this, "PostcardApplication"); webView.loadUrl("file:///android_asset/www/index.html"); this.properties = new Properties(); String propFileName = "postcard.properties"; try { InputStream inputStream = context.getAssets().open(propFileName); if (inputStream != null) { this.properties.load(inputStream); } else { throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); } } catch (IOException e) { e.printStackTrace(); } this.networkAccountDataSource = new NetworkAccountDataSource(context); this.networkAccountDataSource.open(); this.personDataSource = new PersonDataSource(context); this.personDataSource.open(); this.tagDataSource = new TagDataSource(context); this.tagDataSource.open(); }
From source file:edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarTestCase.java
/** * Finds a directory relative to the given module, whether the working directory is the * module (as when running the tests from buildr) or the root of the project (as when running * in IDEA).//from w w w.ja va2 s. c om */ public static File getModuleRelativeDirectory(String moduleName, String directory) throws IOException { File dir = new File(directory); if (dir.exists()) return dir; dir = new File(moduleName.replaceAll(":", "/"), directory); if (dir.exists()) return dir; throw new FileNotFoundException( String.format("Could not find directory %s relative to module %s from current directory %s", directory, moduleName, new File(".").getCanonicalPath())); }