List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException()
FileNotFoundException
with null
as its error detail message. From source file:at.bitfire.ical4android.AndroidTaskList.java
public static AndroidTaskList findByID(Account account, TaskProvider provider, AndroidTaskListFactory factory, long id) throws FileNotFoundException, CalendarStorageException { try {// w w w . j a v a 2 s.c o m @Cleanup Cursor cursor = provider.client.query( syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null, null, null); if (cursor != null && cursor.moveToNext()) { AndroidTaskList taskList = factory.newInstance(account, provider, id); ContentValues values = new ContentValues(cursor.getColumnCount()); DatabaseUtils.cursorRowToContentValues(cursor, values); taskList.populate(values); return taskList; } else throw new FileNotFoundException(); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query task list by ID", e); } }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public InputStream getInputStream(File file) throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }/*from w ww . j a v a 2s .c om*/ byte[] data = modifiedDataMapping.get(xidThreadLocal.get()).get(file); if (data == null) { data = oldDataMapping.get(xidThreadLocal.get()).get(file); } if (data == null) { throw new FileNotFoundException(); } return new ByteArrayInputStream(data); }
From source file:com.webpagebytes.cms.local.WPBLocalFileStorage.java
private void initializeFileStorage(String dataDirectory) throws IOException, FileNotFoundException { File fileBaseData = new File(dataDirectory); if (!fileBaseData.exists() || !fileBaseData.isDirectory()) { throw new FileNotFoundException(); }//from w w w. j ava2 s . c o m File publicDataDir = new File(getPathPublicDataDir()); if (!publicDataDir.exists()) { log.log(Level.INFO, "Create public dir for WBLocalCloudFileStorage " + publicDataDir.getAbsolutePath()); if (false == publicDataDir.mkdir()) { throw new IOException("Cannot create dir: " + publicDataDir.getPath()); } } File privateDataDir = new File(getPathPrivateDataDir()); if (!privateDataDir.exists()) { log.log(Level.INFO, "Create private dir for WBLocalCloudFileStorage " + privateDataDir.getAbsolutePath()); if (false == privateDataDir.mkdir()) { throw new IOException("Cannot create dir: " + privateDataDir.getPath()); } } File publicMetaDir = new File(getPathPublicMetaDir()); if (!publicMetaDir.exists()) { log.log(Level.INFO, "Create public meta dir for WBLocalCloudFileStorage " + publicMetaDir.getAbsolutePath()); if (false == publicMetaDir.mkdir()) { throw new IOException("Cannot create dir: " + publicMetaDir.getPath()); } } File privateMetaDir = new File(getPathPrivateMetaDir()); if (!privateMetaDir.exists()) { log.log(Level.INFO, "Create private meta dir for WBLocalCloudFileStorage " + privateMetaDir.getAbsolutePath()); if (false == privateMetaDir.mkdir()) { throw new IOException("Cannot create dir: " + privateMetaDir.getPath()); } } isInitialized = true; }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar findByID(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, long id) throws FileNotFoundException, CalendarStorageException { @Cleanup/*from w w w .ja v a 2 s .co m*/ EntityIterator iterCalendars = null; try { iterCalendars = CalendarContract.CalendarEntity.newEntityIterator(provider.query( syncAdapterURI(ContentUris.withAppendedId(CalendarContract.CalendarEntity.CONTENT_URI, id), account), null, null, null, null)); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendars", e); } if (iterCalendars.hasNext()) { ContentValues values = iterCalendars.next().getEntityValues(); AndroidCalendar calendar = factory.newInstance(account, provider, values.getAsLong(Calendars._ID)); calendar.populate(values); return calendar; } throw new FileNotFoundException(); }
From source file:com.magic.util.FileUtil.java
public static StringBuffer readTextFile(File file, boolean newline) throws FileNotFoundException, IOException { if (!file.exists()) { throw new FileNotFoundException(); }/*from www . j a va2s . com*/ StringBuffer buf = new StringBuffer(); BufferedReader in = null; try { in = new BufferedReader(new FileReader(file)); String str; while ((str = in.readLine()) != null) { buf.append(str); if (newline) { buf.append(System.getProperty("line.separator")); } } } catch (IOException e) { Debug.logError(e, module); throw e; } finally { if (in != null) { try { in.close(); } catch (IOException e) { Debug.logError(e, module); } } } return buf; }
From source file:de.fu_berlin.inf.dpp.core.util.FileUtils.java
/** * Move the file to the same location, adding the file extension "BACKUP" or * "_BACKUP_X" on file name where X is a number that matches a not used file * name.// w w w . ja v a 2 s.c o m * * @param file the {@link IFile} to rename * @param monitor a progress monitor to show progress to user * @throws IOException * @throws FileNotFoundException */ public static void backupFile(IFile file, IProgressMonitor monitor) throws IOException, FileNotFoundException { if (!file.exists()) { throw new FileNotFoundException(); } IProject project = file.getProject(); IPath originalBackupPath = file.getProjectRelativePath().addFileExtension("BACKUP"); IPath backupPath = originalBackupPath; for (int i = 0; i < 1000; i++) { if (!project.exists(backupPath)) { break; } backupPath = originalBackupPath.removeFileExtension().addFileExtension("BACKUP_" + i); } file.move(file.getFullPath().removeLastSegments(1).append(backupPath.lastSegment()), true); }
From source file:com.rogue.reginald.config.ConfigurationLoader.java
private void saveResource(String name) throws IOException, FileNotFoundException { File file = new File(name); System.out.println(String.format("Name = '%s', saving...", name)); InputStream is = ConfigurationLoader.class.getResourceAsStream(name); if (is == null) { throw new FileNotFoundException(); }//from w w w .jav a2 s . c o m if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[102400]; int len; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); } }
From source file:com.textocat.textokit.corpus.statistics.dao.corpus.XmiFileTreeCorpusDAO.java
@Override public Set<String> getAnnotatorIds(URI docURI) throws FileNotFoundException { if (annotatorsByDocument.containsKey(docURI)) { return annotatorsByDocument.get(docURI); } else {/*from w w w . j a v a 2 s . c o m*/ throw new FileNotFoundException(); } }
From source file:com.khepry.utilities.GenericUtilities.java
public static void displayLogFile(String logFilePath, long logSleepMillis, String xsltFilePath, String xsldFilePath) {/* w w w . j a v a 2s.c o m*/ Logger.getLogger("").getHandlers()[0].close(); // only display the log file // if the logSleepMillis property // is greater than zero milliseconds if (logSleepMillis > 0) { try { Thread.sleep(logSleepMillis); File logFile = new File(logFilePath); File xsltFile = new File(xsltFilePath); File xsldFile = new File(xsldFilePath); File tmpFile = File.createTempFile("tmpLogFile", ".xhtml", logFile.getParentFile()); if (logFile.exists()) { if (xsltFile.exists() && xsldFile.exists()) { String xslFilePath; String xslFileName; String dtdFilePath; String dtdFileName; try { xslFileName = new File(logFilePath).getName().replace(".xhtml", ".xsl"); xslFilePath = logFile.getParentFile().toString().concat("/").concat(xslFileName); FileUtils.copyFile(new File(xsltFilePath), new File(xslFilePath)); dtdFileName = new File(logFilePath).getName().replace(".xhtml", ".dtd"); dtdFilePath = logFile.getParentFile().toString().concat("/").concat(dtdFileName); FileUtils.copyFile(new File(xsldFilePath), new File(dtdFilePath)); } catch (IOException ex) { String message = Level.SEVERE.toString().concat(": ").concat(ex.getLocalizedMessage()); Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, message, ex); GenericUtilities.outputToSystemErr(message, logSleepMillis > 0); return; } BufferedWriter bw = Files.newBufferedWriter(Paths.get(tmpFile.getAbsolutePath()), Charset.defaultCharset(), StandardOpenOption.CREATE); List<String> logLines = Files.readAllLines(Paths.get(logFilePath), Charset.defaultCharset()); for (String line : logLines) { if (line.startsWith("<!DOCTYPE log SYSTEM \"logger.dtd\">")) { bw.write("<!DOCTYPE log SYSTEM \"" + dtdFileName + "\">\n"); bw.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslFileName + "\"?>\n"); } else { bw.write(line.concat("\n")); } } bw.write("</log>\n"); bw.close(); } // the following statement is commented out because it's not quite ready for prime-time yet // Files.write(Paths.get(logFilePath), transformLogViaXSLT(logFilePath, xsltFilePath).getBytes(), StandardOpenOption.CREATE); Desktop.getDesktop().open(tmpFile); } else { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, logFilePath, new FileNotFoundException()); } } catch (InterruptedException | IOException ex) { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:de.fosd.jdime.common.FileArtifact.java
/** * Constructs a new <code>FileArtifact</code> contained in the given <code>File</code>. * * @param revision//from w w w . j a v a 2s.c om * the <code>Revision</code> the artifact belongs to * @param file * the <code>File</code> in which the artifact is stored * @param checkExistence * whether to ensure that <code>file</code> exists * * @throws FileNotFoundException * if <code>checkExistence</code> is <code>true</code> and <code>file</code> does not exist according to {@link * java.io.File#exists()} */ public FileArtifact(Revision revision, File file, boolean checkExistence) throws FileNotFoundException { assert file != null; if (checkExistence && !file.exists()) { LOG.fatal("File not found: " + file.getAbsolutePath()); throw new FileNotFoundException(); } setRevision(revision); this.file = file; if (LOG.isTraceEnabled()) { LOG.trace("Artifact initialized: " + file.getPath()); LOG.trace("Artifact exists: " + exists()); LOG.trace("File exists: " + file.exists()); if (exists()) { LOG.trace("Artifact isEmpty: " + isEmpty()); } } }