Example usage for java.io FileNotFoundException getLocalizedMessage

List of usage examples for java.io FileNotFoundException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup.java

private boolean readGraphs(Set<Path> pathSet, RDFService rdfService, String type, OntModel baseModel) {

    int count = 0;

    boolean modelChanged = false;

    // For each file graph in the target directory update or add that graph to
    // the Jena SDB, and attach the graph as a submodel of the base model
    for (Path p : pathSet) {

        count++; // note this will count the empty files too
        try {//from  w w  w  . java2s .co m
            FileInputStream fis = new FileInputStream(p.toFile());
            try {
                OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
                String fn = p.getFileName().toString().toLowerCase();
                if (fn.endsWith(".n3") || fn.endsWith(".ttl")) {
                    model.read(fis, null, "N3");
                } else if (fn.endsWith(".owl") || fn.endsWith(".rdf") || fn.endsWith(".xml")) {
                    model.read(fis, null, "RDF/XML");
                } else if (fn.endsWith(".md")) {
                    // Ignore markdown files - documentation.
                } else {
                    log.warn("Ignoring " + type + " file graph " + p
                            + " because the file extension is unrecognized.");
                }

                if (!model.isEmpty() && baseModel != null) {
                    baseModel.addSubModel(model);
                    log.debug("Attached file graph as " + type + " submodel " + p.getFileName());
                }

                modelChanged = modelChanged | updateGraphInDB(rdfService, model, type, p);

            } catch (Exception ioe) {
                log.error("Unable to process file graph " + p, ioe);
                System.out.println("Unable to process file graph " + p);
                ioe.printStackTrace();
            } finally {
                fis.close();
            }
        } catch (FileNotFoundException fnfe) {
            log.warn(p + " not found. Unable to process file graph"
                    + ((fnfe.getLocalizedMessage() != null) ? fnfe.getLocalizedMessage() : ""));
        } catch (IOException ioe) {
            // this is for the fis.close() above.
            log.warn("Exception while trying to close file graph file: " + p, ioe);
        }
    } // end - for

    log.info("Read " + count + " " + type + " file graph" + ((count == 1) ? "" : "s"));

    return modelChanged;
}

From source file:org.deegree.services.wms.StyleRegistry.java

Style loadNoImport(String layerName, File file, boolean legend) {
    XMLInputFactory fac = XMLInputFactory.newInstance();
    FileInputStream in = null;/*w  w  w.jav  a2  s.c o  m*/
    try {

        LOG.debug("Trying to load{} style from '{}'", legend ? "" : " legend", file);
        in = new FileInputStream(file);
        Style sty = SymbologyParser.INSTANCE.parse(fac.createXMLStreamReader(file.toString(), in));

        if (legend) {
            monitoredLegendFiles.put(file, new Pair<Long, String>(file.lastModified(), layerName));
        } else {
            monitoredFiles.put(file, new Pair<Long, String>(file.lastModified(), layerName));
        }
        return sty;
    } catch (FileNotFoundException e) {
        LOG.info("Style file '{}' for layer '{}' could not be found: '{}'",
                new Object[] { file, layerName, e.getLocalizedMessage() });
    } catch (XMLStreamException e) {
        LOG.trace("Stack trace:", e);
        LOG.info("Style file '{}' for layer '{}' could not be loaded: '{}'",
                new Object[] { file, layerName, e.getLocalizedMessage() });
    } finally {
        closeQuietly(in);
    }
    return null;
}

From source file:org.apache.jmeter.save.converters.SampleResultConverter.java

protected void readFile(String resultFileName, SampleResult res) {
    File in = null;//from ww w .  j a v  a  2 s .co m
    InputStream fis = null;
    try {
        in = new File(resultFileName);
        fis = new BufferedInputStream(new FileInputStream(in));
        ByteArrayOutputStream outstream = new ByteArrayOutputStream(res.getBytes());
        byte[] buffer = new byte[4096];
        int len;
        while ((len = fis.read(buffer)) > 0) {
            outstream.write(buffer, 0, len);
        }
        outstream.close();
        res.setResponseData(outstream.toByteArray());
    } catch (FileNotFoundException e) {
        log.warn(e.getLocalizedMessage());
    } catch (IOException e) {
        log.warn(e.getLocalizedMessage());
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:org.jcryptool.crypto.classic.model.algorithm.ClassicAlgorithmCmd.java

public void execute(CommandLine commandLine) throws IllegalCommandException {
    /**/* w w  w.  j  a  va2  s  .c o  m*/
     * Order of argument reading:
     *       text
     *       currentAlphabet
     *       something
     *       key (last!)
     */
    super.execute(commandLine);

    currentAlphabet = null;

    result = new StringBuilder();

    // read text 

    try {

        InputStream inputStream = null;
        try {
            inputStream = handleInputOption(commandLine);
        } catch (FileNotFoundException e) {
            result.append(e.getLocalizedMessage());
            return;
        }

        // read currentAlphabet 

        AbstractAlphabet alphabet = handleAlphabetOption(commandLine);
        this.currentAlphabet = alphabet;

        // read other options

        int cryptMode = -1;
        if (commandLine.hasOption(MODEDECRYPTION_OPTIONNAME)) { //$NON-NLS-1$
            cryptMode = AbstractAlgorithm.DECRYPT_MODE;
        } else {
            cryptMode = AbstractAlgorithm.ENCRYPT_MODE;
        }

        boolean filter = !commandLine.hasOption(NOFILTER_OPTIONNAME); //$NON-NLS-1$

        // handle options contributed by subclasses

        handleOtherOptions(commandLine, result);

        // read the key

        char[] key = handleKeyOption(commandLine, result);

        // initialize the algorithm
        AbstractClassicAlgorithm algorithm = initializeAlgorithm(cryptMode, inputStream, alphabet, key, filter);

        //execute

        ClassicDataObject dataObject = (ClassicDataObject) algorithm.execute();

        //finish

        if (!commandLine.getArgList().isEmpty()) {
            result.append(Messages.ClassicAlgorithmCmd_ignoredargs);
            result.append(commandLine.getArgList());
            result.append("\n\n"); //$NON-NLS-1$
        }

        result.append(dataObject.getOutput());

    } catch (ParseException e) {
        result.append(Messages.ClassicAlgorithmCmd_error + e.getMessage());
    }

}

From source file:org.signserver.client.cli.defaultimpl.ValidateDocumentCommand.java

/**
 * Execute the signing operation./*w  w  w .j av a  2s  .c  o  m*/
 */
public final void run() {
    FileInputStream fin = null;
    try {
        final byte[] bytes;
        final Map<String, Object> requestContext = new HashMap<String, Object>();

        if (inFile == null) {
            bytes = data.getBytes();
        } else {
            requestContext.put("FILENAME", inFile.getName());
            fin = new FileInputStream(inFile);
            bytes = new byte[(int) inFile.length()];
            fin.read(bytes);
        }
        createValidator().validate(bytes, requestContext);

    } catch (FileNotFoundException ex) {
        LOG.error(MessageFormat.format(TEXTS.getString("FILE_NOT_FOUND:"), ex.getLocalizedMessage()));
    } catch (IllegalRequestException ex) {
        LOG.error(ex);
    } catch (CryptoTokenOfflineException ex) {
        LOG.error(ex);
    } catch (SignServerException ex) {
        LOG.error(ex);
    } catch (SOAPFaultException ex) {
        if (ex.getCause() instanceof AuthorizationRequiredException) {
            final AuthorizationRequiredException authEx = (AuthorizationRequiredException) ex.getCause();
            LOG.error("Authorization required: " + authEx.getMessage());
        }
        LOG.error(ex);
    } catch (IOException ex) {
        LOG.error(ex);
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException ex) {
                LOG.error("Error closing file", ex);
            }
        }
    }
}

From source file:com.epam.dlab.backendapi.core.commands.CommandExecutorMockAsync.java

/**
 * Describe action./*from   w w w  .j a  va2s. co  m*/
 */
private void describe() {
    String templateFileName;
    try {
        templateFileName = getAbsolutePath(findTemplatesDir(), parser.getImageType() + "_description.json");
    } catch (FileNotFoundException e) {
        throw new DlabException(
                "Cannot describe image " + parser.getImageType() + ". " + e.getLocalizedMessage(), e);
    }
    responseFileName = getAbsolutePath(parser.getResponsePath(), parser.getRequestId() + JSON_FILE_ENDING);

    log.debug("Create response file from {} to {}", templateFileName, responseFileName);
    File fileResponse = new File(responseFileName);
    File fileTemplate = new File(templateFileName);
    try {
        if (!fileTemplate.exists()) {
            throw new FileNotFoundException("File \"" + fileTemplate + "\" not found.");
        }
        if (!fileTemplate.canRead()) {
            throw new IOException("Cannot read file \"" + fileTemplate + "\".");
        }
        Files.createParentDirs(fileResponse);
        Files.copy(fileTemplate, fileResponse);
    } catch (IOException e) {
        throw new DlabException(
                "Can't create response file " + responseFileName + ": " + e.getLocalizedMessage(), e);
    }
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static boolean copy(File src, File dst) {
    FileInputStream srcStream = null;
    FileOutputStream dstStream = null;
    try {//from w w  w .j  a  va2s. co m
        srcStream = new FileInputStream(src);
        dstStream = new FileOutputStream(dst);
        dstStream.getChannel().transferFrom(srcStream.getChannel(), 0, srcStream.getChannel().size());
        return true;
    } catch (FileNotFoundException e) {
        Log.e("MyExpenses", e.getLocalizedMessage());
        return false;
    } catch (IOException e) {
        Log.e("MyExpenses", e.getLocalizedMessage());
        return false;
    } finally {
        try {
            srcStream.close();
        } catch (Exception e) {
        }
        try {
            dstStream.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.geotools.gce.imagemosaic.catalog.oracle.DataStoreWrapper.java

/**
 * Store the properties on disk//from  w  w w  .jav  a2  s. co m
 * @param properties
 * @param typeName
 */
protected void storeProperties(Properties properties, String typeName) {
    OutputStream outStream = null;
    try {
        final String propertiesPath = auxiliaryFolder.getAbsolutePath() + File.separatorChar + typeName
                + ".properties";
        outStream = new BufferedOutputStream(new FileOutputStream(new File(propertiesPath)));
        properties.store(outStream, null);
    } catch (FileNotFoundException e) {
        if (LOGGER.isLoggable(Level.WARNING)) {
            LOGGER.warning("Unable to store the mapping " + e.getLocalizedMessage());
        }
    } catch (IOException e) {
        if (LOGGER.isLoggable(Level.WARNING)) {
            LOGGER.warning("Unable to store the mapping " + e.getLocalizedMessage());
        }

    } finally {
        if (outStream != null) {
            IOUtils.closeQuietly(outStream);
        }
    }
}

From source file:org.tomahawk.libtomahawk.resolver.PipeLine.java

private PipeLine() {
    try {/* w  w w  .j av a2s  .co  m*/
        String[] plugins = TomahawkApp.getContext().getAssets().list("js/resolvers");
        for (String plugin : plugins) {
            String path = "js/resolvers/" + plugin + "/content";
            try {
                String rawJsonString = TomahawkUtils.inputStreamToString(
                        TomahawkApp.getContext().getAssets().open(path + "/metadata.json"));
                ScriptResolverMetaData metaData = InfoSystemUtils.getObjectMapper().readValue(rawJsonString,
                        ScriptResolverMetaData.class);
                ScriptResolver scriptResolver = new ScriptResolver(metaData, path, this);
                mResolvers.add(scriptResolver);
            } catch (FileNotFoundException e) {
                Log.e(TAG, "PipeLine: " + e.getClass() + ": " + e.getLocalizedMessage());
            } catch (JsonMappingException e) {
                Log.e(TAG, "PipeLine: " + e.getClass() + ": " + e.getLocalizedMessage());
            } catch (JsonParseException e) {
                Log.e(TAG, "PipeLine: " + e.getClass() + ": " + e.getLocalizedMessage());
            } catch (IOException e) {
                Log.e(TAG, "PipeLine: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
        }
    } catch (IOException e) {
        Log.e(TAG, "ensureInit: " + e.getClass() + ": " + e.getLocalizedMessage());
    }
    mResolvers.add(new DataBaseResolver(
            TomahawkApp.getContext().getString(R.string.local_collection_pretty_name), this));
    SpotifyResolver spotifyResolver = new SpotifyResolver(this);
    mResolvers.add(spotifyResolver);
    setAllResolversAdded(true);
}

From source file:eu.medsea.mimeutil.detector.MagicMimeMimeDetector.java

/**
 * Defer this call to the InputStream method
 *//*  w  w  w  .  j a v a2  s. co m*/
public Collection getMimeTypesFile(final File file) throws UnsupportedOperationException {
    InputStream in = null;
    try {
        return getMimeTypesInputStream(in = new BufferedInputStream(new FileInputStream(file)));
    } catch (FileNotFoundException e) {
        throw new UnsupportedOperationException(e.getLocalizedMessage());
    } catch (Exception e) {
        throw new MimeException(e);
    } finally {
        closeStream(in);
    }
}