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.example.cuisoap.agrimac.machineRegister.driverInfoFragment.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        Uri license_uri = data.getData();
        Log.e("uri", license_uri.toString());
        ContentResolver cr = context.getContentResolver();
        try {/*from   w ww  .  ja v  a  2 s  .  co  m*/
            Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(license_uri));
            if (requestCode == 1) {
                //String path=getRealPathFromURI(uri);
                //System.out.println(path);
                bitmap = ImageUtils.comp(bitmap);
                license_path = ImageUtils.saveMyBitmap(bitmap, "driver");
                license_pic.setImageBitmap(bitmap);
                license_pic.setVisibility(View.VISIBLE);
                license.setVisibility(View.GONE);
                license_pic.setOnClickListener(myOnClickListener);
            }

        } catch (FileNotFoundException e) {
            Log.e("Exception", e.getMessage(), e);
        }
    } else {
        Toast.makeText(context, "?", Toast.LENGTH_SHORT).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.impetus.ankush.agent.action.impl.YAMLManipulator.java

/**
 * Read conf value.//from w  w w.  jav a 2  s.  com
 * 
 * @param file
 *            the file
 * @param propertyName
 *            the property name
 * @return the string
 */
public String readConfValue(String file, String objPropertyName) {

    String propertyName = (String) objPropertyName;

    Yaml yaml = new Yaml();
    try {
        InputStream fis = new FileInputStream(file);
        Object javaObject = yaml.load(fis);
        Map<String, Object> map = (Map<String, Object>) javaObject;

        for (Map.Entry<String, Object> entry : map.entrySet()) {
            if (entry.getKey().equals(propertyName)) {
                return (String) entry.getValue();
            }
        }
        fis.close();

    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return null;
}

From source file:me.taylorkelly.mywarp.bukkit.util.parametric.ExceptionConverter.java

/**
 * Converts a {@link FileNotFoundException} to a human readable {@link CommandException}.
 *
 * @param ex the FileNotFoundException//from  w w  w  .j a  va  2 s.com
 * @throws CommandException the wrapped exception
 */
@ExceptionMatch
public void convert(FileNotFoundException ex) throws CommandException {
    throw new CommandException(MESSAGES.getString("exception.file-not-found", ex.getMessage()), ex);
}

From source file:org.dataone.proto.trove.mn.service.v1.impl.MNStorageImpl.java

@Override
public Identifier create(Identifier pid, InputStream object, SystemMetadata sysmeta)
        throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType,
        InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest {
    try {//  w ww . j  a va2s .  c om
        File systemMetadata = new File(dataoneCacheDirectory + File.separator + "meta" + File.separator
                + EncodingUtilities.encodeUrlPathSegment(pid.getValue()));
        TypeMarshaller.marshalTypeToFile(sysmeta, systemMetadata.getAbsolutePath());

        if (systemMetadata.exists()) {
            systemMetadata.setLastModified(sysmeta.getDateSysMetadataModified().getTime());
        } else {
            throw new ServiceFailure("1190", "SystemMetadata not found on FileSystem after create");
        }
        File objectFile = new File(dataoneCacheDirectory + File.separator + "object" + File.separator
                + EncodingUtilities.encodeUrlPathSegment(pid.getValue()));
        if (!objectFile.exists() && objectFile.createNewFile()) {
            objectFile.setReadable(true);
            objectFile.setWritable(true);
            objectFile.setExecutable(false);
        }

        if (object != null) {
            FileOutputStream objectFileOutputStream = new FileOutputStream(objectFile);
            BufferedInputStream inputStream = new BufferedInputStream(object);
            byte[] barray = new byte[SIZE];
            int nRead = 0;

            while ((nRead = inputStream.read(barray, 0, SIZE)) != -1) {
                objectFileOutputStream.write(barray, 0, nRead);
            }
            objectFileOutputStream.flush();
            objectFileOutputStream.close();
            inputStream.close();
        }
    } catch (FileNotFoundException ex) {
        throw new ServiceFailure("1190", ex.getCause().toString() + ":" + ex.getMessage());
    } catch (IOException ex) {
        throw new ServiceFailure("1190", ex.getMessage());
    } catch (JiBXException ex) {
        throw new InvalidSystemMetadata("1180", ex.getMessage());
    }
    return pid;
}

From source file:eu.wisebed.wiseui.persistence.PersistenceServiceTest.java

private byte[] loadBinaryImageFromDisk(final String path) {
    byte[] bytes = null;
    FileInputStream in = null;//from   ww  w  .  j a  va  2  s .  c o m
    try {
        in = new FileInputStream(path);
    } catch (final FileNotFoundException e) {
        LOGGER.error(e.getMessage(), e);
    }

    try {
        bytes = IOUtils.toByteArray(in);
    } catch (final IOException e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (final IOException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }
    return bytes;
}

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

/**
 * Test synthesize.//from  w w  w  .j a v a 2  s .  c  o m
 */
@Test
public void testSynthesize() {
    File audio = new File("src/test/resources/sample1.wav");
    if (audio == null || !audio.exists() || !audio.isFile())
        throw new IllegalArgumentException("audio is not a valid audio file");

    InputStreamEntity reqEntity = null;
    try {
        reqEntity = new InputStreamEntity(new FileInputStream(audio), -1);
        List<Parameter> parameters = new ArrayList<Parameter>();
        parameters.add(new Parameter("text", text));
        parameters.add(new Parameter("voice", Voice.EN_MICHAEL.getName()));
        parameters.add(new Parameter("accept", MediaType.AUDIO_WAV));

        mockServer.when(request().withQueryStringParameters(parameters).withPath(SYNTHESIZE_PATH))
                .respond(response().withHeaders(new Header(HttpHeaders.Names.CONTENT_TYPE, MediaType.AUDIO_WAV))
                        .withBody(IOUtils.toString(reqEntity.getContent())));

        InputStream in = service.synthesize(text, Voice.EN_MICHAEL, MediaType.AUDIO_WAV);
        Assert.assertNotNull(in);

        writeInputStreamToOutputStream(in, new FileOutputStream("target/output.wav"));

    } catch (FileNotFoundException e) {
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:com.cognifide.maven.plugins.crx.CrxPackageUploadMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
        getLog().info("Skipping upload in this project because it's not the Execution Root");
        return;//from   ww  w.j  a  v a 2 s. c om
    }

    if (this.skip) {
        getLog().info("Skipping package uploading as instructed");
        return;
    }

    File packageFile = getPackageFile();

    String targetURL = getUploadURL();
    getLog().info("Uploading package " + packageFileName + " to " + targetURL);
    try {
        String response = post(targetURL, createUploadParameters(packageFile));
        CrxResponse parsedJson = CrxResponse.parseCrxJsonResponse(response);

        if (parsedJson.isSuccess()) {
            getLog().info(parsedJson.getMsg());
            mavenSession.getUserProperties().put(UPLOADED_PACKAGE_PATH_PROPERTY, parsedJson.getPath());
        } else {
            getLog().error(parsedJson.getMsg());
            throw new MojoExecutionException(parsedJson.getMsg());
        }
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("File '" + packageFile.getName() + "' not found!", e);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.github.promeg.configchecker.Main.java

/**
 * Tries to open an input file as a Zip archive (jar/apk) with a
 * "classes.dex" inside./*from   w  ww.  j a v a  2  s  .  com*/
 */
void openInputFileAsZip(String fileName, List<String> dexFiles) throws IOException {
    ZipFile zipFile;

    // Try it as a zip file.
    try {
        zipFile = new ZipFile(fileName);
    } catch (FileNotFoundException fnfe) {
        // not found, no point in retrying as non-zip.
        System.err.println("Unable to open '" + fileName + "': " + fnfe.getMessage());
        throw fnfe;
    } catch (ZipException ze) {
        // not a zip
        return;
    }

    // Open and add all files matching "classes.*\.dex" in the zip file.
    for (ZipEntry entry : Collections.list(zipFile.entries())) {
        if (entry.getName().matches("classes.*\\.dex")) {
            dexFiles.add(openDexFile(zipFile, entry).getAbsolutePath());
        }
    }

    zipFile.close();
}

From source file:com.impetus.ankush.agent.action.impl.YAMLManipulator.java

/**
 * Delete conf value.//from   w w w  .  ja  va2 s  .  c  om
 * 
 * @param file
 *            the file
 * @param propertyName
 *            the property name
 * @return true, if successful
 */
public boolean deleteConfValue(String file, String objPropertyName) {

    String propertyName = (String) objPropertyName;
    Yaml yaml = new Yaml();
    try {
        InputStream fis = new FileInputStream(file);
        Object javaObject = yaml.load(fis);
        Map<String, Object> map = (Map<String, Object>) javaObject;
        if (map.containsKey(propertyName)) {
            map.remove(propertyName);
        }
        fis.close();
        // save to file
        File confFile = new File(file);
        if (!confFile.exists()) {
            System.err.println("File " + file + " does not exists.");
        }
        String dumped = yaml.dumpAsMap(map);
        FileUtils.writeStringToFile(confFile, dumped, false);

        return true;

    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return false;
}

From source file:org.usd.edu.btl.cli.ConvertBets.java

public void toGalaxy(String input, String output) {
    InputStream infile = null;//from  w w w .  j a v  a2 s . c om
    Tool myTool = null;
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); //Unmarshalling  Convert XML content into a Java Object.
        infile = new FileInputStream("./test_inputs/test_galaxy.xml");
        Tool test_tool = (Tool) unmarshaller.unmarshal(infile);
        myTool = test_tool;
        //System.out.println(test_tool.toString()); //print the test_tool 

    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
    } catch (JAXBException e) {
        System.err.println(e.getMessage());
    } finally {
        try {
            if (infile != null) {
                infile.close();
            }
        } catch (IOException e) {
            System.err.println("You're rubbish, you can't even close a file");
            System.err.println(e.getMessage());
        }
    }

    //JAXB-Marshall Java back to XML
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Tool.class);
        Marshaller marshaller = jaxbContext.createMarshaller(); //Marshalling  Convert a Java object into a XML file.
        marshaller.marshal(myTool, System.out); //print XML out
    } catch (JAXBException e) {
        System.err.println("JAXB dun goofed");
        System.err.println(e.getMessage());
    }
    // RUN GALAXY TO BETS CONVERSION
    BETSV1 betsOutput = GalaxyConverter.toBETS(myTool);
    try {
        System.err.println("************************************************\n"
                + "*********PRINTING OUT CONVERSION************\n" + "----------Galaxy --> Bets--------------\n"
                + "************************************************\n");
        //print objects as Json using jackson
        System.err.println("=== BLD TO BETS JSON === \n");
        System.out.println(betsOutput);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}