List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:de.phip1611.apps.numbered_filenames_with_leading_zeros.JSONConfigProvider.java
/** * Ldt die Konfigurationsdatei und parst die JSON-Daten in ein JSON-Objekt. * @throws FileNotFoundException // w w w . ja v a 2s. com */ public void loadConfig() throws FileNotFoundException { if (!this.isReadable()) { throw new FileNotFoundException("Konfig-Datei ist nicht vorhanden oder konnte nicht gelesen werden."); } try { config = (JSONObject) new JSONParser().parse(new FileReader(RELATIVE_CONFIGFILE_PATH)); } catch (IOException | ParseException ex) { System.err.println("Konfig-Datei konnte nicht erfolgreich geffnet und geparst werden."); } }
From source file:net.modelbased.proasense.storage.reader.StorageReaderMongoServiceRestBenchmark.java
private Properties loadClientProperties() { clientProperties = new Properties(); String propFilename = "client.properties"; InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFilename); try {//from w w w . j a va2s . c o m if (inputStream != null) { clientProperties.load(inputStream); } else throw new FileNotFoundException("Property file: '" + propFilename + "' not found in classpath."); } catch (IOException e) { System.out.println("Exception:" + e.getMessage()); } return clientProperties; }
From source file:io.stallion.utils.ResourceHelpers.java
public static String loadResource(String pluginName, String path) { try {//from ww w.ja va2 s.c o m URL url = pluginPathToUrl(pluginName, path); if (url == null) { throw new FileNotFoundException("Resource not found: " + path); } return loadResourceFromUrl(url, pluginName); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.twosigma.beakerx.chart.serializer.RastersSerializer.java
@Override public void serialize(Rasters rasters, JsonGenerator jgen, SerializerProvider sp) throws IOException { validate(rasters);/*from ww w .j a v a 2 s . co m*/ jgen.writeStartObject(); jgen.writeObjectField(TYPE, SerializerUtil.getTypeName(rasters)); jgen.writeObjectField("x", rasters.getX()); jgen.writeObjectField("y", rasters.getY()); jgen.writeObjectField("opacity", rasters.getOpacity()); jgen.writeObjectField("visible", rasters.getVisible()); jgen.writeObjectField("yAxis", rasters.getYAxis()); jgen.writeObjectField("position", rasters.getPosition()); jgen.writeObjectField("width", rasters.getWidth()); jgen.writeObjectField("height", rasters.getHeight()); // datastring will override file path/url if (rasters.getDataString() != null) { jgen.writeObjectField("value", Bytes2Base64(rasters.getDataString(), null)); } else if (!rasters.getFilePath().isEmpty()) { String path = rasters.getFilePath(); File file = new File(path); if (!file.exists()) { throw new FileNotFoundException("Cannot find file " + path); } byte[] picture = Files.readAllBytes(new File(path).toPath()); String extension = ""; int i = path.lastIndexOf('.'); if (i > 0) { extension = path.substring(i + 1); } jgen.writeObjectField("value", Bytes2Base64(picture, extension)); } else if (!rasters.getFileUrl().isEmpty()) { jgen.writeObjectField("value", rasters.getFileUrl()); } jgen.writeEndObject(); }
From source file:eu.europeana.enrichment.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()); }/* ww w .j ava 2s .co m*/ } files.addAll(Arrays.asList(list)); } return files; }
From source file:datawarehouse.CSVLoader.java
/** * Parse CSV file using OpenCSV library and load in given database table. * * @param csvFile Input CSV file/*from ww w .j a v a2 s .c om*/ * @param tableName Database table name to import data * @param truncateBeforeLoad Truncate the table before inserting new * records. * @throws Exception */ public void loadCSV(String csvFile, String tableName, boolean truncateBeforeLoad) throws Exception { CSVReader csvReader = null; if (null == this.connection) { throw new Exception("Not a valid connection."); } try { csvReader = new CSVReader(new FileReader(csvFile), this.seprator); } catch (Exception e) { e.printStackTrace(); throw new Exception("Error occured while executing file. " + e.getMessage()); } String[] headerRow = csvReader.readNext(); if (null == headerRow) { throw new FileNotFoundException( "No columns defined in given CSV file." + "Please check the CSV file format."); } String questionmarks = StringUtils.repeat("?,", headerRow.length); questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1); String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName); query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ",")); query = query.replaceFirst(VALUES_REGEX, questionmarks); System.out.println("Query: " + query); String[] nextLine; Connection con = null; PreparedStatement ps = null; try { con = this.connection; con.setAutoCommit(false); ps = con.prepareStatement(query); if (truncateBeforeLoad) { //delete data from table before loading csv con.createStatement().execute("DELETE FROM " + tableName); } final int batchSize = 1000; int count = 0; while ((nextLine = csvReader.readNext()) != null) { if (null != nextLine) { int index = 1; for (String string : nextLine) { //System.out.print(string + ": "); try { DateFormat format = new SimpleDateFormat("dd.mm.yyyy"); Date date = format.parse(string); ps.setDate(index++, new java.sql.Date(date.getTime())); //System.out.println("date"); } catch (ParseException | SQLException e) { try { Double income = parseDouble(string.replace(",", ".")); ps.setDouble(index++, income); //System.out.println("double"); } catch (NumberFormatException | SQLException err) { ps.setString(index++, string); //System.out.println("string"); } } } ps.addBatch(); } if (++count % batchSize == 0) { ps.executeBatch(); } } ps.executeBatch(); // insert remaining records con.commit(); } catch (Exception e) { con.rollback(); e.printStackTrace(); throw new Exception("Error occured while loading data from file to database." + e.getMessage()); } finally { if (null != ps) { ps.close(); } if (null != con) { con.close(); } csvReader.close(); } }
From source file:com.martinwunderlich.nlp.io.LexisNexisParser.java
private void loadConfiguration() { try {/*from ww w . ja v a2 s .c om*/ InputStream is = getClass().getClassLoader().getResourceAsStream(propertiesFile); if (is != null) config.load(is); else throw new FileNotFoundException("Configuration file is missing. Looked for: " + propertiesFile); } catch (IOException e) { throw new RuntimeException(e); // wrap and rethrow } }
From source file:epgtools.dumpepgfromts.FileLoader.java
public void load() throws FileNotFoundException { //??/*from w ww . java 2 s.co m*/ if (!tsFile.isFile()) { throw new FileNotFoundException( "???? = " + tsFile.getAbsolutePath()); } //SDT?EIT? final Set<Integer> pids = new HashSet<>(); pids.addAll(RESERVED_PROGRAM_ID.SDT_OR_BAT.getPids()); pids.addAll(RESERVED_PROGRAM_ID.EIT_GR_ST.getPids()); LOG.info("?? = " + tsFile.getAbsolutePath()); final TsReader reader = new TsReader(tsFile, pids, limit); Map<Integer, List<TsPacketParcel>> pid_packets = reader.getPackets(); Map<Integer, List<Section>> pids_sections_temp = new ConcurrentHashMap<>(); for (Integer pidKey : pid_packets.keySet()) { LOG.info("?pid = " + Integer.toHexString(pidKey) + " pid = " + RESERVED_PROGRAM_ID.reverseLookUp(pidKey)); SectionReconstructor sectionMaker = new SectionReconstructor(pid_packets.get(pidKey), pidKey); List<Section> sections = sectionMaker.getSections(); if (sections != null) { LOG.info(" = " + sections.size()); pids_sections_temp.put(pidKey, sections); } } Map<Integer, List<Section>> pids_sections = Collections.unmodifiableMap(pids_sections_temp); pid_packets = null; pids_sections_temp = null; ChannelDataExtractor chde = new ChannelDataExtractor(); ProgrammeDataExtractor pgde = new ProgrammeDataExtractor(); for (Integer pid : pids_sections.keySet()) { LOG.info("?pid = " + Integer.toHexString(pid) + " pid = " + RESERVED_PROGRAM_ID.reverseLookUp(pid)); for (Section s : pids_sections.get(pid)) { try { if (RESERVED_PROGRAM_ID.reverseLookUp(pid) == RESERVED_PROGRAM_ID.SDT_OR_BAT) { chde.makeDataSet(s); } else if (RESERVED_PROGRAM_ID.reverseLookUp(pid) == RESERVED_PROGRAM_ID.EIT_GR_ST) { pgde.makeDataSet(s); } } catch (IllegalArgumentException ex) { LOG.warn(ex); } } } this.channels = chde.getUnmodifiableDataSet(); this.programmes = pgde.getUnmodifiableDataSet(); }
From source file:ru.xxlabaza.popa.template.TemplaterFacade.java
@SneakyThrows public String build(String templateName, Map<String, Object> bindings) { log.info("Template: '{}', bindings: {}", templateName, bindingsToString(bindings)); val pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + templateName + extensionsPattern); val templatePath = Files.list(templatesFolder).filter(it -> pathMatcher.matches(it.getFileName())) .findFirst()//from www . j a va 2s . co m .orElseThrow( () -> new FileNotFoundException(String.format("Template '%s' not found", templateName))) .toAbsolutePath(); val templater = templaters.get(FileSystemUtils.getExstension(templatePath)); return templater.build(templatesFolder.relativize(templatePath), bindings); }
From source file:gash.router.app.DemoApp.java
/** * sample application (client) use of our messaging service * * @param args/*from w w w . j a v a2 s . c om*/ */ public static void main(String[] args) { if (args.length == 0) { System.out.println("usage: <ip address> <port no>"); System.exit(1); } String ipAddress = args[0]; int port = Integer.parseInt(args[1]); Scanner s = new Scanner(System.in); boolean isExit = false; try { MessageClient mc = new MessageClient(ipAddress, port); DemoApp da = new DemoApp(mc); int choice = 0; while (true) { System.out.println( "Enter your option \n1. WRITE a file. \n2. READ a file. \n3. Update a File. \n4. Delete a File\n 5 Ping(Global)\n 6 Exit"); choice = s.nextInt(); switch (choice) { case 1: { System.out.println("Enter the full pathname of the file to be written "); String currFileName = s.next(); File file = new File(currFileName); if (file.exists()) { ArrayList<ByteString> chunkedFile = da.divideFileChunks(file); String name = file.getName(); int i = 0; String requestId = SupportMessageGenerator.generateRequestID(); for (ByteString string : chunkedFile) { mc.saveFile(name, string, chunkedFile.size(), i++, requestId); } } else { throw new FileNotFoundException("File does not exist in this path "); } } break; case 2: { System.out.println("Enter the file name to be read : "); String currFileName = s.next(); da.sendReadTasks(currFileName); //Thread.sleep(1000 * 100); } break; case 3: { System.out.println("Enter the full pathname of the file to be updated"); String currFileName = s.next(); File file = new File(currFileName); if (file.exists()) { ArrayList<ByteString> chunkedFile = da.divideFileChunks(file); String name = file.getName(); int i = 0; String requestId = SupportMessageGenerator.generateRequestID(); for (ByteString string : chunkedFile) { mc.updateFile(name, string, chunkedFile.size(), i++, requestId); } //Thread.sleep(10 * 1000); } else { throw new FileNotFoundException("File does not exist in this path "); } } break; case 4: System.out.println("Enter the file name to be deleted : "); String currFileName = s.next(); mc.deleteFile(currFileName); //Thread.sleep(1000 * 100); break; case 5: da.ping(1); break; case 6: isExit = true; break; default: break; } if (isExit) break; } } catch (Exception e) { e.printStackTrace(); } finally { CommConnection.getInstance().release(); if (s != null) s.close(); } }