List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.shengpay.commons.bp.logback.LogbackWebConfigurer.java
/** * Initialize logback, including setting the web app root system property. * /*ww w. j av a 2 s . co m*/ * @param servletContext * the current ServletContext * @see WebUtils#setWebAppRootSystemProperty */ public static void initLogging(ServletContext servletContext) { // Expose the web app root system property. if (exposeWebAppRoot(servletContext)) { WebUtils.setWebAppRootSystemProperty(servletContext); } // Only perform custom logback initialization in case of a config file. String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); if (location != null) { // Perform actual logback initialization; else rely on logback's default initialization. try { // Return a URL (e.g. "classpath:" or "file:") as-is; // consider a plain file path as relative to the web application root directory. if (!ResourceUtils.isUrl(location)) { // Resolve system property placeholders before resolving real path. location = SystemPropertyUtils.resolvePlaceholders(location); location = WebUtils.getRealPath(servletContext, location); } // Write log message to server log. servletContext.log("Initializing logback from [" + location + "]"); // Initialize without refresh check, i.e. without logback's watchdog thread. LogbackConfigurer.initLogging(location); } catch (FileNotFoundException ex) { throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage()); } } }
From source file:Zip.java
/** * Reads a GZIP file and dumps the contents to the console. *//*w w w . j av a2 s . c om*/ public static void readGZIPFile(String fileName) { // use BufferedReader to get one line at a time BufferedReader gzipReader = null; try { // simple loop to dump the contents to the console gzipReader = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(fileName)))); while (gzipReader.ready()) { System.out.println(gzipReader.readLine()); } gzipReader.close(); } catch (FileNotFoundException fnfe) { System.out.println("The file was not found: " + fnfe.getMessage()); } catch (IOException ioe) { System.out.println("An IOException occurred: " + ioe.getMessage()); } finally { if (gzipReader != null) { try { gzipReader.close(); } catch (IOException ioe) { } } } }
From source file:net.shopxx.util.CompressUtils.java
public static void extract(File srcFile, File destDir) { Assert.notNull(srcFile);/* w ww . j a v a 2s . co m*/ Assert.state(srcFile.exists()); Assert.state(srcFile.isFile()); Assert.notNull(destDir); Assert.state(!destDir.exists() || destDir.isDirectory()); destDir.mkdirs(); ArchiveInputStream archiveInputStream = null; try { archiveInputStream = new ArchiveStreamFactory() .createArchiveInputStream(new BufferedInputStream(new FileInputStream(srcFile))); ArchiveEntry archiveEntry; while ((archiveEntry = archiveInputStream.getNextEntry()) != null) { if (archiveEntry.isDirectory()) { new File(destDir, archiveEntry.getName()).mkdirs(); } else { OutputStream outputStream = null; try { outputStream = new BufferedOutputStream( new FileOutputStream(new File(destDir, archiveEntry.getName()))); IOUtils.copy(archiveInputStream, outputStream); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(outputStream); } } } } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } catch (ArchiveException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(archiveInputStream); } }
From source file:edu.purdue.cybercenter.dm.util.Helper.java
public static String fileToString(String filename) { String content;//from ww w .j a v a 2 s . com File file = new File(filename); try (InputStream is = new FileInputStream(file)) { content = IOUtils.toString(is); } catch (FileNotFoundException ex) { throw new RuntimeException(String.format("%s: file does not exist: %s", ex.getMessage(), filename)); } catch (IOException ex) { throw new RuntimeException( String.format("%s: Unable to convert file to string: %s", ex.getMessage(), filename)); } return content; }
From source file:com.asksven.commandcenter.valueobjects.CommandReaderWriter.java
public static void writeFile(Context ctx, CommandCollection data, String strFileName) { try {/*from w ww .java 2s . c o m*/ FileOutputStream target = new FileOutputStream( DataStorage.getExternalStoragePath(ctx) + "/" + strFileName); writeStream(data, target); target.close(); } catch (FileNotFoundException e) { Log.e(TAG, "File could not be written: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "File could not be closed: " + e.getMessage()); e.printStackTrace(); } }
From source file:io.dataapps.chlorine.finder.FinderEngine.java
private static InputStream getInputStream(String fileName, boolean fromClassPath) { InputStream in = null;// w ww . ja v a 2 s . c o m if (fromClassPath) { in = FinderEngine.class.getClassLoader().getResourceAsStream(fileName); } else { try { in = new FileInputStream(fileName); } catch (FileNotFoundException e) { LOG.warn(e.getMessage()); } } return in; }
From source file:at.illecker.sentistorm.commons.util.io.IOUtils.java
public static InputStream getInputStream(File file) { InputStream in = null;//from w w w .j a v a 2 s . c o m try { in = new FileInputStream(file); // unzip if necessary if (file.getName().endsWith(".gz")) { in = new GZIPInputStream(in, GZIP_FILE_BUFFER_SIZE); } // buffer input stream in = new BufferedInputStream(in); } catch (FileNotFoundException e) { LOG.error("FileNotFoundException: " + e.getMessage()); } catch (IOException e) { LOG.error("IOException: " + e.getMessage()); } return in; }
From source file:fr.ens.biologie.genomique.eoulsan.actions.ClusterTaskAction.java
/** * Execute the task.//w w w.jav a 2 s . com * @param taskContextFile context file */ private static void run(final DataFile taskContextFile) { checkNotNull(taskContextFile, "contextFile is null"); // Get Eoulsan runtime final LocalEoulsanRuntime localRuntime = (LocalEoulsanRuntime) EoulsanRuntime.getRuntime(); // Set the cluster task mode localRuntime.setMode(EoulsanExecMode.CLUSTER_TASK); try { // Execute the task TaskSerializationUtils.execute(taskContextFile); } catch (FileNotFoundException e) { Common.errorExit(e, "File not found: " + e.getMessage()); } catch (IOException e) { Common.errorExit(e, "IOException: " + e.getMessage()); } catch (EoulsanRuntimeException e) { Common.errorExit(e, "Error while executing " + Globals.APP_NAME_LOWER_CASE + ": " + e.getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.worldline.easycukes.commons.helpers.FileHelper.java
/** * Extracts the content of a zip folder in a specified directory * * @param from a {@link String} representation of the URL containing the zip * file to be unzipped//from w w w .j av a2s .c om * @param to the path on which the content should be extracted * @throws IOException if anything's going wrong while unzipping the content of the * provided zip folder */ public static void unzip(@NonNull String from, @NonNull String to, boolean isRemote) throws IOException { @Cleanup ZipInputStream zip = null; if (isRemote) zip = new ZipInputStream(new FileInputStream(from)); else zip = new ZipInputStream(FileHelper.class.getResourceAsStream(from)); log.debug("Extracting zip from: " + from + " to: " + to); // Extract without a container directory if exists ZipEntry entry = zip.getNextEntry(); String rootDir = "/"; if (entry != null) if (entry.isDirectory()) rootDir = entry.getName(); else { final String filePath = to + entry.getName(); // if the entry is a file, extracts it try { extractFile(zip, filePath); } catch (final FileNotFoundException fnfe) { log.warn(fnfe.getMessage(), fnfe); } } zip.closeEntry(); entry = zip.getNextEntry(); // iterates over entries in the zip file while (entry != null) { String entryName = entry.getName(); if (entryName.startsWith(rootDir)) entryName = entryName.replaceFirst(rootDir, ""); final String filePath = to + "/" + entryName; if (!entry.isDirectory()) // if the entry is a file, extracts it try { extractFile(zip, filePath); } catch (final FileNotFoundException fnfe) { log.warn(fnfe.getMessage(), fnfe); } else { // if the entry is a directory, make the directory final File dir = new File(filePath); dir.mkdir(); } zip.closeEntry(); entry = zip.getNextEntry(); } // delete the zip file if recovered from URL if (isRemote) new File(from).delete(); }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.VitroResourceBundle.java
/** * Returns the bundle for the for foo_ba_RR, providing that * foo_ba_RR.properties exists in the I18n area of either the theme or the * application.//from w w w .j a v a 2s. c o m * * If the desired file doesn't exist in either location, return null. * Usually, this does not indicate a problem but only that we were looking * for too specific a bundle. For example, if the base name of the bundle is * "all" and the locale is "en_US", we will likely return null on the search * for all_en_US.properties, and all_en.properties, but will return a full * bundle for all.properties. * * Of course, if all.properties doesn't exist either, then we have a * problem, but that will be reported elsewhere. * * @return the populated bundle or null. */ public static VitroResourceBundle getBundle(String bundleName, ServletContext ctx, String appI18nPath, String themeI18nPath, Control control) { try { return new VitroResourceBundle(bundleName, ctx, appI18nPath, themeI18nPath, control); } catch (FileNotFoundException e) { log.debug(e.getMessage()); return null; } catch (Exception e) { log.warn(e, e); return null; } }