Example usage for java.io FileNotFoundException getMessage

List of usage examples for java.io FileNotFoundException getMessage

Introduction

In this page you can find the example usage for java.io FileNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.test.ImporterTest.java

/**
 * @param importer to be used for unknown file import
 *//*  w  w  w  .  j a  v  a2 s.  com*/
public static void testUnknownFileImport(IImporter importer) {
    try {
        importer.importModelsFrom("unknown.file");
        fail("A file not found exception has been expected here!");
    } catch (FileNotFoundException e) {
        // expected exception
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + e.getMessage());
    }
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.test.ImporterTest.java

/**
 * @param importer to be used for unknown files import
 *///w  w  w .  j a  v a2  s.  c o m
public static void testUnknownFilesImport(IImporter importer) {
    try {
        ArrayList<String> files = new ArrayList<String>();
        files.add("unknown.file");
        importer.importModelsFrom(files);
        fail("A file not found exception has been expected here!");
    } catch (FileNotFoundException e) {
        // expected exception
    } catch (Exception e) {
        fail("Unexpected exception occurred: " + e.getMessage());
    }
}

From source file:com.excilys.ebi.utils.spring.log.logback.web.LogbackWebConfigurer.java

/**
 * Initialize Logback, including setting the web app root system property.
 * //  w  w  w .j a  va  2s. c  o  m
 * @param servletContext
 *            the current ServletContext
 * @see org.springframework.web.util.WebUtils#setWebAppRootSystemProperty
 */
public static void initLogging(ServletContext servletContext) {

    // Only perform custom Logback initialization in case of a config file.
    String location = getConfigLocation(servletContext);

    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
            LogbackConfigurer.initLogging(location);
        } catch (FileNotFoundException ex) {
            throw new IllegalArgumentException("Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
        } catch (JoranException e) {
            throw new RuntimeException("Unexpected error while configuring logback", e);
        }
    }
}

From source file:at.illecker.sentistorm.commons.util.io.IOUtils.java

public static InputStream getInputStream(String fileOrUrl, boolean unzip) {
    InputStream in = null;//  w w w.ja va2s  . c  om
    try {
        if (fileOrUrl.matches("https?://.*")) {
            URL u = new URL(fileOrUrl);
            URLConnection uc = u.openConnection();
            in = uc.getInputStream();
        } else {
            // 1) check if file is within jar
            in = IOUtils.class.getClassLoader().getResourceAsStream(fileOrUrl);

            // windows File.separator is \, but getting resources only works with /
            if (in == null) {
                in = IOUtils.class.getClassLoader().getResourceAsStream(fileOrUrl.replaceAll("\\\\", "/"));
            }

            // 2) if not found in jar, load from the file system
            if (in == null) {
                in = new FileInputStream(fileOrUrl);
            }
        }

        // unzip if necessary
        if ((unzip) && (fileOrUrl.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:it.geosolutions.geobatch.opensdi.csvingest.utils.CSVSchemaHandler.java

/**
 * Load a properties File and save the values in a Map
 * @param fileURL/*from www.jav a2  s .  c om*/
 * @return
 */
public static Map<String, String> loadProperties(File properties) {

    InputStream inStream = null;
    Map<String, String> propertiesMap = null;
    try {
        inStream = new FileInputStream(properties);
        Properties p = new Properties();
        p.load(inStream);
        propertiesMap = new HashMap<String, String>((Map) p);
    } catch (FileNotFoundException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException e) {
                inStream = null;
                LOGGER.error(e.getMessage(), e);
            }
        }
    }
    return propertiesMap;
}

From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java

public static String fileDigest(File file) {
    String md5;//from   w w w . ja  va 2  s.c o m
    try {
        FileInputStream fis = new FileInputStream(file);
        md5 = DigestUtils.md5Hex(fis);
        fis.close();
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return md5;
}

From source file:net.sf.firemox.tools.MSaveDeck.java

/**
 * Saves deck to ASCII file from specified staticTurnLists. This new file will
 * contain the card names sorted in alphabetical order with their quantity
 * with this format :<br>//  w  w  w  .  ja v a2s .  c o  m
 * <i>card's name </i> <b>; </b> <i>qty </i> <b>\n </b> <br>
 * 
 * @param fileName
 *          Name of new file.
 * @param names
 *          ListModel of card names.
 * @param parent
 *          the parent
 * @return true if the current deck has been correctly saved. false otherwise.
 */
public static boolean saveDeck(String fileName, MListModel<MCardCompare> names, JFrame parent) {
    PrintWriter outStream = null;
    try {
        // create the deckfile. If it was already existing, it would be scrathed.
        outStream = new PrintWriter(new FileOutputStream(fileName));
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(parent,
                "Cannot create/modify the specified deck file:" + fileName + "\n" + ex.getMessage(),
                "File creation problem", JOptionPane.ERROR_MESSAGE);
        return false;
    }

    Object[] namesArray = names.toArray();
    MCardCompare[] cards = new MCardCompare[namesArray.length];
    System.arraycopy(namesArray, 0, cards, 0, namesArray.length);

    // sorts names
    Arrays.sort(cards, new MCardCompare());
    // writes lines corresponding to this format : "card;quantity\n"
    for (int i = 0; i < cards.length; i++) {
        outStream.println(cards[i].toString());
    }
    IOUtils.closeQuietly(outStream);

    // successfull deck save
    JOptionPane.showMessageDialog(parent,
            "Saving file " + fileName.substring(fileName.lastIndexOf("/") + 1) + " was successfully completed.",
            "Save success", JOptionPane.INFORMATION_MESSAGE);
    return true;
}

From source file:com.aurel.track.exchange.docx.exporter.LaTeXExportBL.java

/**
 * Serializes the docx content into the response's output stream
 * @param response//  w  ww .j a  v  a  2 s. co  m
 * @param wordMLPackage
 * @return
 */
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));

    OutputStream outputStream = null;
    try {
        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));
    }

    return null;
}

From source file:ktdiedrich.imagek.SegmentationCMD.java

public static String getImageIdPath(int imageId) {
    String path = null;//from   www. j  a v  a 2  s.  co m
    Connection con = null;
    DbConn dbConn = new DbConn();
    try {
        con = dbConn.connect();
        Queries q = new Queries(con);
        path = q.getImagePath(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();
        }
    }
    return path;
}

From source file:net.shopxx.util.CompressUtils.java

public static void archive(File[] srcFiles, File destFile, String archiverName) {
    Assert.notNull(destFile);//from w w  w . ja  v a 2 s  .  c  o m
    Assert.state(!destFile.exists() || destFile.isFile());
    Assert.hasText(archiverName);

    File parentFile = destFile.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    ArchiveOutputStream archiveOutputStream = null;
    try {
        archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiverName,
                new BufferedOutputStream(new FileOutputStream(destFile)));
        if (ArrayUtils.isNotEmpty(srcFiles)) {
            for (File srcFile : srcFiles) {
                if (srcFile == null || !srcFile.exists()) {
                    continue;
                }
                Set<File> files = new HashSet<File>();
                if (srcFile.isFile()) {
                    files.add(srcFile);
                }
                if (srcFile.isDirectory()) {
                    files.addAll(FileUtils.listFilesAndDirs(srcFile, TrueFileFilter.INSTANCE,
                            TrueFileFilter.INSTANCE));
                }
                String basePath = FilenameUtils.getFullPath(srcFile.getCanonicalPath());
                for (File file : files) {
                    try {
                        String entryName = FilenameUtils.separatorsToUnix(
                                StringUtils.substring(file.getCanonicalPath(), basePath.length()));
                        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, entryName);
                        archiveOutputStream.putArchiveEntry(archiveEntry);
                        if (file.isFile()) {
                            InputStream inputStream = null;
                            try {
                                inputStream = new BufferedInputStream(new FileInputStream(file));
                                IOUtils.copy(inputStream, archiveOutputStream);
                            } catch (FileNotFoundException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } catch (IOException e) {
                                throw new RuntimeException(e.getMessage(), e);
                            } finally {
                                IOUtils.closeQuietly(inputStream);
                            }
                        }
                    } catch (IOException e) {
                        throw new RuntimeException(e.getMessage(), e);
                    } finally {
                        archiveOutputStream.closeArchiveEntry();
                    }
                }
            }
        }
    } catch (ArchiveException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(archiveOutputStream);
    }
}