Example usage for java.io FileNotFoundException getLocalizedMessage

List of usage examples for java.io FileNotFoundException getLocalizedMessage

Introduction

In this page you can find the example usage for java.io FileNotFoundException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:net.straylightlabs.tivolibre.DecoderApp.java

public void run() {
    if (options == null || cli == null) {
        throw new IllegalStateException("Must call parseCommandLineArgs() before calling run()");
    }/*  ww w.j  a v a2 s .c  om*/

    if (cli.hasOption('v')) {
        System.out.format("TivoLibre %s%n", TivoDecoder.VERSION);
        System.exit(0);
    } else if (cli.hasOption('h')) {
        showUsage();
        System.exit(0);
    }

    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    if (cli.hasOption('d')) {
        root.setLevel(Level.DEBUG);
    } else {
        root.setLevel(Level.ERROR);
    }

    DecoderOptions decoderOptions = new DecoderOptions();

    decoderOptions.mak = loadMak();
    if (!cli.hasOption('m')) {
        if (decoderOptions.mak == null) {
            System.err.format("Error: You must provide your media access key%n");
            showUsage();
            System.exit(1);
        }
    } else {
        decoderOptions.mak = cli.getOptionValue('m');
        saveMak(decoderOptions.mak);
    }

    if (cli.hasOption("compat-mode")) {
        logger.debug("Running in compatibility mode");
        decoderOptions.compatibilityMode = true;
    }

    if (cli.hasOption('D')) {
        decoderOptions.dumpMetadata = true;
    }

    if (cli.hasOption('p')) {
        decoderOptions.pytivoMetadata = true;
    }

    if (cli.hasOption('x')) {
        decoderOptions.noVideo = true;
    }

    try {
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            if (cli.hasOption('i')) {
                inputStream = new FileInputStream(cli.getOptionValue('i'));
            } else {
                inputStream = System.in;
            }
            if (cli.hasOption('o')) {
                String outputLocation = cli.getOptionValue('o');
                outputStream = new FileOutputStream(outputLocation);
                decoderOptions.pytivoMetadataPath = appendToPath(Paths.get(outputLocation), ".txt");
            } else {
                outputStream = System.out;
                decoderOptions.pytivoMetadataPath = Paths.get("pytivo.txt");
            }
            decode(inputStream, outputStream, decoderOptions);
        } catch (FileNotFoundException e) {
            logger.error("Input file {} not found: {}", cli.getOptionValue('i'), e.getLocalizedMessage());
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outputStream != null) {
                outputStream.close();
            }
        }
    } catch (IOException e) {
        logger.error("IOException: {}", e.getLocalizedMessage(), e);
    }
}

From source file:org.geotools.gce.imagemosaic.Utils.java

/**
 * Load a sample image from which we can take the sample model and color
 * model to be used to fill holes in responses.
 * /*from w  w w.j ava2s.  c om*/
 * @param sampleImageFile
 *            the path to sample image.
 * @return a sample image from which we can take the sample model and color
 *         model to be used to fill holes in responses.
 */
public static RenderedImage loadSampleImage(final File sampleImageFile) {
    // serialize it
    InputStream inStream = null;
    ObjectInputStream oiStream = null;
    try {

        // do we have the sample image??
        if (Utils.checkFileReadable(sampleImageFile)) {
            inStream = new BufferedInputStream(new FileInputStream(sampleImageFile));
            oiStream = new ObjectInputStream(inStream);

            // load the image
            return (RenderedImage) oiStream.readObject();

        } else {
            if (LOGGER.isLoggable(Level.WARNING))
                LOGGER.warning("Unable to find sample image for path " + sampleImageFile);
            return null;
        }
    } catch (FileNotFoundException e) {
        if (LOGGER.isLoggable(Level.WARNING))
            LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
        return null;
    } catch (IOException e) {
        if (LOGGER.isLoggable(Level.WARNING))
            LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
        return null;
    } catch (ClassNotFoundException e) {
        if (LOGGER.isLoggable(Level.WARNING))
            LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
        return null;
    } finally {
        try {
            if (inStream != null)
                inStream.close();
        } catch (Throwable e) {

            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
        }
        try {
            if (oiStream != null)
                oiStream.close();
        } catch (Throwable e) {

            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
        }
    }
}

From source file:resources.utils.FileIoUtils.java

/**
 * 20130927 Fixed Memory Leak. Dont use line by line, just use apache
 * commons io!! so simple and easy!//from   www.  j  av a2 s.  co  m
 * 
 * @param filePath
 * @return
 */
public String readFileToString(String filePath) {

    String fileContentString = null;

    try {

        VirtualFile vf = VirtualFile.fromRelativePath(filePath);
        File realFile = vf.getRealFile();
        fileContentString = FileUtils.readFileToString(realFile);

    } catch (java.io.FileNotFoundException e) {
        play.Logger.error("File Not Found exception.", e);
        fileContentString = "File Not Found exception. This file may have been removed. " + filePath;
    } catch (Throwable e) {
        play.Logger.error("Error in readConfigFile.", e.getLocalizedMessage());
        e.printStackTrace();
        fileContentString = "File Not Found exception. This file may have been removed. " + filePath;
    }
    return fileContentString.toString();

}

From source file:com.wooki.services.parsers.XHTMLToFormattingObjects.java

public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
    InputSource toReturn = null;/*from   w w  w.j a va 2  s . co m*/
    Element cachedValue = cache.get(systemId);
    if (cachedValue == null) {
        if (systemId.contains("http://")) {
            HttpMethod get = new GetMethod(systemId);
            httpClient.executeMethod(get);
            byte[] body = get.getResponseBody();
            Element element = new Element(systemId, body);
            cache.put(element);
            toReturn = new InputSource(new BufferedInputStream(new ByteArrayInputStream(body)));
            toReturn.setSystemId(systemId);
        } else if (systemId.contains("file://")) {
            String newPath = systemId.substring("file:///".length()).replace('/', File.separatorChar);
            File baseFile = new File(newPath);
            try {
                toReturn = new InputSource(new FileInputStream(baseFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                logger.error(e.getLocalizedMessage());
                return null;
            }
        }
    } else {
        toReturn = new InputSource(
                new BufferedInputStream(new ByteArrayInputStream((byte[]) cachedValue.getObjectValue())));
        toReturn.setSystemId(systemId);
    }
    return toReturn;
}

From source file:com.adr.mimame.PlatformList.java

private List<GamesItem> loadList(File f) {
    try {//w  ww .j ava2 s. c  om
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(new File(f, "games.xml"));

        ArrayList<GamesItem> games = new ArrayList<GamesItem>();

        NodeList nodegames = doc.getElementsByTagName("game");
        for (int i = 0; i < nodegames.getLength(); i++) {
            GamesItem item = new GamesItem((Element) nodegames.item(i));
            games.add(item);
        }

        return games;
    } catch (FileNotFoundException ex) {
        logger.log(Level.INFO, ex.getLocalizedMessage());
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.wooki.services.parsers.XHTMLToFormattingObjects.java

public Source resolve(String href, String base) throws TransformerException {
    Source toReturn = null;//from  ww  w. j  ava  2  s .co m
    if (base != null && base.contains("file://")) {
        String newPath = base.substring("file:///".length()).replace('/', File.separatorChar);
        newPath = newPath.substring(0, newPath.lastIndexOf(File.separatorChar));
        File baseFile = new File(newPath);
        baseFile = new File(
                baseFile.getAbsolutePath() + File.separatorChar + href.replace('/', File.separatorChar));
        try {
            toReturn = new StreamSource(new FileInputStream(baseFile));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return null;
        }
    } else {
        if (base.contains("http://")) {
            String newUrl = base.substring(0, base.lastIndexOf('/') + 1);
            newUrl += href;
            HttpMethod get = new GetMethod(newUrl);
            try {
                httpClient.executeMethod(get);
                byte[] body = get.getResponseBody();
                Element element = new Element(newUrl, body);
                cache.put(element);
                toReturn = new StreamSource(new BufferedInputStream(new ByteArrayInputStream(body)));
            } catch (HttpException e) {
                e.printStackTrace();
                logger.error(e.getLocalizedMessage());
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                logger.error(e.getLocalizedMessage());
                return null;
            }
            toReturn.setSystemId(newUrl);
        } else {
            toReturn = new StreamSource(XHTMLToFormattingObjects.class.getResourceAsStream(href));
        }
    }
    return toReturn;
}

From source file:com.newrelic.agent.Obfuscation.Proguard.java

private boolean fetchConfiguration() {
    /*     */ try {
        /* 105 */ Reader propsReader = new BufferedReader(
                new FileReader(getProjectRoot() + File.separator + "newrelic.properties"));
        /* 106 */ Properties newRelicProps = new Properties();
        /* 107 */ newRelicProps.load(propsReader);
        /*     */
        /* 109 */ this.licenseKey = newRelicProps.getProperty("com.newrelic.application_token");
        /* 110 */ this.uploadingEnabled = newRelicProps
                .getProperty("com.newrelic.enable_proguard_upload", "true").equals("true");
        /* 111 */ this.mappingApiHost = newRelicProps.getProperty("com.newrelic.mapping_upload_host");
        /*     */
        /* 113 */ if (this.licenseKey == null) {
            /* 114 */ this.log.error(
                    "Unable to find a value for com.newrelic.application_token in your newrelic.properties");
            /* 115 */ this.log
                    .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
            /*     */
            /* 117 */ return false;
            /*     */ }
        /*     */
        /* 120 */ propsReader.close();
        /*     */ } catch (FileNotFoundException e) {
        /* 122 */ this.log.error("Unable to find your newrelic.properties in the project root ("
                + getProjectRoot() + "): " + e.getLocalizedMessage());
        /* 123 */ this.log
                .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
        /*     */
        /* 125 */ return false;
        /*     */ } catch (IOException e) {
        /* 127 */ this.log.error("Unable to read your newrelic.properties in the project root ("
                + getProjectRoot() + "): " + e.getLocalizedMessage());
        /* 128 */ this.log
                .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
        /*     */
        /* 130 */ return false;
        /*     */ }
    /*     *///w  ww . ja  va 2 s. c om
    /* 133 */ return true;
    /*     */ }

From source file:com.microsoft.rightsmanagement.sampleapp.MainActivity.java

@Override
protected void onResumeFragments() {
    super.onResumeFragments();
    // handle unposted tasks from mMsipcTaskFragment
    if (mMsipcTaskFragment != null) {
        TaskStatus latestUnpostedTaskStatus = mMsipcTaskFragment.getLatestUnpostedTaskStatus();
        if (latestUnpostedTaskStatus != null) {
            onMsipcTaskUpdate(latestUnpostedTaskStatus);
        }/*from   ww w  . j a v a 2 s. c  o  m*/
    }
    // handle pending uri
    if (mUriOfFilePendingConsumption != null) {
        // Show Log dialog only on first launch
        showCustomerExperienceDataConsentDialogFragmentIfNeeded(new CompletionCallback<Void>() {

            @Override
            public void onSuccess(Void item) {
                setToShowCustomerExperienceDataConsentDialogFragmentAgainOnStart(false);
                try {
                    handleUriInput(mUriOfFilePendingConsumption);
                } catch (FileNotFoundException e) {
                    App.displayMessageDialog(getSupportFragmentManager(), e.getLocalizedMessage());
                } finally {
                    // uri was handled. There is no pending uri now
                    mUriOfFilePendingConsumption = null;
                }
            }

            @Override
            public void onCancel() {
                setToShowCustomerExperienceDataConsentDialogFragmentAgainOnStart(true);
                finish();
            }
        });
    }
}

From source file:org.geotools.gce.imagemosaic.Utils.java

/**
 * Setup a {@link Histogram} object by deserializing  
 * a file representing a serialized Histogram.
 * /*from  w w w .  jav  a  2s  .  c  o  m*/
 * @param file
 * @return the deserialized histogram.
 */
static Histogram getHistogram(final String file) {
    Utilities.ensureNonNull("file", file);
    Histogram histogram = null;

    // Firstly: check if the histogram have been already
    // deserialized and it is available in cache
    if (ehcache != null && ehcache.isKeyInCache(file)) {
        if (ehcache.isElementInMemory(file)) {
            final Element element = ehcache.get(file);
            if (element != null) {
                final Serializable value = element.getValue();
                if (value != null && value instanceof Histogram) {
                    histogram = (Histogram) value;
                    return histogram;
                }
            }
        }
    }

    // No histogram in cache. Deserializing...
    if (histogram == null) {
        FileInputStream fileStream = null;
        ObjectInputStream objectStream = null;
        try {

            fileStream = new FileInputStream(file);
            objectStream = new ObjectInputStream(fileStream);
            histogram = (Histogram) objectStream.readObject();
            if (ehcache != null) {
                ehcache.put(new Element(file, histogram));
            }
        } catch (FileNotFoundException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Unable to parse Histogram:" + e.getLocalizedMessage());
            }
        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Unable to parse Histogram:" + e.getLocalizedMessage());
            }
        } catch (ClassNotFoundException e) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Unable to parse Histogram:" + e.getLocalizedMessage());
            }
        } finally {
            if (objectStream != null) {
                IOUtils.closeQuietly(objectStream);
            }
            if (fileStream != null) {
                IOUtils.closeQuietly(fileStream);
            }
        }
    }
    return histogram;
}

From source file:com.grayraven.barcoder.CameraActivityFragement.java

private void SetupCallbacks() {
    rawCallback = new Camera.PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            Log.d("Log", "onPictureTaken - raw");
        }//  w w w.j  av  a  2 s  . c om
    };

    /** Handles data for jpeg picture */
    shutterCallback = new Camera.ShutterCallback() {
        public void onShutter() {
            Log.i("Log", "onShutter'd");
        }
    };

    jpegCallback = new Camera.PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            boolean result = false;
            File pictureFile = getOutputMediaFile();
            if (pictureFile == null) {
                Toast.makeText(getActivity(), "Image retrieval failed.", Toast.LENGTH_LONG).show();
                return;
            }

            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
                Log.i(TAG, "Imaged saved to:" + pictureFile.getAbsolutePath());
                result = true;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                Log.e(TAG, "File exception saving captured image: " + e.getLocalizedMessage());
                result = false;
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "File exception saving captured image: " + e.getLocalizedMessage());
                result = false;
            }

            if (result) {
                ((CameraActivity) getActivity()).setScanResult(true);
                Intent i = new Intent(getActivity(), MainActivity.class);
                startActivity(i);
            } else {
                ((CameraActivity) getActivity()).setScanResult(false);
            }
        }
    };
}