List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:ktdiedrich.imagek.SegmentationCMD.java
public static void recordDatabase(Extractor3D segmentor, int imageId, String directory) { Connection con = null;/* w ww .j ava 2s.c o m*/ DbConn dbConn = new DbConn(); try { con = dbConn.connect(); Inserts inserts = new Inserts(con); String name = segmentor.getSegBaseName(); if (name.contains(File.separator)) { name = SegmentationCMD.parseDirectoryFileName(name)[1]; } int segmentationId = inserts.insertSegmentation(segmentor.getSeedClusterMin(), segmentor.getClusterSizeThreshold(), segmentor.getMaxChisq(), segmentor.getZDiff(), segmentor.getSeedHistogramThreshold(), segmentor.getScalpDist(), segmentor.getFillHolesTimes(), segmentor.getHoleFillDirections(), segmentor.getHoleFillRadius(), segmentor.getMedianFilterSize(), segmentor.getMedFilterStdDevAbove(), imageId, segmentor.getBubbleFillAlgorithm(), name + ".zip", // segFileName directory); System.out.println("Recorded Segmentation_id: " + segmentationId + " Image_id: " + imageId); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); } catch (SQLException e) { System.err.println(e.getMessage()); e.printStackTrace(); } finally { try { con.close(); } catch (SQLException e) { System.err.println(e.getMessage()); e.printStackTrace(); } } }
From source file:gsn.http.ac.ParameterSet.java
private static void changeSensorName(String filepath, String name) { File f = new File(filepath); Pattern pat = Pattern.compile("name[\\s]*=[\\s]*\"[\\s]*[\\S]+[\\s]*\""); Matcher match;/*w ww . j ava 2s . c o m*/ FileInputStream fs = null; InputStreamReader in = null; BufferedReader br = null; StringBuffer sb = new StringBuffer(); String textinLine; try { fs = new FileInputStream(f); in = new InputStreamReader(fs); br = new BufferedReader(in); while (true) { textinLine = br.readLine(); if (textinLine == null) break; if (textinLine.contains("<virtual-sensor")) { match = pat.matcher(textinLine); match.find(); textinLine = match.replaceFirst("name=\"" + name + "\""); } sb.append(textinLine + "\n"); } fs.close(); in.close(); br.close(); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } try { FileWriter fstream = new FileWriter(f); // write file again BufferedWriter outobj = new BufferedWriter(fstream); outobj.write(sb.toString()); outobj.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:co.paralleluniverse.photon.Photon.java
private static void printFinishStatistics(final Meter errors, final StripedTimeSeries<Long> sts, final StripedHistogram sh, final String testName) { final File file = new File(testName + ".txt"); try (PrintWriter out = new PrintWriter(file)) { out.println("ErrorsCounter: " + errors.getCount()); final long millisTime = new Date().getTime(); final long nanoTime = System.nanoTime(); sts.getRecords()/*from w w w.j a v a 2 s .c om*/ .forEach(rec -> out.println(df .format(new Date(millisTime - TimeUnit.NANOSECONDS.toMillis(nanoTime - rec.timestamp))) + " " + testName + " responseTime " + rec.value + "ms")); out.println("\nHistogram:"); for (int i = 0; i <= 100; i++) out.println(testName + " responseTimeHistogram " + i + "% : " + sh.getHistogramData().getValueAtPercentile(i)); System.out.println("Statistics file: " + file.getAbsolutePath()); } catch (final FileNotFoundException ex) { System.err.println(ex.getMessage()); } }
From source file:edu.harvard.i2b2.navigator.LoggerDialog.java
/** * reads the i2b2.log file in the classpath directory * //from w w w . ja v a2 s . co m * @param aFile * file * @return */ public static String getContents(File file) { // file contents StringBuffer contents = new StringBuffer(); // declared here to make visible to finally clause BufferedReader input = null; try { // this implementation reads one line at a time // FileReader always assumes default encoding input = new BufferedReader(new FileReader(file)); String line = null; while ((line = input.readLine()) != null) { contents.append(line); contents.append(System.getProperty("line.separator")); } } catch (FileNotFoundException ex) { // ex.printStackTrace(); // System.out.println(ex.getMessage()); log.error(ex.getMessage()); } catch (IOException ex) { // ex.printStackTrace(); // System.out.println(ex.getMessage()); log.error(ex.getMessage()); } finally { try { if (input != null) { // flush and close input streams and readers input.close(); } } catch (IOException ex) { // ex.printStackTrace(); // System.out.println(ex.getMessage()); log.error(ex.getMessage()); } } return contents.toString(); }
From source file:de.thischwa.pmcms.server.ServletUtils.java
public static boolean writeFile(HttpServletResponse resp, File reqFile) { boolean retVal = false; InputStream in = null;/*from w w w.j a v a 2s . c o m*/ try { in = new BufferedInputStream(new FileInputStream(reqFile)); IOUtils.copy(in, resp.getOutputStream()); logger.debug("File successful written to servlet response: " + reqFile.getAbsolutePath()); } catch (FileNotFoundException e) { logger.error("Resource not found: " + reqFile.getAbsolutePath()); } catch (IOException e) { logger.error(String.format("Error while rendering [%s]: %s", reqFile.getAbsolutePath(), e.getMessage()), e); } finally { IOUtils.closeQuietly(in); } return retVal; }
From source file:com.aurel.track.exchange.latex.exporter.LaTeXExportBL.java
/** * Serializes the docx content into the response's output stream * @param response// w w w.j a v a 2s . c o m * @param wordMLPackage * @return */ public static String prepareReportResponse(HttpServletResponse response, TWorkItemBean workItem, ReportBeans reportBeans, TPersonBean user, Locale locale, String templateDir, String templateFile) { ReportBeansToLaTeXConverter rl = new ReportBeansToLaTeXConverter(); File pdf = rl.generatePdf(workItem, reportBeans.getItems(), true, locale, user, "", "", false, new File(templateFile), new File(templateDir)); String fileName = workItem.getSynopsis() + ".pdf"; String contentType = "application/pdf"; if (pdf.length() < 10) { pdf = new File(pdf.getParent() + "/errors.txt"); fileName = workItem.getSynopsis() + ".txt"; contentType = "text"; } OutputStream outputStream = null; try { response.reset(); response.setHeader("Content-Type", contentType); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); DownloadUtil.prepareCacheControlHeader(ServletActionContext.getRequest(), response); outputStream = response.getOutputStream(); InputStream is = new FileInputStream(pdf); IOUtils.copy(is, outputStream); is.close(); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } // Docx4J.save(wordMLPackage, outputStream, Docx4J.FLAG_NONE); // //wordMLPackage.save(outputStream); // /*SaveToZipFile saver = new SaveToZipFile(wordMLPackage); // saver.save(outputStream);*/ // } catch (Exception e) { // LOGGER.error("Exporting the docx failed with throwable " + e.getMessage()); // LOGGER.debug(ExceptionUtils.getStackTrace(e)); // } return null; }
From source file:com.cws.esolutions.security.listeners.SecurityServiceInitializer.java
/** * Shuts down the running security service process. *///ww w . j a v a 2s. c o m public static void shutdown() { final String methodName = SecurityServiceInitializer.CNAME + "#shutdown()"; if (DEBUG) { DEBUGGER.debug(methodName); } final SecurityConfigurationData config = SecurityServiceInitializer.svcBean.getConfigData(); Map<String, DataSource> dsMap = SecurityServiceInitializer.svcBean.getDataSources(); if (DEBUG) { DEBUGGER.debug("SecurityConfigurationData: {}", config); } try { DAOInitializer.closeAuthConnection( new FileInputStream(FileUtils.getFile(config.getSecurityConfig().getAuthConfig())), false, svcBean); if (dsMap != null) { for (String key : dsMap.keySet()) { if (DEBUG) { DEBUGGER.debug("Key: {}", key); } BasicDataSource dataSource = (BasicDataSource) dsMap.get(key); if (DEBUG) { DEBUGGER.debug("BasicDataSource: {}", dataSource); } if ((dataSource != null) && (!(dataSource.isClosed()))) { dataSource.close(); } } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); } catch (FileNotFoundException fnfx) { ERROR_RECORDER.error(fnfx.getMessage(), fnfx); } }
From source file:org.openbaton.vnfm.utils.Utils.java
public static void loadExternalProperties(Properties properties) { if (properties.getProperty("external-properties-file") != null) { File externalPropertiesFile = new File(properties.getProperty("external-properties-file")); if (externalPropertiesFile.exists()) { log.debug("Loading properties from external-properties-file: " + properties.getProperty("external-properties-file")); InputStream is = null; try { is = new FileInputStream(externalPropertiesFile); properties.load(is);// ww w . j a v a2 s .c o m } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } } else { log.debug("external-properties-file: " + properties.getProperty("external-properties-file") + " doesn't exist"); } } }
From source file:net.minecraftforge.fml.common.asm.transformers.MarkerTransformer.java
private static void processJar(File inFile, File outFile, MarkerTransformer[] transformers) throws IOException { ZipInputStream inJar = null;// w w w . ja va2s . c o m ZipOutputStream outJar = null; try { try { inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile))); } catch (FileNotFoundException e) { throw new FileNotFoundException("Could not open input file: " + e.getMessage()); } try { outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile))); } catch (FileNotFoundException e) { throw new FileNotFoundException("Could not open output file: " + e.getMessage()); } ZipEntry entry; while ((entry = inJar.getNextEntry()) != null) { if (entry.isDirectory()) { outJar.putNextEntry(entry); continue; } byte[] data = new byte[4096]; ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream(); int len; do { len = inJar.read(data); if (len > 0) { entryBuffer.write(data, 0, len); } } while (len != -1); byte[] entryData = entryBuffer.toByteArray(); String entryName = entry.getName(); if (entryName.endsWith(".class") && !entryName.startsWith(".")) { ClassNode cls = new ClassNode(); ClassReader rdr = new ClassReader(entryData); rdr.accept(cls, 0); String name = cls.name.replace('/', '.').replace('\\', '.'); for (MarkerTransformer trans : transformers) { entryData = trans.transform(name, name, entryData); } } ZipEntry newEntry = new ZipEntry(entryName); outJar.putNextEntry(newEntry); outJar.write(entryData); } } finally { IOUtils.closeQuietly(outJar); IOUtils.closeQuietly(inJar); } }
From source file:edu.cornell.med.icb.goby.modes.AggregatePeaksByPeakDistanceMode.java
public static void writeAnnotations(final String outputFileName, final ObjectList<Annotation> annotationList, final boolean append) { PrintWriter writer = null;/* www.jav a2 s. c o m*/ final File outputFile = new File(outputFileName); try { if (!outputFile.exists()) { writer = new PrintWriter(outputFile); writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } if (writer != null) { final ObjectListIterator<Annotation> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final Annotation annotation = annotIterator.next(); annotation.write(writer); } } else { System.err.println("Cannot write annotations to file: " + outputFileName); System.err.println("The writer failed to initialize."); System.exit(1); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }