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:Forms.FrmPrincipal.java

private void btnFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileActionPerformed
    // TODO add your handling code here:
    File sArchivo;/*from  w  ww.j ava2  s.  c  o m*/
    JFileChooser archivo = new JFileChooser();
    BufferedReader br = null;
    int lin = 0;
    patrones = new ArrayList<String[]>();

    try {
        archivo.setCurrentDirectory(new File(System.getProperty("user.home")));
        int result = archivo.showOpenDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
            sArchivo = archivo.getSelectedFile();
            txtArchivo.setText(sArchivo.getAbsolutePath());

            br = new BufferedReader(new FileReader(sArchivo.getAbsolutePath()));
            String linea = br.readLine();
            while (null != linea) {
                String[] campos = linea.split(SEPARADOR);
                numEntradas = campos.length;
                patrones.add(campos);
                linea = br.readLine();
                lin++;
            }
        }

        llenaMatriz();

    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage());
        Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage());
        Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (null != br)
            try {
                br.close();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
                Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
}

From source file:com.omertron.pushoverapi.PushoverApi.java

public boolean propertiesLoad(String filename) {
    Properties props = new Properties();

    InputStream propsStream = null;
    File propsFile = new File(filename);
    try {/*from w  w  w  .ja  v a2  s .c  o  m*/
        propsStream = new FileInputStream(propsFile);
        props.load(propsStream);
    } catch (FileNotFoundException ex) {
        LOG.warn("Property file '{}' not found.", propsFile.getAbsolutePath());
        return Boolean.FALSE;
    } catch (IOException ex) {
        LOG.warn("Error processing properties file '{}', error: {}", propsFile.getAbsolutePath(),
                ex.getMessage());
        return Boolean.FALSE;
    } finally {
        if (propsStream != null) {
            try {
                propsStream.close();
            } catch (IOException ex) {
                LOG.debug("Failed to close properties file '{}' properly. Error: {}", filename,
                        ex.getMessage());
            }
        }
    }

    return Boolean.TRUE;
}

From source file:com.cws.esolutions.security.dao.certmgmt.impl.CertificateManagerImpl.java

/**
 * @see com.cws.esolutions.security.dao.certmgmt.interfaces.ICertificateManager#applyCertificateRequest(String, File, File, String)
 *//*  w w w . j av  a2s . c  o  m*/
public synchronized boolean applyCertificateRequest(final String commonName, final File certificateFile,
        final File keystoreFile, final String storePassword) throws CertificateManagementException {
    final String methodName = ICertificateManager.CNAME
            + "#applyCertificateRequest(final String commonName, final File certificateFile, final File keystoreFile, final String storePassword) throws CertificateManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", commonName);
        DEBUGGER.debug("Value: {}", certificateFile);
        DEBUGGER.debug("Value: {}", keystoreFile);
    }

    final File rootDirectory = certConfig.getRootDirectory();
    final File certificateDirectory = FileUtils
            .getFile(certConfig.getCertificateDirectory() + "/" + commonName);
    final File storeDirectory = FileUtils.getFile(certConfig.getStoreDirectory() + "/" + commonName);

    if (DEBUG) {
        DEBUGGER.debug("rootDirectory: {}", rootDirectory);
        DEBUGGER.debug("certificateDirectory: {}", certificateDirectory);
        DEBUGGER.debug("storeDirectory: {}", storeDirectory);
        DEBUGGER.debug("certificateFile: {}", certificateFile);
        DEBUGGER.debug("keystoreFile: {}", keystoreFile);
    }

    boolean isComplete = false;
    FileInputStream certStream = null;
    FileOutputStream storeStream = null;
    FileInputStream keystoreInput = null;
    FileInputStream rootCertStream = null;
    FileInputStream intermediateCertStream = null;

    try {
        if (!(rootDirectory.exists())) {
            throw new CertificateManagementException(
                    "Root certificate directory either does not exist or cannot be written to. Cannot continue.");
        }

        if (!(rootDirectory.canWrite())) {
            throw new CertificateManagementException(
                    "Root certificate directory either does not exist or cannot be written to. Cannot continue.");
        }

        if (!(certConfig.getRootCertificateFile().exists())) {
            throw new CertificateManagementException("Root certificate file does not exist. Cannot continue.");
        }

        if (!(certConfig.getIntermediateCertificateFile().exists())) {
            throw new CertificateManagementException(
                    "Intermediate certificate file does not exist. Cannot continue.");
        }

        if (!(storeDirectory.canWrite())) {
            throw new CertificateManagementException(
                    "Keystore directory either does not exist or cannot be written to. Cannot continue.");
        }

        if (!(keystoreFile.canWrite())) {
            throw new CertificateManagementException(
                    "Unable to write to applicable keystore. Cannot continue.");
        }

        keystoreInput = FileUtils.openInputStream(keystoreFile);
        certStream = FileUtils.openInputStream(certificateFile);

        if (DEBUG) {
            DEBUGGER.debug("keystoreInput: {}", keystoreInput);
            DEBUGGER.debug("certStream: {}", certStream);
        }

        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(keystoreInput, storePassword.toCharArray());

        if (DEBUG) {
            DEBUGGER.debug("KeyStore: {}", keyStore);
        }

        Key privateKey = keyStore.getKey(commonName, storePassword.toCharArray());
        CertificateFactory certFactory = CertificateFactory.getInstance(certConfig.getCertificateType());

        if (DEBUG) {
            DEBUGGER.debug("CertificateFactory: {}", certFactory);
        }

        rootCertStream = FileUtils.openInputStream(FileUtils.getFile(certConfig.getRootCertificateFile()));
        intermediateCertStream = FileUtils
                .openInputStream(FileUtils.getFile(certConfig.getIntermediateCertificateFile()));

        if (DEBUG) {
            DEBUGGER.debug("rootCertStream: {}", rootCertStream);
            DEBUGGER.debug("intermediateCertStream: {}", intermediateCertStream);
        }

        X509Certificate[] responseCert = new X509Certificate[] {
                (X509Certificate) certFactory.generateCertificate(rootCertStream),
                (X509Certificate) certFactory.generateCertificate(intermediateCertStream),
                (X509Certificate) certFactory.generateCertificate(certStream) };

        if (DEBUG) {
            DEBUGGER.debug("X509Certificate[]", (Object) responseCert);
        }

        storeStream = FileUtils.openOutputStream(keystoreFile);
        keyStore.setKeyEntry(commonName, privateKey, storePassword.toCharArray(), responseCert);
        keyStore.store(storeStream, storePassword.toCharArray());

        isComplete = true;
    } catch (FileNotFoundException fnfx) {
        throw new CertificateManagementException(fnfx.getMessage(), fnfx);
    } catch (IOException iox) {
        throw new CertificateManagementException(iox.getMessage(), iox);
    } catch (NoSuchAlgorithmException nsax) {
        throw new CertificateManagementException(nsax.getMessage(), nsax);
    } catch (IllegalStateException isx) {
        throw new CertificateManagementException(isx.getMessage(), isx);
    } catch (KeyStoreException ksx) {
        throw new CertificateManagementException(ksx.getMessage(), ksx);
    } catch (CertificateException cx) {
        throw new CertificateManagementException(cx.getMessage(), cx);
    } catch (UnrecoverableKeyException ukx) {
        throw new CertificateManagementException(ukx.getMessage(), ukx);
    } finally {
        if (storeStream != null) {
            IOUtils.closeQuietly(storeStream);
        }

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

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

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

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

    return isComplete;
}

From source file:org.tacografo.file.FileBlockTGD.java

/**
 * Se encarga de leer los bytes del fichero he introducirlo en un
 * hasmap<FID,array bytes> los bloques bienen formado por TLV =
 * tag-longitud-value// w  ww  . j av a2s  .co  m
 * @throws ErrorFile 
 **/
@SuppressWarnings("unchecked")
private void factorizar_bloques(InputStream is, int sizeFile) throws ErrorFile {

    DataInputStream entrada = null;
    @SuppressWarnings({ "unused", "rawtypes" })
    HashMap<String, CardBlock> lista = new HashMap();

    try {
        entrada = new DataInputStream(is);
        this.lectura_bloque(entrada);

    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
    } catch (EOFException e) {

    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

}

From source file:com.facebook.FileLruCache.java

OutputStream openPutStream(final String key, String contentTag) throws IOException {
    final File buffer = BufferFile.newFile(this.directory);
    buffer.delete();/*ww  w .  ja  v  a  2  s.  c  o  m*/
    if (!buffer.createNewFile()) {
        throw new IOException("Could not create file at " + buffer.getAbsolutePath());
    }

    FileOutputStream file = null;
    try {
        file = new FileOutputStream(buffer);
    } catch (FileNotFoundException e) {
        Logger.log(LoggingBehaviors.CACHE, Log.WARN, TAG, "Error creating buffer output stream: " + e);
        throw new IOException(e.getMessage());
    }

    StreamCloseCallback renameToTargetCallback = new StreamCloseCallback() {
        @Override
        public void onClose() {
            final File target = new File(directory, Utility.md5hash(key));
            if (!buffer.renameTo(target)) {
                buffer.delete();
            }
            trim();
        }
    };

    CloseCallbackOutputStream cleanup = new CloseCallbackOutputStream(file, renameToTargetCallback);
    BufferedOutputStream buffered = new BufferedOutputStream(cleanup, Utility.DEFAULT_STREAM_BUFFER_SIZE);
    boolean success = false;

    try {
        // Prefix the stream with the actual key, since there could be collisions
        JSONObject header = new JSONObject();
        header.put(HEADER_CACHEKEY_KEY, key);
        if (!Utility.isNullOrEmpty(contentTag)) {
            header.put(HEADER_CACHE_CONTENT_TAG_KEY, contentTag);
        }

        StreamHeader.writeHeader(buffered, header);

        success = true;
        return buffered;
    } catch (JSONException e) {
        // JSON is an implementation detail of the cache, so don't let JSON exceptions out.
        Logger.log(LoggingBehaviors.CACHE, Log.WARN, TAG, "Error creating JSON header for cache file: " + e);
        throw new IOException(e.getMessage());
    } finally {
        if (!success) {
            buffered.close();
        }
    }
}

From source file:com.ephesoft.dcma.gwt.uploadbatch.server.UploadBatchServiceImpl.java

/**
 * This method is used to serialize the BatchClassField that is to be used in Web scanner module
 * //from w ww .  jav a2  s .c o  m
 * @param folderName
 * @param values
 */

@Override
public void serializeBatchClassField(String folderName, List<BatchClassFieldDTO> values) throws GWTException {
    FileOutputStream fileOutputStream = null;
    File serializedExportFile = null;
    ArrayList<BatchClassField> batchClassFieldList = new ArrayList<BatchClassField>();
    for (BatchClassFieldDTO batchClassFieldDTO : values) {
        BatchClassField batchClassField = new BatchClassField();
        batchClassField.setBatchClass(null);
        batchClassField.setDataType(batchClassFieldDTO.getDataType());
        batchClassField.setIdentifier(batchClassFieldDTO.getIdentifier());
        batchClassField.setName(batchClassFieldDTO.getName());
        batchClassField.setFieldOrderNumber(Integer.parseInt(batchClassFieldDTO.getFieldOrderNumber()));
        batchClassField.setDescription(batchClassFieldDTO.getDescription());
        batchClassField.setValidationPattern(batchClassFieldDTO.getValidationPattern());
        batchClassField.setSampleValue(batchClassFieldDTO.getSampleValue());
        batchClassField.setFieldOptionValueList(batchClassFieldDTO.getFieldOptionValueList());
        batchClassField.setValue(batchClassFieldDTO.getValue());
        batchClassFieldList.add(batchClassField);
    }
    try {
        BatchSchemaService batchSchemaService = this.getSingleBeanOfType(BatchSchemaService.class);
        String folderPath = batchSchemaService.getUploadBatchFolder() + File.separator + folderName;
        File currentBatchUploadFolder = new File(folderPath);
        if (!currentBatchUploadFolder.exists()) {
            currentBatchUploadFolder.mkdirs();
        }
        serializedExportFile = new File(folderPath + File.separator + BCF_SER_FILE_NAME + SERIALIZATION_EXT);
        fileOutputStream = new FileOutputStream(serializedExportFile);
        SerializationUtils.serialize(batchClassFieldList, fileOutputStream);
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.info("Error occurred while creating the serializable file." + e, e);
        throw new GWTException(e.getMessage());
    } finally {
        try {
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }

        } catch (Exception e) {
            if (serializedExportFile != null) {
                LOG.error("Problem closing stream for file :" + serializedExportFile.getName());
            }
        }
    }

}

From source file:no.met.jtimeseries.service.TimeSeriesService.java

@GET
@Path("thredds/diagram")
@Produces("image/png")
@ServiceDescription("Visualize data from a thredds server.")
public Response createThreddsDiagram(@QueryParam("url") String url,
        @QueryParam("parameters") String parameterList, @QueryParam("variables") String variableList,
        @QueryParam("with_header") @DefaultValue("false") boolean withHeader,
        @QueryParam("header") String header, @QueryParam("width") @DefaultValue("750") int width,
        @QueryParam("height") @DefaultValue("300") int height) {

    System.out.println(url);//from ww  w  .  ja v  a  2s  . c om

    Location location = null;

    if (parameterList != null && variableList != null) {
        logger.severe("Uanble to handle both <parameters> and <variables> in request.");
        return Response.status(Response.Status.BAD_REQUEST).build();
    }

    ParameterReference parameterReference = ParameterReference.STANDARD_NAME;
    if (parameterList == null) {
        parameterList = variableList;
        parameterReference = ParameterReference.VARIABLE_NAME;
    }

    List<String> parameters = null;
    if (parameterList != null) {
        parameters = new Vector<String>();
        String[] param = parameterList.split(",");
        for (int i = 0; i < param.length; i++) {
            System.out.println(param[i]);
            parameters.add(param[i]);
        }
    }

    if (withHeader)
        if (header == null)
            header = "AUTO";

    try {
        JFreeChart chart = NetcdfMeteogramWrapper.getChart(url, location, parameters, parameterReference,
                header);
        File ret = new PngChartSaver().save(chart, width, height);
        return serveFile(ret);
    } catch (FileNotFoundException e) {
        LogUtils.logException(logger, "Unable to make sense of data: " + e.getMessage(), e);
        return Response.status(502).build();
    } catch (ParseException e) {
        LogUtils.logException(logger, "Unable to make sense of request or data: " + e.getMessage(), e);
        return Response.status(Response.Status.BAD_REQUEST).build();
    } catch (Exception e) {
        LogUtils.logException(logger,
                "Failed to create timeseries diagram from thredds data: " + e.getMessage(), e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

From source file:org.tacografo.file.FileBlockTGD.java

/**
 * Se encarga de leer los bytes del fichero he introducirlo en un
 * hasmap<FID,array bytes> los bloques bienen formado por TLV =
 * tag(FID)-longitud-value//from  w w w .  j av a2 s  .co  m
 * @throws ErrorFile ocurrido cuando no es un fichero tgd o falla en la lectura de algun bloque
 * porque no encuentre el tag(fid)
 */
private void factorizar_bloques(String nombre_fichero) throws ErrorFile {
    FileInputStream fis = null;
    DataInputStream entrada = null;
    try {
        fis = new FileInputStream(nombre_fichero);
        entrada = new DataInputStream(fis);
        //lectura de bloques siempre y cuando la lectura del fid exista
        this.lectura_bloque(entrada);

    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
    } catch (EOFException e) {
        // se produce cuando se llega al final del fichero
        //System.out.println(e.getMessage());
    } catch (IOException e) {
        System.out.println(e.getMessage());
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (entrada != null) {
                entrada.close();
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

}

From source file:marytts.tools.voiceimport.HMMVoicePackager.java

/**
 * Load mapping of features from file//from   w  ww  .  j a  v  a 2 s .  c  o  m
 * @param fileName 
 * @throws FileNotFoundException
 */
private Map<String, String> loadFeaturesMap(String fileName) throws FileNotFoundException {

    Scanner aliasList = null;
    try {
        aliasList = new Scanner(new BufferedReader(new FileReader(fileName)));
        String line;
        logger.info("loading features map from file: " + fileName);
        while (aliasList.hasNext()) {
            line = aliasList.nextLine();
            String[] fea = line.split(" ");

            actualFeatureNames.put(fea[1], fea[0]);
            logger.info("  " + fea[0] + " -->  " + fea[1]);
        }
        if (aliasList != null) {
            aliasList.close();
        }
    } catch (FileNotFoundException e) {
        logger.debug("loadTrickyPhones:  " + e.getMessage());
        throw new FileNotFoundException();
    }
    return actualFeatureNames;
}

From source file:com.grupohqh.carservices.operator.ManipulateCarActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case CAPTURE_IMAGE:
            final File file = getTempFile(this);
            try {
                bm = MediaStore.Images.Media.getBitmap(getContentResolver(), Uri.fromFile(file));
                imgCar.setImageBitmap(bm);
                // do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc)
            } catch (FileNotFoundException e) {
                Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }//from w  ww.  j a  v  a 2  s  . c om
            break;
        }
    }
}