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:com.danjarvis.documentcontract.DocumentContract.java

/**
 * Creates a new file from the data resolved through the provided content URI.
 *
 * @return name of created file (residing at cordova.file.dataDirectory).
 *///from  ww w . j a  va2  s .  c  o  m
private void createFile(JSONObject args, CallbackContext callback) {
    try {
        Uri uri;
        String fileName;
        ContentResolver contentResolver;
        InputStream is;
        FileOutputStream fs;
        byte[] buffer;
        int read = 0;

        uri = getUri(args);
        if (null == uri || !(uri.getScheme().equals(ContentResolver.SCHEME_CONTENT))) {
            callback.error(INVALID_URI_ERROR);
            return;
        }

        fileName = getFileName(args);
        if (null == fileName) {
            callback.error(INVALID_PARAMS_ERROR);
            return;
        }

        contentResolver = cordova.getActivity().getContentResolver();
        if (null == contentResolver) {
            callback.error("Failed to get ContentResolver object.");
            return;
        }

        is = contentResolver.openInputStream(uri);
        fs = cordova.getActivity().openFileOutput(fileName, Context.MODE_PRIVATE);

        buffer = new byte[32768];
        while ((read = is.read(buffer, 0, buffer.length)) != -1) {
            fs.write(buffer, 0, read);
        }

        fs.close();
        fs.flush();
        is.close();

        callback.success(fileName);
    } catch (FileNotFoundException fe) {
        callback.error(fe.getMessage());
    } catch (IOException ie) {
        callback.error(ie.getMessage());
    }
}

From source file:com.przyjaznyplan.utils.CsvConverter.java

public void open(String path) throws FileNotFoundException {

    path = Environment.getExternalStorageDirectory().toString() + "/" + path;
    if (!new File(path).exists()) {
        Log.i("NO FILE", path + " DOES NOT EXIST");
        throw new FileNotFoundException(" DOES NOT EXIST");
    }/*from ww w.j  a v  a  2 s  .c o  m*/

    lines = new ArrayList<String[]>();
    try {
        reader = new CSVReader(new FileReader(path), SEPARATOR);
    } catch (FileNotFoundException e) {
        Log.e("CSV Reader EXCEPTION", e.getMessage());
    }
    String[] nextLine;

    try {
        while ((nextLine = reader.readNext()) != null) {

            lines.add(nextLine);

        }
    } catch (Exception e) {
        Log.e("CSV Reader EXCEPTION", e.getMessage());
    }

    rootFolder = new File(path).getParent();

}

From source file:net.dahanne.android.regalandroid.utils.FileUtils.java

/**
 * download the requested file from the gallery, and save it to cache
 * /*  w ww.  j  a  v  a2s .c  o  m*/
 * @param context
 * @param fileName
 * @param extension
 * @param imageUrl
 * @param isTemporary
 * @return
 * @throws GalleryConnectionException
 * @throws FileHandlingException
 */
public File getFileFromGallery(Context context, String fileName, String extension, String imageUrl,
        boolean isTemporary, int albumName) throws GalleryConnectionException, FileHandlingException {
    logger.debug(
            "gettingFileFromGallery, fileName : {} -- extension : {} -- imageUrl : {} -- isTemporary : {} -- albumName : {}",
            new Object[] { fileName, extension, imageUrl, isTemporary, albumName });
    File imageFileOnExternalDirectory = null;
    try {
        InputStream inputStreamFromUrl = null;
        String storageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(storageState)) {
            logger.debug("storage is mounted");
            File savePath = new File(Settings.getReGalAndroidCachePath(context) + "/" + albumName);
            // if the cache has never been used before
            if (!savePath.exists()) {
                // we make sure regalandroid path exists (ex : /regalandroid)
                File regalAndroidDirectory = new File(Settings.getReGalAndroidPath(context));
                regalAndroidDirectory.mkdir();
                // we then create regalandroid cache path (tmp)
                File regalAndroidCacheDirectory = new File(Settings.getReGalAndroidCachePath(context));
                regalAndroidCacheDirectory.mkdir();
                // and also that the specific album folder exists, bug #65
                File albumCacheDirectory = new File(
                        Settings.getReGalAndroidCachePath(context) + "/" + albumName);
                albumCacheDirectory.mkdir();

                // issue #30 : insert the .nomedia file so that the dir
                // won't be parsed by other photo apps
                File noMediaFile = new File(
                        Settings.getReGalAndroidCachePath(context) + "/" + albumName + NO_CACHE_PATH);
                if (!noMediaFile.createNewFile()) {
                    throw new FileHandlingException(context.getString(R.string.external_storage_problem));
                }
            }
            // if the file downloaded is not a cache file, but a file to
            // keep
            if (!isTemporary) {
                savePath = new File(Settings.getReGalAndroidPath(context));
                // if there is no file extension, we add the one that
                // corresponds to the picture (if we have it)
                if (fileName.lastIndexOf(".") == -1 && !StringUtils.isEmpty(extension)) {
                    fileName = fileName + "." + extension;
                }
            }
            logger.debug("savePath is : {}", savePath);
            //in case the filename has special characters
            imageFileOnExternalDirectory = new File(savePath, fileName);
            inputStreamFromUrl = RemoteGalleryConnectionFactory.getInstance().getInputStreamFromUrl(imageUrl);
        } else {
            throw new FileHandlingException(context.getString(R.string.external_storage_problem));
        }
        FileOutputStream fos;
        fos = new FileOutputStream(imageFileOnExternalDirectory);
        byte[] buf = new byte[1024];
        int len;
        while ((len = inputStreamFromUrl.read(buf)) > 0) {
            fos.write(buf, 0, len);
        }
        fos.close();
        inputStreamFromUrl.close();

    } catch (FileNotFoundException e) {
        throw new FileHandlingException(e.getMessage());
    } catch (IOException e) {
        throw new FileHandlingException(e.getMessage());
    }
    return imageFileOnExternalDirectory;
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.schema.validator.SchemaValidatorImpl.java

public SchemaValidationResult validate(File _xmlFile) {
    SchemaValidationResult result = new SchemaValidationResult();
    result.setInputFile(_xmlFile);//w  w  w.  jav a 2 s.  c o  m
    try {
        Validator validator = getValidator();
        Source source = getSource(_xmlFile);
        validator.validate(source);
    } catch (FileNotFoundException e) {
        result.setException(e);
        result.setStatus(SchemaValidationStatus.FILE_READ_FAILURE);
        result.setMessage(e.getMessage());
    } catch (SAXException e) {
        result.setException(e);
        result.setStatus(SchemaValidationStatus.FAILURE);
    } catch (IOException e) {
        result.setException(e);
        result.setStatus(SchemaValidationStatus.FAILURE);
    }

    return result;
}

From source file:com.impetus.ankush.agent.service.ServiceMonitor.java

/**
 * Method to collect service status by technology
 * //  w w  w .  j av a 2 s.  co m
 * @return
 */
private Map<String, Map<String, Boolean>> collectServiceStatus() {
    // Service Conf directory
    String serviceConfDir = conf.getStringValue(Constant.PROP_SERVICE_CONF_DIR);
    // ServiceConf directory file object.
    File serviceConfigDir = new File(serviceConfDir);
    LOGGER.info("ServiceConfDirectory:" + serviceConfDir);

    // Getting list of files whose name ends with XML extension in agent
    // services folder.
    File[] files = serviceConfigDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            // file name ends with XML extension.
            return name.endsWith(Constant.File_Extension.XML);
        }
    });

    Map<String, Map<String, Boolean>> serviceStatus = new HashMap<String, Map<String, Boolean>>();
    // Add agent status
    Map<String, Boolean> agentStatus = new HashMap<String, Boolean>();
    agentStatus.put(Constant.AGENT, true);
    serviceStatus.put(Constant.AGENT, agentStatus);

    // iterate over the files.
    for (File file : files) {
        LOGGER.info("Service File:" + file.getName());
        String componentName = FilenameUtils.getBaseName(file.getName());
        try {
            // java XML context object.
            JAXBContext jc = JAXBContext.newInstance(ServiceConfiguration.class);
            // Input stream reader.
            InputStream inputStream = new FileInputStream(file);
            // Buffered reader
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            // Creating un marshaller
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            // Getting component services
            ServiceConfiguration services = (ServiceConfiguration) unmarshaller.unmarshal(br);
            // Adding component service status against component.
            serviceStatus.put(componentName, getServiceStatus(services.getTypeServices()));
            LOGGER.info("Service Status Object:" + serviceStatus);
        } catch (FileNotFoundException e) {
            LOGGER.error(e.getMessage(), e);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    return serviceStatus;
}

From source file:com.github.jknack.amd4j.Amd4jMojo.java

/**
 * Execute the command.//w w  w . j  a  v  a2 s  .  c om
 *
 * @param amd4j An {@link Amd4j} instance.
 * @param basedir The working directory.
 * @param name The script's name to execute.
 * @throws IOException If something goes wrong.
 */
protected final void execute(final Amd4j amd4j, final String basedir, final String name)
        throws MojoExecutionException, MojoFailureException {
    try {
        Config config = merge(name, newConfig());
        if (isEmpty(config.getBaseUrl())) {
            config.setBaseUrl(".");
        } else if (!config.getBaseUrl().equals(".")) {
            // remove the user.dir prefix
            config.setBaseUrl(config.getBaseUrl().replace(basedir, ""));
        }
        getLog().debug("options:\n" + config + "\n");
        isTrue(!isEmpty(config.getName()), "The following option is required: %s", "name");
        doExecute(amd4j, config);
    } catch (FileNotFoundException ex) {
        processError(name, "File not found: " + ex.getMessage(), ex);
    } catch (IOException ex) {
        processError(name, "I/O error: " + ex.getMessage(), ex);
    } catch (IllegalArgumentException ex) {
        processError(name, ex.getMessage(), ex);
    } catch (Exception ex) {
        processError(name, "Unexpected error: " + ex.getMessage(), ex);
    }
}

From source file:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java

/**
 * init is called one time when the Servlet is loaded. This is the
 * place where one-time initialization is done. Specifically, we
 * load the properties file for this application.
 *
 * @param config servlet configuration information
 * @exception ServletException there was a problem with initialization
 *///from w ww. j  a  va 2s  .com
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {
        LOGGER.info("[FDS] Initialize oai servlet.");
        this.properties = OAIUtil.loadProperties();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new ServletException(e.getMessage());
    } catch (Throwable e) {
        e.printStackTrace();
        throw new ServletException(e.getMessage());
    }
}

From source file:com.hs.mail.imap.server.ImapServer.java

private DebuggingHandler createDebuggingHandler() {
    DebuggingHandler handler = new DebuggingHandler();
    String path = Config.getProperty("imap_protocol_log", null);
    if (path != null) {
        try {/*from  w w  w. jav a 2  s . c o  m*/
            FileOutputStream fos = new FileOutputStream(path);
            handler.setDebugOut(new PrintStream(fos));
        } catch (FileNotFoundException e) {
            // Ignore this exception
            log.error(e.getMessage());
        }
    }
    return handler;
}

From source file:com.ibm.watson.developer_cloud.text_to_speech.v1.TextToSpeechTest.java

/**
 * Test with voice as wav./*from w  ww .  j a va  2s .co m*/
 */
//@Test
public void testWithVoiceAsWav() {
    InputStream is = service.synthesize(text, Voice.EN_MICHAEL, MediaType.AUDIO_WAV);
    Assert.assertNotNull(is);

    try {
        writeInputStreamToOutputStream(is, new FileOutputStream("target/output.wav"));
    } catch (FileNotFoundException e) {
        Assert.fail(e.getMessage());
    }

}

From source file:it.publisys.ims.discovery.job.EntityTasks.java

@Scheduled(fixedRate = 600000, initialDelay = 5000)
public void reloadEntities() {
    log.debug("Reload Entities");

    log.debug("ServletContext: " + servletContext);

    try {//from  w  w w.j av a2s  . c om
        Resource resourceDir = new ClassPathResource(METADATA_DIR + "/" + GUARDS_DIR);

        if (!resourceDir.exists()) {
            throw new FileNotFoundException(
                    String.format("Directory dei Medatada non presente. [%s]", resourceDir));
        }

        List<File> files = loadMetadataXml(resourceDir.getFile());
        EntitiesDescriptorDocument entitiesDescriptorDocument = storeEntitiesFile(files);

        EntityDescriptorType[] entityDescriptorTypes = loadAndCacheEntities(entitiesDescriptorDocument);
        loadEntities(entityDescriptorTypes);

    } catch (FileNotFoundException fnfe) {
        log.warn(fnfe.getMessage(), fnfe);
    } catch (IOException ioe) {
        log.warn("Caricamento Metadata non riuscito.", ioe);
    }

}