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:com.microsoft.tfs.client.common.ui.compare.TFSShelvedChangeNode.java

@Override
public InputStream getContents() throws CoreException {
    if (pendingChange.getItemType() == ItemType.FOLDER) {
        return null;
    }//www.j  a  v a  2  s .c o  m

    synchronized (downloadedFilePathLock) {
        if (downloadedFilePath == null) {
            final String localFileName = ServerPath.getFileName(pendingChange.getServerItem());

            downloadedFilePath = pendingChange
                    .downloadShelvedFileToTempLocation(repository.getVersionControlClient(), localFileName)
                    .getAbsolutePath();
        }

        try {
            return new BufferedInputStream(new FileInputStream(downloadedFilePath));
        } catch (final FileNotFoundException e) {
            throw new CoreException(new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0,
                    e.getLocalizedMessage(), e));
        }
    }
}

From source file:im.ene.lab.toro.sample.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
            requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, 1000);
        } else {/*from  ww w. j  a v  a2  s .c o m*/
            try {
                Log.e(TAG, "onResume: " + Arrays.toString(Util.loadMovieFolder()));
            } catch (FileNotFoundException e) {
                Log.e(TAG, "onResume: " + e.getLocalizedMessage());
                e.printStackTrace();
            }
        }
    }
}

From source file:org.linphone.tools.OpenH264DownloadHelper.java

/**
  * Try to download and load codec/*ww w .ja  va  2s.co m*/
  * Requirements :
  *  fileDirection
  *  nameFileDownload
  *  urlDownload
  *  nameLib
  *  codecDownListener
  */
public void downloadCodec() {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                String path = fileDirection + "/" + nameLib;
                URL url = new URL(urlDownload);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                urlConnection.connect();
                Log.i("OpenH264Downloader", " ");
                InputStream inputStream = urlConnection.getInputStream();
                FileOutputStream fileOutputStream = new FileOutputStream(
                        fileDirection + "/" + nameFileDownload);
                int totalSize = urlConnection.getContentLength();
                openH264DownloadHelperListener.OnProgress(0, totalSize);

                Log.i("OpenH264Downloader", " Download file:" + nameFileDownload);

                byte[] buffer = new byte[4096];
                int bufferLength;
                int total = 0;
                while ((bufferLength = inputStream.read(buffer)) > 0) {
                    total += bufferLength;
                    fileOutputStream.write(buffer, 0, bufferLength);
                    openH264DownloadHelperListener.OnProgress(total, totalSize);
                }

                fileOutputStream.close();
                inputStream.close();

                Log.i("OpenH264Downloader", " Uncompress file:" + nameFileDownload);

                FileInputStream in = new FileInputStream(fileDirection + "/" + nameFileDownload);
                FileOutputStream out = new FileOutputStream(path);
                BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);

                while ((bufferLength = bzIn.read(buffer)) > 0) {
                    out.write(buffer, 0, bufferLength);
                }
                in.close();
                out.close();
                bzIn.close();

                Log.i("OpenH264Downloader", " Remove file:" + nameFileDownload);
                new File(fileDirection + "/" + nameFileDownload).delete();

                Log.i("OpenH264Downloader", " Loading plugin:" + path);
                System.load(path);
                openH264DownloadHelperListener.OnProgress(2, 1);
            } catch (FileNotFoundException e) {
                openH264DownloadHelperListener.OnError(e.getLocalizedMessage());
            } catch (IOException e) {
                openH264DownloadHelperListener.OnError(e.getLocalizedMessage());
            }
        }
    });
    thread.start();
}

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

public void findAndSendMapFile() {
    /*  45 */ String mappingString = "";
    /*     *///from w  ww  .j a va 2  s  .c  o  m
    /*  47 */ if (getProjectRoot() != null) {
        /*  48 */ if (!fetchConfiguration()) {
            /*  49 */ return;
            /*     */ }
        /*     */
        /*  52 */ File projectRoot = new File(getProjectRoot());
        /*  53 */ IOFileFilter fileFilter = FileFilterUtils.nameFileFilter("mapping.txt");
        /*  54 */ Collection files = FileUtils.listFiles(projectRoot, fileFilter, TrueFileFilter.INSTANCE);
        /*     */
        /*  56 */ if (files.isEmpty()) {
            /*  57 */ this.log.error(
                    "While evidence of ProGuard was detected, New Relic failed to find your mapping.txt file.");
            /*  58 */ this.log
                    .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
            /*     */ }
        /*     */
        /*  61 */ for (File file : files) {
            /*  62 */ this.log.info("Found mapping.txt: " + file.getPath());
            /*     */ try
            /*     */ {
                /*  66 */ FileWriter fileWriter = new FileWriter(file, true);
                /*  67 */ fileWriter.write("# NR_BUILD_ID: " + NewRelicClassVisitor.getBuildId());
                /*  68 */ fileWriter.close();
                /*     */
                /*  70 */ mappingString = mappingString + FileUtils.readFileToString(file);
                /*     */ } catch (FileNotFoundException e) {
                /*  72 */ this.log.error("Unable to open your mapping.txt file: " + e.getLocalizedMessage());
                /*  73 */ this.log
                        .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
                /*     */ } catch (IOException e) {
                /*  75 */ this.log.error("Unable to open your mapping.txt file: " + e.getLocalizedMessage());
                /*  76 */ this.log
                        .error("To de-obfuscate your builds, you'll need to upload your mapping.txt manually.");
                /*     */ }
            /*     */ }
        /*     */
        /*  80 */ if (this.uploadingEnabled)
            /*  81 */ sendMapping(mappingString);
        /*     */ }
    /*     */ }

From source file:org.apache.bookkeeper.bookie.EntryLogTest.java

@Test(timeout = 60000)
/** Test that EntryLogger Should fail with FNFE, if entry logger directories does not exist*/
public void testEntryLoggerShouldThrowFNFEIfDirectoriesDoesNotExist() throws Exception {
    File tmpDir = createTempDir("bkTest", ".dir");
    ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
    conf.setLedgerDirNames(new String[] { tmpDir.toString() });
    EntryLogger entryLogger = null;//from   w w  w  .  j  a v a 2s.  c o  m
    try {
        entryLogger = new EntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs()));
        fail("Expecting FileNotFoundException");
    } catch (FileNotFoundException e) {
        assertEquals("Entry log directory does not exist", e.getLocalizedMessage());
    } finally {
        if (entryLogger != null) {
            entryLogger.shutdown();
        }
    }
}

From source file:org.apache.myfaces.shared_impl.renderkit.RendererUtils.java

/**
 * Helper method which loads a resource file (such as css) by a given context path and a file name.
 * Useful to provide css files (or js files) inline.
 *
 * @param ctx  <code>FacesContext</code> object to calculate the context path of the web application.
 * @param file name of the resource file (e.g. <code>foo.css</code>).
 * @return the content of the resource file, or <code>null</code> if no such file is available.
 *//*  w  w w . j a va 2  s .c  o m*/
public static String loadResourceFile(FacesContext ctx, String file) {

    ByteArrayOutputStream content = new ByteArrayOutputStream(10240);

    InputStream in = null;
    try {
        in = ctx.getExternalContext().getResourceAsStream(file);
        if (in == null) {
            return null;
        }

        byte[] fileBuffer = new byte[10240];
        int read;
        while ((read = in.read(fileBuffer)) > -1) {
            content.write(fileBuffer, 0, read);
        }
    } catch (FileNotFoundException e) {
        if (log.isWarnEnabled())
            log.warn("no such file " + file, e);
        content = null;
    } catch (IOException e) {
        if (log.isWarnEnabled())
            log.warn("problems during processing resource " + file, e);
        content = null;
    } finally {
        try {
            content.close();
        } catch (IOException e) {
            log.warn(e.getLocalizedMessage(), e);
        }
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                log.warn(e.getLocalizedMessage(), e);
            }
        }
    }

    return content.toString();
}

From source file:org.eclipse.jubula.app.dashboard.DashboardApp.java

/**
 *  /*from  w  w w  . j  a v  a2 s. co m*/
 * {@inheritDoc} 
 */
public Object start(IApplicationContext context) throws Exception {
    final String testdriverClassName = System.getProperty(PROP_DRIVER_CLASS_NAME);
    if (testdriverClassName == null) {
        FileInputStream configFileInputStream = null;
        Properties configuration = new Properties();
        try {
            String path = System.getenv("TEST_DASHBOARD_PROPERTIES"); //$NON-NLS-1$
            if (StringUtils.isBlank(path)) {
                path = System.getProperty("TEST_DASHBOARD_PROPERTIES"); //$NON-NLS-1$
            }
            if (StringUtils.isBlank(path)) {
                String home = System.getProperty("user.home"); //$NON-NLS-1$
                path = home + File.separator + JUBULA_HOME;
            }
            path += File.separator + PROPERTIES_FILE_NAME;
            configFileInputStream = new FileInputStream(path);
            configuration.load(configFileInputStream);
            System.getProperties().putAll(configuration);
        } catch (FileNotFoundException fnfe) {
            System.out.println(fnfe.getLocalizedMessage());
        } finally {
            if (configFileInputStream != null) {
                configFileInputStream.close();
            }
        }
    }
    final String connectionUrl = System.getProperty(PROP_JDBC_URL);
    final String username = System.getProperty(PROP_USERNAME);
    final String password = System.getProperty(PROP_PASSWORD);
    final String driverClassName = System.getProperty(PROP_DRIVER_CLASS_NAME);

    final DatabaseConnectionInfo connectionInfo = new DatabaseConnectionInfo() {
        @Override
        public String getDriverClassName() {
            return driverClassName;
        }

        @Override
        public String getConnectionUrl() {
            return connectionUrl;
        }
    };

    return PlatformUI.createAndRunWorkbench(PlatformUI.createDisplay(),
            new DashboardWindowAdvisor(connectionInfo, username, password));
}

From source file:org.exoplatform.utils.ExoDocumentUtils.java

/**
 * Gets a DocumentInfo with info coming from the document at the given URI.
 * /*from w  w  w .  j  a va  2  s . c  o  m*/
 * @param contentUri the content URI of the document (content:// ...)
 * @param context
 * @return a DocumentInfo or null if an error occurs
 */
public static DocumentInfo documentFromContentUri(Uri contentUri, Context context) {
    if (contentUri == null)
        return null;

    try {
        ContentResolver cr = context.getContentResolver();
        Cursor c = cr.query(contentUri, null, null, null, null);
        int sizeIndex = c.getColumnIndex(OpenableColumns.SIZE);
        int nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
        int orientIndex = c.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION);
        c.moveToFirst();

        DocumentInfo document = new DocumentInfo();
        document.documentName = c.getString(nameIndex);
        document.documentSizeKb = c.getLong(sizeIndex) / 1024;
        document.documentData = cr.openInputStream(contentUri);
        document.documentMimeType = cr.getType(contentUri);
        if (orientIndex != -1) { // if found orientation column
            document.orientationAngle = c.getInt(orientIndex);
        }
        return document;
    } catch (FileNotFoundException e) {
        Log.d(LOG_TAG, e.getClass().getSimpleName(), e.getLocalizedMessage());
    } catch (Exception e) {
        Log.e(LOG_TAG, "Cannot retrieve the content at " + contentUri);
        if (Log.LOGD)
            Log.d(LOG_TAG, e.getMessage() + "\n" + Log.getStackTraceString(e));
    }
    return null;
}

From source file:it.geosolutions.geoserver.rest.publisher.GeoserverRESTImageMosaicTest.java

@Test
public void testCreateDeleteImageMosaicDatastore() throws MalformedURLException, UnsupportedEncodingException {
    if (!enabled()) {
        return;//from  w ww .  j  av a 2  s . c  o  m
    }
    deleteAll();

    final String wsName = "geosolutions";
    final String coverageStoreName = "resttestImageMosaic";

    final GSImageMosaicEncoder coverageEncoder = new GSImageMosaicEncoder();
    /*
     * unused in mosaic creation
     * this is only useful if you want to modify an existing coverage:
     * publisher.configureCoverage(ce, wsname, csname);
     * or create a new one from an existing store:
     * publisher.createCoverage(ce, wsname, csname);
     */
    //        coverageEncoder.setName("time_geotiff");

    coverageEncoder.setAllowMultithreading(true);
    coverageEncoder.setBackgroundValues("");
    coverageEncoder.setFilter("");
    coverageEncoder.setInputTransparentColor("");
    coverageEncoder.setLatLonBoundingBox(-180, -90, 180, 90, "EPSG:4326");
    coverageEncoder.setMaxAllowedTiles(6000);
    coverageEncoder.setNativeBoundingBox(-180, -90, 180, 90, "EPSG:4326");
    coverageEncoder.setOutputTransparentColor("");
    coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
    coverageEncoder.setSRS("EPSG:4326");
    coverageEncoder.setSUGGESTED_TILE_SIZE("256,256");
    coverageEncoder.setUSE_JAI_IMAGEREAD(true);

    GSVersionDecoder v = reader.getGeoserverVersion();
    if (v.compareTo(GSVersionDecoder.VERSION.v24) >= 0) {
        GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder("GRAY_INDEX",
                "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units", "REAL_32BITS");
        coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
    }

    // activate time
    final GSDimensionInfoEncoder time = new GSDimensionInfoEncoder(true);
    time.setPresentation(Presentation.LIST);
    // set time metadata
    coverageEncoder.setMetadata("time", time);
    // not active elevation
    coverageEncoder.setMetadata("elevation", new GSDimensionInfoEncoder());

    assertTrue(publisher.createWorkspace(wsName));

    LOGGER.info(coverageEncoder.toString());

    final String styleName = "raster";
    File sldFile;
    try {
        sldFile = new ClassPathResource("testdata/raster.sld").getFile();
        // insert style
        assertTrue(publisher.publishStyle(sldFile));
    } catch (IOException e1) {
        assertFalse(e1.getLocalizedMessage(), Boolean.FALSE);
        e1.printStackTrace();
    }

    GSLayerEncoder layerEncoder = new GSLayerEncoder();

    layerEncoder.setDefaultStyle(styleName);
    LOGGER.info(layerEncoder.toString());
    // creation test
    RESTCoverageStore coverageStore = null;
    try {
        final File mosaicFile = new ClassPathResource("testdata/time_geotiff/").getFile();

        if (!publisher.publishExternalMosaic(wsName, coverageStoreName, mosaicFile, coverageEncoder,
                layerEncoder)) {
            fail();
        }
        coverageStore = reader.getCoverageStore(wsName, coverageStoreName);

        if (coverageStore == null) {
            LOGGER.error("*** coveragestore " + coverageStoreName + " has not been created.");
            fail("*** coveragestore " + coverageStoreName + " has not been created.");
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    }
    // Get a Granule
    String coverageName = "time_geotiff";
    RESTStructuredCoverageGranulesList granules = reader.getGranules(wsName, coverageStoreName, coverageName,
            null, null, null);
    String granuleId = granules.get(0).getFid();
    // Test Granule Exists
    assertTrue(reader.existsGranule(wsName, coverageStoreName, coverageName, granuleId));
    // test a Granule does not exists
    assertFalse(reader.existsGranule(wsName, coverageStoreName, coverageName,
            granuleId.substring(0, granuleId.indexOf(".")) + "." + granules.size() + 1));

    // removing recursively coveragestore
    boolean removed = publisher.removeCoverageStore(coverageStore.getWorkspaceName(), coverageStore.getName(),
            true);
    if (!removed) {
        LOGGER.error("*** CoverageStore " + coverageStoreName + " has not been removed.");
        fail("*** CoverageStore " + coverageStoreName + " has not been removed.");
    }

    assertTrue(publisher.removeStyle(styleName));
    assertTrue(publisher.removeWorkspace(wsName));
}

From source file:resources.utils.CronusFileIoUtils.java

/**
 * 20130927 Fixed Memory Leak. Dont use line by line, just use apache
 * commons io!! so simple and easy!/* www.  ja va  2  s  .c om*/
 * 
 * @param filePath
 * @return
 */
public String readFileToString(String filePath) {

    String fileContentString = null;

    try {

        File realFile = this.getRealFileFromRelativePath(filePath);
        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();

}