List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException(String s)
FileNotFoundException
with the specified detail message. From source file:com.carmatech.maven.MergeOperation.java
private List<File> removeNonExisting(final List<File> files) throws FileNotFoundException { final List<File> existingFiles = Lists.newArrayListWithExpectedSize(files.size()); for (final File file : files) { if (file.exists()) { existingFiles.add(file);//w ww . java 2 s. c om } else { if (errorOnMissingFile) { throw new FileNotFoundException(file.getAbsolutePath()); } else { logger.warn("Skipped file as it could not be found on disk: [" + file.getAbsolutePath() + "]."); } } } return existingFiles; }
From source file:edu.lternet.pasta.datapackagemanager.DataPackageError.java
/** * Delete the error file [transaction].txt in the "error" directory for the * given package identifier./* w ww. j av a2 s . c o m*/ * * @param packageId * The data package identifier * @param transaction * The transaction identifier * @throws FileNotFoundException */ public void deleteError(String transaction) throws FileNotFoundException { String errorPath = errorDir + "/"; String errorName = transaction + ".txt"; File file = new File(errorPath + errorName); if (!file.exists()) { String gripe = "The error file " + errorName + " was not found!"; throw new FileNotFoundException(gripe); } try { FileUtils.forceDelete(file); } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } }
From source file:com.aionengine.gameserver.dataholders.loadingutils.XmlMerger.java
/** * This method creates a result document if it is missing, * or updates existing one if the source file has modification.<br /> * If there are no changes - nothing happens. * * @throws FileNotFoundException when source file doesn't exists. * @throws XMLStreamException when XML processing error was occurred. *//*from w ww . j a v a 2 s .c o m*/ public void process() throws Exception { logger.debug("Processing " + sourceFile + " files into " + destFile); if (!sourceFile.exists()) throw new FileNotFoundException("Source file " + sourceFile.getPath() + " not found."); boolean needUpdate = false; if (!destFile.exists()) { logger.debug("Dest file not found - creating new file"); needUpdate = true; } else if (!metaDataFile.exists()) { logger.debug("Meta file not found - creating new file"); needUpdate = true; } else { logger.debug("Dest file found - checking file modifications"); needUpdate = checkFileModifications(); } if (needUpdate) { logger.debug("Modifications found. Updating..."); try { doUpdate(); } catch (Exception e) { FileUtils.deleteQuietly(destFile); FileUtils.deleteQuietly(metaDataFile); throw e; } } else { logger.debug("Files are up-to-date"); } }
From source file:com.digitalgeneralists.assurance.Application.java
static void installDb(InputStream propertiesFileStream, InputStream dbScriptStream) throws IOException, SQLException { Logger logger = Logger.getLogger(Application.class); Connection dbConnection = null; ResultSet rs = null;/*from w w w .j a va 2 s.com*/ try { Properties properties = new Properties(); if (propertiesFileStream != null) { properties.load(propertiesFileStream); } else { throw new FileNotFoundException("The database properties file could not be loaded."); } String dbUrl = (String) properties.get("jdbc.url"); String dbUser = (String) properties.get("jdbc.username"); String dbPassword = (String) properties.get("jdbc.password"); dbConnection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); ArrayList<String> listOfDatabases = new ArrayList<String>(); DatabaseMetaData meta = dbConnection.getMetaData(); String[] tableTypes = { "TABLE" }; rs = meta.getTables(null, null, Application.verificationTableName, tableTypes); while (rs.next()) { String databaseName = rs.getString("TABLE_NAME"); listOfDatabases.add(databaseName.toUpperCase()); } if (listOfDatabases.contains(Application.verificationTableName)) { logger.info("Database already exists"); } else { ScriptRunner runner = new ScriptRunner(dbConnection, true, true); Reader dbScript = new InputStreamReader(dbScriptStream); runner.runScript(dbScript); logger.info("Database is created"); } } finally { if (rs != null) { try { rs.close(); rs = null; } catch (SQLException e) { // The ship is going down. Not much we can do. logger.fatal(e); } } if (dbConnection != null) { dbConnection.close(); dbConnection = null; } } logger = null; }
From source file:at.bitfire.ical4android.AndroidEvent.java
public Event getEvent() throws FileNotFoundException, CalendarStorageException { if (event != null) return event; try {/*from ww w .j a va 2 s.c o m*/ @Cleanup EntityIterator iterEvents = CalendarContract.EventsEntity.newEntityIterator(calendar.provider.query( calendar.syncAdapterURI( ContentUris.withAppendedId(CalendarContract.EventsEntity.CONTENT_URI, id)), null, null, null, null), calendar.provider); if (iterEvents.hasNext()) { event = new Event(); Entity e = iterEvents.next(); populateEvent(e.getEntityValues()); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { if (Attendees.CONTENT_URI.equals(subValue.uri)) populateAttendee(subValue.values); if (Reminders.CONTENT_URI.equals(subValue.uri)) populateReminder(subValue.values); } populateExceptions(); return event; } else throw new FileNotFoundException("Locally stored event couldn't be found"); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't read locally stored event", e); } }
From source file:io.github.data4all.util.Gallery.java
/** * Receives the file of the image at the given timestamp. * //from w w w . j ava2 s .c om * @param timestamp * The timestamp of the image * @return The file object of the image * @throws FileNotFoundException * If the image is not stored in this gallery */ public File getImageFile(long timestamp) throws FileNotFoundException { final File result = this.buildPath(timestamp, ENDING_JPEG); if (result.exists()) { return result; } else { throw new FileNotFoundException("No image found for timestamp " + timestamp); } }
From source file:de.elomagic.carafile.server.bl.SeedBean.java
public void seedChunk(final InputStream inputStream, final String chunkId) throws IOException, GeneralSecurityException, JMSException { LOG.debug("Seeding chunk " + chunkId); Chunk chunk = chunkDAO.findByIdentifier(chunkId); if (chunk == null) { throw new FileNotFoundException( "Chunk id " + chunkId + " not found. File already registered at registry?"); }//w w w. ja v a 2 s .c om byte[] buf = new byte[chunk.getFileMeta().getChunkSize()]; int bufferSize; try (InputStream in = inputStream) { bufferSize = readBlock(in, buf); } catch (IOException ex) { throw ex; } // Check SHA-1 String sha1 = Hex.encodeHexString(DigestUtils.sha1(Arrays.copyOf(buf, bufferSize))); if (!chunk.getHash().equalsIgnoreCase(sha1)) { throw new GeneralSecurityException( "Chunk SHA-1 validation failed (Expected " + chunk.getHash() + ", but is " + sha1 + ")"); } repositoryBean.writeChunk(chunkId, buf, bufferSize); LOG.debug("Chunk id " + chunkId + " seed"); // Initiate to register at tracker LOG.debug("Queue up new file for registration."); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(chunkQueue); TextMessage message = session.createTextMessage(chunkId); messageProducer.send(message); connection.close(); }
From source file:com.amalto.core.servlet.LogViewerServlet.java
private File getLogFile(String location) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); File file = ResourceUtils.getFile(resolvedLocation); if (!file.exists()) { throw new FileNotFoundException("Log file [" + resolvedLocation + "] not found"); }//from w ww . ja va2 s. c o m return file; }