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.aurel.track.exchange.track.importer.TrackImportAction.java

/**
 * Render the import page/*from   w  ww.  j  av a 2s  . c  o m*/
 */
@Override

/**
 * Save the zip file and import the data 
 * @return
 */
public String execute() {
    LOGGER.info("Import started");
    InputStream inputStream;
    try {
        inputStream = new FileInputStream(uploadFile);
    } catch (FileNotFoundException e) {
        LOGGER.error("Getting the input stream for the zip failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")));
        return null;
    }

    /**
     * delete the old temporary attachment directory if exists from previous imports 
     */
    String tempAttachmentDirectory = AttachBL.getAttachDirBase() + File.separator + AttachBL.tmpAttachments;
    AttachBL.deleteDirectory(new File(tempAttachmentDirectory));

    /**
     * extract the zip to a temporary directory
     */
    ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(inputStream));
    final int BUFFER = 2048;
    File unzipTempDirectory = new File(tempAttachmentDirectory);
    if (!unzipTempDirectory.exists()) {
        unzipTempDirectory.mkdirs();
    }
    BufferedOutputStream dest = null;
    ZipEntry zipEntry;
    try {
        while ((zipEntry = zipInputStream.getNextEntry()) != null) {
            File destFile = new File(unzipTempDirectory, zipEntry.getName());
            // grab file's parent directory structure         
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new FileOutputStream(destFile);
            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
        }
        zipInputStream.close();
    } catch (Exception e) {
        LOGGER.error("Extracting the zip to the temporary directory failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")), false);
        return null;
    }

    /**
     * get the data file (the only file from the zip which is not an attachment)  
     */
    File importDataFile = new File(tempAttachmentDirectory, ExchangeFieldNames.EXCHANGE_ZIP_ENTRY);
    if (!importDataFile.exists()) {
        LOGGER.error("The file " + ExchangeFieldNames.EXCHANGE_ZIP_ENTRY + " not found in the zip");
        JSONUtility.encodeJSON(servletResponse,
                JSONUtility.encodeJSONFailure(getText("admin.actions.importTp.err.failed")), false);
        return null;
    }

    /**
     * field parser
     */
    LOGGER.debug("Parsing the fields");
    List<ISerializableLabelBean> customFieldsBeans = new ImporterFieldParser().parse(importDataFile);
    Map<Integer, Integer> fieldsMatcherMap = null;
    try {
        fieldsMatcherMap = TrackImportBL.getFieldMatchMap(customFieldsBeans);
    } catch (ImportExceptionList importExceptionList) {
        LOGGER.error("Getting the field match map failed ");
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importErrorMessageListJSON(
                        ErrorHandlerJSONAdapter.handleErrorList(importExceptionList.getErrorDataList(), locale),
                        null, true));
        return null;
    }

    /**
     * dropdown parser
     */
    LOGGER.debug("Parsing the external dropdowns");
    SortedMap<String, List<ISerializableLabelBean>> externalDropdowns = new ImporterDropdownParser()
            .parse(importDataFile, fieldsMatcherMap);

    /**
     * data parser
     */
    LOGGER.debug("Parsing the items");
    List<ExchangeWorkItem> externalReportBeansList = new ImporterDataParser().parse(importDataFile,
            fieldsMatcherMap);
    try {
        LOGGER.debug("Importing the items");
        ImportCounts importCounts = TrackImportBL.importWorkItems(externalReportBeansList, externalDropdowns,
                fieldsMatcherMap, personID, locale);
        LOGGER.debug("Imported " + importCounts.getNoOfCreatedIssues() + " new issues " + " modified "
                + importCounts.getNoOfUpdatedIssues());
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(true,
                        getText("admin.actions.importTp.lbl.result",
                                new String[] { Integer.valueOf(importCounts.getNoOfCreatedIssues()).toString(),
                                        Integer.valueOf(importCounts.getNoOfUpdatedIssues()).toString() }),
                        true, locale),
                false);
    } catch (ImportExceptionList importExceptionList) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importErrorMessageListJSON(
                        ErrorHandlerJSONAdapter.handleErrorList(importExceptionList.getErrorDataList(), locale),
                        null, true),
                false);
        return null;
    } catch (ImportException importException) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(false, getText(importException.getMessage()), true, locale),
                false);
        return null;
    } catch (Exception e) {
        JSONUtility.encodeJSON(servletResponse,
                ImportJSON.importMessageJSON(false, getText("admin.actions.importTp.err.failed"), true, locale),
                false);
        return null;
    }
    LOGGER.info("Import done");
    return null;
}

From source file:com.netease.qa.emmagee.utils.CpuInfo.java

/**
 * read the status of CPU.//  w  w  w  .java 2 s.c  o  m
 * 
 * @throws FileNotFoundException
 */
public void readCpuStat() {
    String processPid = Integer.toString(pid);
    String cpuStatPath = "/proc/" + processPid + "/stat";
    try {
        // monitor cpu stat of certain process
        RandomAccessFile processCpuInfo = new RandomAccessFile(cpuStatPath, "r");
        String line = "";
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.setLength(0);
        while ((line = processCpuInfo.readLine()) != null) {
            stringBuffer.append(line + "\n");
        }
        String[] tok = stringBuffer.toString().split(" ");
        processCpu = Long.parseLong(tok[13]) + Long.parseLong(tok[14]);
        processCpuInfo.close();
    } catch (FileNotFoundException e) {
        Log.w(LOG_TAG, "FileNotFoundException: " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    readTotalCpuStat();
}

From source file:net.bpelunit.framework.control.deploy.activevos9.ActiveVOS9Deployment.java

private void scanForBPELFiles() throws DeploymentException {
    @SuppressWarnings("unchecked")
    Iterator<File> pddFiles = FileUtils.iterateFiles(tempDirectory, new String[] { "pdd" }, true);

    while (pddFiles.hasNext()) {
        File pddFile = pddFiles.next();

        try {// ww w  .jav a  2  s .c  om
            Document pddXml = XMLUtil.parseXML(new FileInputStream(pddFile));
            Element pddRoot = pddXml.getDocumentElement();

            String locationInBPR = pddRoot.getAttribute("location");

            File bpelFile = new File(tempDirectory, locationInBPR);

            allProcesses.add(new BPELInfo(bpelFile, pddFile, pddXml));
        } catch (FileNotFoundException e) {
            throw new DeploymentException("File could not be read: " + e.getMessage(), e);
        } catch (SAXException e) {
            throw new DeploymentException("XML file could not be parsed: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new DeploymentException("XML file could not be read: " + e.getMessage(), e);
        } catch (ParserConfigurationException e) {
            throw new DeploymentException("XML file could not be parsed: " + e.getMessage(), e);
        } catch (JAXBException e) {
            throw new DeploymentException("BPEL file could not be parsed: " + e.getMessage(), e);
        }
    }
}

From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java

private void displayData() {
    if (dataDirectory != null) {
        outputGraphDataSeries.clear();/*from w w w.jav  a 2  s.co m*/

        // Create a copy of the data directory for the worker thread
        final File dataDirectory = this.dataDirectory;
        new Thread(() -> {
            if (dataDirectory.exists() && dataDirectory.isDirectory()) {
                for (File d : dataDirectory.listFiles()) {
                    if (d.exists() && d.isFile() && d.getName().endsWith(".csv")) {
                        try (BufferedReader dataReader = new BufferedReader(new FileReader(d))) {
                            String line;
                            while ((line = dataReader.readLine()) != null) {
                                String[] data = line.split(",");
                                if (data.length >= 2) {
                                    double error = Double.parseDouble(data[0]);
                                    double output = Double.parseDouble(data[1]);

                                    // Add to the data series on the UI
                                    // thread
                                    SwingUtilities.invokeLater(() -> {
                                        outputGraphDataSeries.add(error, output);
                                    });
                                } else {
                                    System.err.println("Too few values in data line: " + line);
                                }
                            }
                        } catch (FileNotFoundException e) {
                            System.err.println("Could not open data file: " + e.getMessage());
                        } catch (IOException e) {
                            System.err.println("Could not read data file: " + e.getMessage());
                        } catch (NumberFormatException e) {
                            System.err.println("Data is not a valid number: " + e.getMessage());
                        }
                    }
                }
            }
        }).start();
    }
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.DataBrowser.java

/**
 * generateQueryKey method stores queries in query history file.
 * /*from w  w  w.  j av a  2  s .com*/
 * @return Boolean true is operation is successful, false otherwise
 * @param properties
 *          a collection queries in form of key and values
 */
private boolean storeQueriesInFile(Properties properties) {
    boolean operationStatus = false;
    FileOutputStream fileOut = null;

    File file = new File(queryHistoryFile);
    try {
        fileOut = new FileOutputStream(file);
        properties.store(fileOut,
                resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_DESCRIPTION"));
        operationStatus = true;
    } catch (FileNotFoundException e) {

        if (LOGGER.infoEnabled()) {
            LOGGER.info(resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + " : "
                    + e.getMessage());
        }
    } catch (IOException e) {
        if (LOGGER.infoEnabled()) {
            LOGGER.info(e.getMessage());
        }
    } finally {
        if (fileOut != null) {
            try {
                fileOut.close();
            } catch (IOException e) {
                if (LOGGER.infoEnabled()) {
                    LOGGER.info(e.getMessage());
                }
            }
        }
    }
    return operationStatus;
}

From source file:edu.nwpu.gemfire.monitor.data.DataBrowser.java

/**
 * generateQueryKey method fetches queries from query history file
 * /*from  w  w  w  .j a  va2  s  .c o m*/
 * @return Properties A collection queries in form of key and values
 */
private ObjectNode fetchAllQueriesFromFile() {
    InputStream inputStream = null;
    JsonNode queriesJSON = mapper.createObjectNode();

    try {
        inputStream = new FileInputStream(Repository.get().getPulseConfig().getQueryHistoryFileName());
        String inputStreamString = new Scanner(inputStream, "UTF-8").useDelimiter("\\A").next();
        queriesJSON = mapper.readTree(inputStreamString);
    } catch (FileNotFoundException e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine(resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + " : "
                    + e.getMessage());
        }
    } catch (Exception e) {
        if (LOGGER.infoEnabled()) {
            LOGGER.info(e.getMessage());
        }
    } finally {
        // Close input stream
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (LOGGER.infoEnabled()) {
                    LOGGER.info(e.getMessage());
                }
            }
        }
    }

    return (ObjectNode) queriesJSON;
}

From source file:com.pivotal.gemfire.tools.pulse.internal.data.DataBrowser.java

/**
 * generateQueryKey method fetches queries from query history file
 * //from  w  w w  .j av a 2  s. c  o m
 * @return Properties A collection queries in form of key and values
 */
private Properties fetchAllQueriesFromFile() {
    InputStream inputStream = null;
    Properties properties = new Properties();

    try {
        inputStream = new FileInputStream(queryHistoryFile);
        if (inputStream != null) {
            // Load properties from input stream
            properties.load(inputStream);
        }
    } catch (FileNotFoundException e) {
        if (LOGGER.infoEnabled()) {
            LOGGER.info(resourceBundle.getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + " : "
                    + e.getMessage());
        }
    } catch (IOException e) {
        if (LOGGER.infoEnabled()) {
            LOGGER.info(e.getMessage());
        }
    } catch (Exception e) {
        if (LOGGER.infoEnabled()) {
            LOGGER.info(e.getMessage());
        }
    } finally {
        // Close input stream
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (LOGGER.infoEnabled()) {
                    LOGGER.info(e.getMessage());
                }
            }
        }
    }
    return properties;
}

From source file:com.tcs.base64.Base64ImagePlugin.java

private boolean saveImage(String b64String, String fileName, String dirName, Boolean overwrite,
        CallbackContext callbackContext) {
    boolean result = false;
    try {/*from  w  w w.j a  va  2s  .c o  m*/

        //Directory and File
        File dir = new File(dirName);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File file = new File(dirName, fileName);

        //Avoid overwriting a file
        if (!overwrite && file.exists()) {
            Log.v(TAG, "File already exists");
            //                return new PluginResult(PluginResult.Status.OK, "File already exists!");
            callbackContext.error("File already exists!");
            return false;
        }

        //Decode Base64 back to Binary format
        byte[] decodedBytes = Base64.decodeBase64(b64String.getBytes());

        //Save Binary file to phone
        file.createNewFile();
        FileOutputStream fOut = new FileOutputStream(file);
        fOut.write(decodedBytes);
        fOut.close();
        Log.v(TAG, "Saved successfully");
        callbackContext.success("Saved successfully!");
        //            return new PluginResult(PluginResult.Status.OK, "Saved successfully!");
        result = true;

    } catch (FileNotFoundException e) {
        Log.v(TAG, "File not Found");
        //            return new PluginResult(PluginResult.Status.ERROR, "File not Found!");
        callbackContext.error("File not Found!");
        result = false;
    } catch (IOException e) {
        Log.v(TAG, e.getMessage());
        //            return new PluginResult(PluginResult.Status.ERROR, e.getMessage());
        callbackContext.error("Exception :" + e.getMessage());
        result = false;
    }
    return result;
}

From source file:fi.smaa.jsmaa.gui.JSMAAMainFrame.java

public void open() {
    if (!checkSaveCurrentModel()) {
        return;/*w w  w .  ja  v a 2 s.  c om*/
    }
    FileLoadDialog dialog = new FileLoadDialog(this, "jsmaa", "JSMAA model files") {
        @Override
        public void doAction(String path, String extension) {
            try {
                File file = new File(path);
                InputStream fis = new FileInputStream(file);
                SMAAModel loadedModel = JSMAABinding.readModel(new BufferedInputStream(fis));
                fis.close();

                modelManager.setModel(loadedModel);
                modelManager.setModelFile(file);
            } catch (FileNotFoundException e) {
                JOptionPane.showMessageDialog(JSMAAMainFrame.this, "Error loading model: " + e.getMessage(),
                        "Load error", JOptionPane.ERROR_MESSAGE);
            } catch (InvalidModelVersionException e) {
                showErrorIncompatibleModel(path, "file contains a an incompatible JSMAA model version "
                        + e.getVersion() + ".\nOnly versions until " + SMAAModel.MODELVERSION
                        + " supported.\nTo open the file, upgrade to a newer version of JSMAA (www.smaa.fi)");
            } catch (Exception e) {
                e.printStackTrace();
                showErrorIncompatibleModel(path, "file doesn't dontain a JSMAA model");
            }
        }
    };
    dialog.loadActions();
}

From source file:com.galactogolf.genericobjectmodel.levelloader.LevelSet.java

private void saveToFile(File f) throws LevelSavingException {
    OutputStream output;/*from   w w w . j  a v a  2  s .c  o  m*/
    try {
        output = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        Log.e("File saving error", e.getMessage());
        throw new LevelSavingException(e.getMessage());
    }
    OutputStreamWriter writer = new OutputStreamWriter(output);

    String data;
    try {
        data = JSONSerializer.toJSON(this).toString(2);
    } catch (JSONException e) {
        Log.e("File saving error", e.getMessage());
        throw new LevelSavingException(e.getMessage());
    }

    try {
        writer.write(data);
        writer.flush();
        writer.close();

        output.close();

    } catch (IOException e) {
        Log.e("Exception", e.getMessage());
    }
}