List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:edu.cornell.med.icb.goby.modes.AggregatePeaksByRPKMDifferenceMode.java
public static void writeAnnotations(final String outputFileName, final ObjectList<Annotation> annotationList, final boolean append) { PrintWriter writer = null;//from w w w. j a va 2 s .c om final File outputFile = new File(outputFileName); try { if (!outputFile.exists()) { writer = new PrintWriter(outputFile); // Write the file header writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } final ObjectListIterator<Annotation> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final Annotation annotation = annotIterator.next(); annotation.write(writer); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }
From source file:de.xirp.ate.ATEManager.java
/** * Loads the given maze file to the/*from w w w . jav a 2 s . c o m*/ * {@link de.xirp.ate.Maze} data structure. * * @param mazeFile * The file name of the maze to load. * @see de.xirp.util.serialization.ObjectDeSerializer */ public static void loadMaze(File mazeFile) { Maze maze = null; try { maze = ObjectDeSerializer.<Maze>getObject(mazeFile); setCurrentMaze(maze); fireMazeChanged(); } catch (FileNotFoundException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } catch (SerializationException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } // Construct a default maze when erros occur maze = new Maze(10, 10); setCurrentMaze(maze); fireMazeChanged(); }
From source file:com.impetus.ankush.common.utils.FileNameUtils.java
/** * Gets the extracted directory name.//w ww .java2s. c om * * @param archiveFile * the archive file * @return Directory name after extraction of archiveFile */ public static String getExtractedDirectoryName(String archiveFile) { String path = null; ONSFileType fileType = getFileType(archiveFile); if (fileType == ONSFileType.TAR_GZ || fileType == ONSFileType.GZ) { try { GZIPInputStream gzipInputStream = null; gzipInputStream = new GZIPInputStream(new FileInputStream(archiveFile)); TarArchiveInputStream tarInput = new TarArchiveInputStream(gzipInputStream); return tarInput.getNextTarEntry().getName(); } catch (FileNotFoundException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } } else if (fileType == ONSFileType.ZIP || fileType == ONSFileType.BIN) { ZipFile zf; try { zf = new ZipFile(archiveFile); Enumeration<? extends ZipEntry> entries = zf.entries(); return entries.nextElement().getName(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } return path; }
From source file:com.group7.dragonwars.engine.MapReader.java
private static List<String> readFile(final String filename, final Activity activity) { AssetManager am = activity.getAssets(); List<String> text = new ArrayList<String>(); try {//from w w w . j a va 2 s . c om BufferedReader in = new BufferedReader(new InputStreamReader(am.open(filename))); String line; while ((line = in.readLine()) != null) { text.add(line); } in.close(); } catch (FileNotFoundException fnf) { System.err.println("Couldn't find " + fnf.getMessage()); System.exit(1); } catch (IOException ioe) { System.err.println("Couldn't read " + ioe.getMessage()); System.exit(1); } return text; }
From source file:org.rapidpm.microservice.optionals.service.ServiceWrapper.java
private static String buildBaseUrl() { try {/*from www. ja v a 2 s . c om*/ String restPortFromFile = getRestPortFromFile(); return String.format("http://127.0.0.1:%d/%s", Integer.valueOf(restPortFromFile), CONTEXT_PATH_REST); } catch (FileNotFoundException e) { LOGGER.warning("The file " + MICROSERVICE_REST_FILE + " was not found. \n It seems like your service wasn't started"); exitHandler.exit(1); } catch (IOException e) { LOGGER.warning("The file " + MICROSERVICE_REST_FILE + " wasn't read/writeable. \n" + e.getMessage()); exitHandler.exit(1); } catch (NumberFormatException e) { LOGGER.warning( "The file " + MICROSERVICE_REST_FILE + " contained no readable port. \n" + e.getMessage()); LOGGER.warning("Remove the file and start the service again"); exitHandler.exit(1); } return null; //never reached }
From source file:com.commsen.apropos.core.PropertiesManager.java
/** * Saves data into {@link #dataFile}. This method is called by other static methods of this * class after modifying any data./*from w w w. ja va 2 s. com*/ */ private static void save() { FileOutputStream fileStream = null; try { fileStream = new FileOutputStream(dataFile); xStream.toXML(instance, fileStream); } catch (FileNotFoundException e) { throw new InternalError(e.getMessage()); } finally { if (fileStream != null) try { fileStream.close(); } catch (IOException e) { // oops failed to close stream } } }
From source file:com.aegiswallet.utils.BasicUtils.java
public static boolean isPasswordInDictionary(Context context, String password) { boolean resultBool = false; if (password == null) return false; try {/*from w ww . ja va 2 s. c om*/ AssetFileDescriptor descriptor = context.getAssets().openFd("commonpasswords.xmf"); FileReader reader = new FileReader(descriptor.getFileDescriptor()); // create a case sensitive word list and sort it ArrayWordList awl = WordLists.createFromReader(new FileReader[] { reader }, true, new ArraysSort()); WordListDictionary dict = new WordListDictionary(awl); DictionarySubstringRule dictRule = new DictionarySubstringRule(dict); dictRule.setWordLength(6); // size of words to check in the password dictRule.setMatchBackwards(true); // match dictionary words backwards List<Rule> ruleList = new ArrayList<Rule>(); ruleList.add(dictRule); PasswordValidator validator = new PasswordValidator(ruleList); PasswordData passwordData = new PasswordData(new Password(password.toLowerCase())); RuleResult result = validator.validate(passwordData); if (result.isValid()) { Log.d(TAG, "Valid password"); resultBool = true; } else { Log.d(TAG, "Invalid password"); } } catch (FileNotFoundException e) { Log.d(TAG, e.getMessage()); } catch (IOException e) { Log.d(TAG, e.getMessage()); } return resultBool; }
From source file:com.impetus.ankush.common.utils.FileNameUtils.java
/** * Gets the path from archive.//ww w . ja va2s .c o m * * @param archiveFile * the archive file * @param charSequence * the char sequence * @return the path from archive */ public static String getPathFromArchive(String archiveFile, String charSequence) { String path = null; ONSFileType fileType = getFileType(archiveFile); if (fileType == ONSFileType.TAR_GZ) { try { GZIPInputStream gzipInputStream = null; gzipInputStream = new GZIPInputStream(new FileInputStream(archiveFile)); TarArchiveInputStream tarInput = new TarArchiveInputStream(gzipInputStream); TarArchiveEntry entry; while (null != (entry = tarInput.getNextTarEntry())) { if (entry.getName().contains(charSequence)) { path = entry.getName(); break; } } } catch (FileNotFoundException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } } else if (fileType == ONSFileType.ZIP) { ZipFile zf; try { zf = new ZipFile(archiveFile); Enumeration<? extends ZipEntry> entries = zf.entries(); String fileName; while (entries.hasMoreElements()) { fileName = entries.nextElement().getName(); if (fileName.contains(charSequence)) { path = fileName; break; } } } catch (IOException e) { LOG.error(e.getMessage(), e); } } return path; }
From source file:com.stgmastek.core.logic.ExecutionOrder.java
/** * Saves the state of the batch for revision runs usage * If the current batch is 1000 and revision is 1 then the file would * be saved as '1000_1.savepoint' /*from w w w. ja v a2 s . c om*/ * * @param batchContext * The job batchContext of the batch * @throws BatchException * Any exception occurred during the serialization process */ public static synchronized void saveBatchState(BatchContext batchContext) throws BatchException { BatchInfo toSaveBatchInfo = batchContext.getBatchInfo(); toSaveBatchInfo.setProgressLevelAtLastSavePoint( (ProgressLevel) ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).clone()); //clone is necessary as ProgresLevel is static if (logger.isDebugEnabled()) { logger.debug("Saving Current Batch progress level as ==>" + ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).toString()); } String savepointFilePath = Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY"); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new FileOutputStream(FilenameUtils.concat(savepointFilePath, toSaveBatchInfo.getBatchNo() + "_" + toSaveBatchInfo.getBatchRevNo() + ".savepoint"))); oos.writeObject(toSaveBatchInfo); oos.flush(); batchContext.setBatchStateSaved(true); } catch (FileNotFoundException e) { batchContext.setBatchStateSaved(false); logger.error(e); throw new BatchException(e.getMessage(), e); } catch (IOException e) { batchContext.setBatchStateSaved(false); logger.error(e); throw new BatchException(e.getMessage(), e); } finally { IOUtils.closeQuietly(oos); } }
From source file:com.galactogolf.genericobjectmodel.levelloader.LevelSet.java
public static LevelSet loadLevelSetFromInternalStorage(String levelFilename, Context context) throws LevelLoadingException { File levelsDir = context.getDir(GameConstants.LOCATION_OF_LEVELS_CREATED_BY_USER, Context.MODE_PRIVATE); LevelSet levelSet;/*from w w w. j ava 2 s .com*/ File f = null; try { File[] files = levelsDir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].getName().equals(levelFilename)) { f = files[i]; } } if (f == null) { throw new LevelLoadingException("Level not found!"); } } catch (Exception ex) { Log.e("General exception", ""); return null; } FileInputStream input = null; try { input = new FileInputStream(f); } catch (FileNotFoundException e) { Log.e("File loading error", e.getMessage()); throw new LevelLoadingException(e.getMessage()); } levelSet = LoadLevelSetFromStream(input); // if this is a file with the id in the name, then check it matches the internal id UUID levelId = null; String[] fileNameParts = f.getName().split("[.]"); if (fileNameParts.length == 4) { levelId = UUID.fromString(fileNameParts[1]); } if (levelId != null && !levelSet.getId().equals(levelId)) { throw new LevelLoadingException("Id within filename and id within file do not agree"); } // manually set the file name to the correct one so prevent conflicts levelSet.setFileName(f.getName()); return levelSet; }