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:edu.cornell.kfs.fp.batch.service.impl.ProcurementCardLoadFlatTransactionsServiceImpl.java

/**
 * Validates and parses the given file, then stores transactions into a temp table.
 * // w  w w  .jav  a2s .c  o  m
 * @param fileName The name of the file to be parsed.
 * @return This method always returns true.  An exception is thrown if a problem occurs while loading the file.
 * 
 * @see org.kuali.kfs.fp.batch.service.ProcurementCardCreateDocumentService#loadProcurementCardFile()
 */
@SuppressWarnings("unchecked")
public boolean loadProcurementCardFile(String fileName) {
    FileInputStream fileContents;
    try {
        fileContents = new FileInputStream(fileName);
    } catch (FileNotFoundException e1) {
        LOG.error("file to parse not found " + fileName, e1);
        throw new RuntimeException(
                "Cannot find the file requested to be parsed " + fileName + " " + e1.getMessage(), e1);
    }

    Collection<?> pcardTransactions = null;
    try {
        byte[] fileByteContent = IOUtils.toByteArray(fileContents);
        pcardTransactions = (Collection<?>) batchInputFileService.parse(procurementCardInputFileType,
                fileByteContent);
    } catch (IOException e) {
        LOG.error("error while getting file bytes:  " + e.getMessage(), e);
        throw new RuntimeException("Error encountered while attempting to get file bytes: " + e.getMessage(),
                e);
    } catch (ParseException e) {
        LOG.error(ERROR_PREFIX + e.getMessage());
        throw new RuntimeException(ERROR_PREFIX + e.getMessage(), e);
    }

    if (pcardTransactions == null || pcardTransactions.isEmpty()) {
        LOG.warn("No PCard transactions in input file " + fileName);
    }

    loadTransactions((List<? extends PersistableBusinessObject>) pcardTransactions);

    LOG.info("Total transactions loaded: " + Integer.toString(pcardTransactions.size()));
    return true;
}

From source file:com.cws.esolutions.security.dao.keymgmt.impl.FileKeyManager.java

/**
 * @see com.cws.esolutions.security.dao.keymgmt.interfaces.KeyManager#createKeys(java.lang.String)
 *///w  ww  .  j  a  v  a2  s  .c  om
public synchronized boolean createKeys(final String guid) throws KeyManagementException {
    final String methodName = FileKeyManager.CNAME
            + "#createKeys(final String guid) throws KeyManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", guid);
    }

    boolean isComplete = false;
    OutputStream publicStream = null;
    OutputStream privateStream = null;

    final File keyDirectory = FileUtils.getFile(keyConfig.getKeyDirectory() + "/" + guid);

    try {
        if (!(keyDirectory.exists())) {
            if (!(keyDirectory.mkdirs())) {
                throw new KeyManagementException(
                        "Configured key directory does not exist and unable to create it");
            }
        }

        keyDirectory.setExecutable(true, true);

        SecureRandom random = new SecureRandom();
        KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance(keyConfig.getKeyAlgorithm());
        keyGenerator.initialize(keyConfig.getKeySize(), random);
        KeyPair keyPair = keyGenerator.generateKeyPair();

        if (keyPair != null) {
            File privateFile = FileUtils
                    .getFile(keyDirectory + "/" + guid + SecurityServiceConstants.PRIVATEKEY_FILE_EXT);
            File publicFile = FileUtils
                    .getFile(keyDirectory + "/" + guid + SecurityServiceConstants.PUBLICKEY_FILE_EXT);

            if (!(privateFile.createNewFile())) {
                throw new IOException("Failed to store private key file");
            }

            if (!(publicFile.createNewFile())) {
                throw new IOException("Failed to store public key file");
            }

            privateFile.setWritable(true, true);
            publicFile.setWritable(true, true);

            privateStream = new FileOutputStream(privateFile);
            publicStream = new FileOutputStream(publicFile);

            IOUtils.write(keyPair.getPrivate().getEncoded(), privateStream);
            IOUtils.write(keyPair.getPublic().getEncoded(), publicStream);

            // assume success, as we'll get an IOException if the write failed
            isComplete = true;
        } else {
            throw new KeyManagementException("Failed to generate keypair. Cannot continue.");
        }
    } catch (FileNotFoundException fnfx) {
        throw new KeyManagementException(fnfx.getMessage(), fnfx);
    } catch (IOException iox) {
        throw new KeyManagementException(iox.getMessage(), iox);
    } catch (NoSuchAlgorithmException nsax) {
        throw new KeyManagementException(nsax.getMessage(), nsax);
    } finally {
        if (publicStream != null) {
            IOUtils.closeQuietly(publicStream);
        }

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

    return isComplete;
}

From source file:com.naval.gui.Gui.java

private void chargerPartie() {
    final JFileChooser fc = new JFileChooser(Config.getRepTravail());

    fc.addChoosableFileFilter(new GameFileFilter("serial", "Sauv de partie"));
    fc.setAcceptAllFileFilterUsed(false);

    int returnVal = fc.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        // TODO : load only if game is !=
        try {/*from  w  ww .j  av  a2 s  .c om*/
            partie = Partie.load(file.getAbsolutePath());

            menuFac.updateForLoad();
            update();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            hintBar.setText(e.getMessage());
        } catch (IOException e) {
            hintBar.setText(e.getMessage());
            e.printStackTrace();

        } catch (ClassNotFoundException e) {
            hintBar.setText(e.getMessage());
            e.printStackTrace();
        }
    }
    if (partie.ordres == null || partie.ordres.size() == 0) {
        for (Navire n : partie.navires) {
            // creation des 3 ordres pour le tour courant.
            partie.ordres.add(new Ordre(n.id, partie.minute));
            partie.ordres.add(new Ordre(n.id, partie.minute));
            partie.ordres.add(new Ordre(n.id, partie.minute));

        }
    }
}

From source file:com.michaeljones.hellohadoop.restclient.HadoopHdfsRestClient.java

public void UploadFile(String remoteRelativePath, String localPath) {
    // %1 nameNodeHost, %2 username %3 resource.
    String uri = String.format(BASIC_URL_FORMAT, nameNodeHost, username, remoteRelativePath);
    List<Pair<String, String>> queryParams = new ArrayList();
    queryParams.add(new Pair<>("user.name", "michaeljones"));
    queryParams.add(new Pair<>("op", "CREATE"));
    queryParams.add(new Pair<>("overwrite", "true"));

    try {//from w  w  w .  j ava 2  s  .  c  o  m
        StringBuilder redirectLocation = new StringBuilder();
        int httpCode = restImpl.PutFile(uri, localPath, queryParams, redirectLocation);

        // NB two separate PUTs may be needed which is not strictly REST, but
        // this is the Hadoop documented procedure.
        switch (httpCode) {
        case 307:
            // The above PUT to the Hadoop name node has returned us a redirection
            // to the Hadoop data node.
            String dataNodeURI = redirectLocation.toString();
            if (dataNodeURI.length() == 0) {
                LOGGER.error("Hadoop redirect location empty");
                throw new RuntimeException("Create file redirect error");
            }

            httpCode = restImpl.PutFile(dataNodeURI, localPath, null, null);
            break;

        case 201:
            // HTTP backends which correctly implement Expect: 100-continue?
            // Will return 201 created immediately.
            break;

        default:
            throw new RuntimeException("Create File failed : HTTP error code : " + httpCode);
        }

        if (httpCode != 201) {
            throw new RuntimeException("Create File failed : HTTP error code : " + httpCode);
        }
    } catch (FileNotFoundException ex) {
        LOGGER.error("Hadoop upload file not found: " + ex.getMessage());
        throw new RuntimeException("Create File failed : " + ex.getMessage());
    } finally {
        // We want to close TCP connections immediately, because garbage collection time
        // is non-deterministic.
        restImpl.Close();
    }
}

From source file:com.npower.unicom.sync.AbstractExportDaemonPlugIn.java

/**
 * /*from  w ww  .  j av  a 2  s  . c o m*/
 * @param date
 */
private void updateLastSyncTimeStamp(Date date) {
    File requestDir = this.getRequestDir();
    File file = new File(requestDir, AbstractExportDaemonPlugIn.FILENAME_LAST_SYNC_TIME_STAMP);
    try {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
        out.writeObject(date);
        out.close();
    } catch (FileNotFoundException e) {
        log.error("failure to update last sync time stamp: " + e.getMessage(), e);
    } catch (IOException e) {
        log.error("failure to update last sync time stamp: " + e.getMessage(), e);
    }
}

From source file:algorithm.laddress.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w ww  .  j  ava 2s  .  co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    // Create path components to save the file
    final String path = "C:\\Users\\Rads\\Documents\\NetBeansProjects\\capstone\\src\\java\\algorithm\\";
    final Part filePart = request.getPart("file");
    final String fileName = getFileName(filePart);

    OutputStream out = null;
    InputStream filecontent = null;
    final PrintWriter writer = response.getWriter();

    try {
        out = new FileOutputStream(new File(path + File.separator + fileName));
        filecontent = filePart.getInputStream();

        int read = 0;
        final byte[] bytes = new byte[1024];

        while ((read = filecontent.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        // writer.println("New file " + fileName + " created at " + path);
        LOGGER.log(Level.INFO, "File{0}being uploaded to {1}", new Object[] { fileName, path });
    } catch (FileNotFoundException fne) {
        writer.println("You either did not specify a file to upload or are "
                + "trying to upload a file to a protected or nonexistent " + "location.");
        writer.println("<br/> ERROR: " + fne.getMessage());

        LOGGER.log(Level.SEVERE, "Problems during file upload. Error: {0}", new Object[] { fne.getMessage() });
    }

    Scanner s = null;
    String listOfAddresses = "";
    try {
        String address = fileName;
        String dname = "C:\\Users\\Rads\\Documents\\NetBeansProjects\\capstone\\src\\java\\algorithm\\"
                + address;
        File f = new File(dname);
        s = new Scanner(f);
        //s.useDelimiter(",");   //Use the normal expression and exclude data we imagine they are not "WORDS"
    } catch (FileNotFoundException e) {

    }
    while (s.hasNextLine()) {
        String[] curr = s.nextLine().split(",");
        listOfAddresses = listOfAddresses + "<br/>" + curr[1];
    }
    String nextView = "user.jsp";
    request.setAttribute("Address", listOfAddresses);
    RequestDispatcher view = request.getRequestDispatcher(nextView);
    view.forward(request, response);
}

From source file:org.apache.manifoldcf.crawler.connectors.webcrawler.DataCache.java

/** Fetch binary data entry from the cache.
*@param documentIdentifier is the document identifier (url).
*@return a binary data stream.//from w  ww.  j  a va2s .c  om
*/
public synchronized InputStream getData(String documentIdentifier) throws ManifoldCFException {
    DocumentData dd = cacheData.get(documentIdentifier);
    if (dd == null)
        return null;
    try {
        return new FileInputStream(dd.getData());
    } catch (FileNotFoundException e) {
        throw new ManifoldCFException("File not found exception opening data: " + e.getMessage(), e);
    }
}

From source file:caarray.client.test.suite.ConfigurableTestSuite.java

/**
 * Loads and executes all of the test cases encapsulated in this suite, and
 * adds the test results to the given TestResultReport. The tests may be created
 * via input from a configuration file, but may also include tests determined
 * by other means./*from  ww  w. j ava2  s.c  om*/
 * 
 * @param resultReport The TestResultReport to which test results will be added.
 */
public void runTests(TestResultReport resultReport) {

    try {
        loadTestsFromFile();
        executeTests(resultReport);
    } catch (FileNotFoundException e) {
        String errorMessage = "An error occured reading an " + getType() + " configuration file: "
                + e.getMessage();
        resultReport.addErrorMessage(errorMessage);
        e.printStackTrace();
        log.error("Exception encountered:", e);
    } catch (IOException e) {
        String errorMessage = "An error occured executing the " + getType() + " test suite: " + e.getMessage();
        resultReport.addErrorMessage(errorMessage);
        e.printStackTrace();
        log.error("Exception encountered:", e);
    }

    catch (TestConfigurationException e) {
        String errorMessage = "An error occured executing the " + getType()
                + " test suite, probably due to an error in the configuration " + "file: " + e.getMessage();
        resultReport.addErrorMessage(errorMessage);
        e.printStackTrace();
        log.error("Exception encountered:", e);
    } catch (Throwable t) {
        String errorMessage = "An unexpected error occured executing the " + getType() + " : "
                + t.getLocalizedMessage();
        resultReport.addErrorMessage(errorMessage);
        t.printStackTrace();
        log.error("Exception encountered:", t);
    }

}

From source file:com.aurel.track.exchange.excel.ExcelFieldMatchAction.java

/**
 * Save the field mappings for the next use
 * @return// ww w.  j a v  a 2  s.  c  o  m
 */
public String save() {
    workbook = ExcelFieldMatchBL.loadWorkbook(excelMappingsDirectory, fileName);
    SortedMap<Integer, String> columnIndexToColumNameMap = ExcelFieldMatchBL.getFirstRowHeaders(workbook,
            selectedSheet);
    Map<String, Integer> columNameToFieldIDMap = ExcelFieldMatchBL
            .getColumnNameToFieldIDMap(columnIndexToFieldIDMap, columnIndexToColumNameMap);
    Set<Integer> lastSavedIdentifierFieldIDIsSet = new HashSet<Integer>();
    //add the explicitly selected field identifiers
    if (columnIndexIsIdentifierMap != null) {
        //at least a field was set as unique identifier
        Iterator<Integer> iterator = columnIndexIsIdentifierMap.keySet().iterator();
        while (iterator.hasNext()) {
            Integer columnIndex = iterator.next();
            Integer fieldID = columnIndexToFieldIDMap.get(columnIndex);
            Boolean isIdentifier = columnIndexIsIdentifierMap.get(columnIndex);
            if ((isIdentifier != null && isIdentifier.booleanValue())) {
                lastSavedIdentifierFieldIDIsSet.add(fieldID);
            }
        }
    }
    //add the implicitly selected field identifiers
    //the mandatory identifiers are disabled (to forbid unselecting them),
    //but it means that they will not be submitted by columnIndexIsIdentifierMap
    //so we should add them manually if a mandatoryIdentifierFields is mapped
    Set<Integer> mandatoryIdentifierFields = ExcelFieldMatchBL.getMandatoryIdentifierFields();
    Iterator<Integer> iterator = mandatoryIdentifierFields.iterator();
    Collection<Integer> submittedFieldIDs = columnIndexToFieldIDMap.values();
    while (iterator.hasNext()) {
        Integer mandatoryIdentifierField = iterator.next();
        if (submittedFieldIDs.contains(mandatoryIdentifierField)) {
            lastSavedIdentifierFieldIDIsSet.add(mandatoryIdentifierField);
        }
    }
    try {
        FileOutputStream fos = new FileOutputStream(new File(excelMappingsDirectory, mappingFileName));
        ObjectOutputStream out = new ObjectOutputStream(fos);
        out.writeObject(columNameToFieldIDMap);
        out.writeObject(lastSavedIdentifierFieldIDIsSet);
        out.close();
    } catch (FileNotFoundException e) {
        LOGGER.warn("Creating the output stream for mapping failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } catch (IOException e) {
        LOGGER.warn("Saving the mapping failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    return NEXT;
}

From source file:hydrograph.ui.perspective.ApplicationWorkbenchWindowAdvisor.java

/**
 * This function used to return Rest Service port Number which running on local
 *
 *//*from   www . j  a  v  a2  s.co  m*/
public String getServicePortFromPropFile(String propertyFile, String portNo, String serviceJar) {
    String portNumber = null;
    try (FileReader fileReader = new FileReader(XMLConfigUtil.CONFIG_FILES_PATH + propertyFile);) {
        Properties properties = new Properties();
        properties.load(fileReader);
        if (StringUtils.isNotBlank(properties.getProperty(serviceJar))) {
            portNumber = properties.getProperty(portNo);
        }
    } catch (FileNotFoundException e) {
        logger.error("File not exists", e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }

    return portNumber;
}