List of usage examples for java.io FileNotFoundException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.amazonaws.mturk.cmd.CreateQualificationType.java
public boolean createQualificationType(String qualFile, String answerFile, String propertiesFile, boolean noRetry) { String test = null;/* w w w .j ava 2s . com*/ String answerKey = null; Properties props = new Properties(); try { if (qualFile != null) { test = new FileUtil(qualFile).getString(); } props = super.loadProperties(propertiesFile); if (answerFile != null) { answerKey = (new FileUtil(answerFile)).getString(); } } catch (FileNotFoundException e) { log.error("Couldn't find one of the necessary files: " + e.getLocalizedMessage(), e); return false; } catch (IOException e) { log.error("Error reading one of the necessary files: " + e.getLocalizedMessage(), e); return false; } String autoGranted = props.getProperty("autogranted"); String autoGrantedValue = props.getProperty("autograntedvalue"); String testDuration = props.getProperty("testdurationinseconds", "10800"); //default to 3 hours Long retryDelay = noRetry ? null : Long.valueOf(props.getProperty("retrydelayinseconds", "259200")); // default to 3 days String qualName = props.getProperty("name"); if (qualName == null || qualName.trim().length() == 0) { log.error( "Cannot create qualification type. The qualification name is not set. Please enter a value in the 'name' field in the properties file (" + propertiesFile + ")"); return false; } try { // merge Velocity templates if any test = getMergedTemplate(qualFile); answerKey = getMergedTemplate(answerFile); QualificationType qualType = service.createQualificationType(qualName, props.getProperty("keywords"), props.getProperty("description"), QualificationTypeStatus.Active, retryDelay, // retryDelayInSeconds test, answerKey, test != null ? Long.valueOf(testDuration) : null, // testDurationInSeconds autoGranted != null ? Boolean.valueOf(autoGranted) : null, // autoGranted autoGrantedValue != null ? Integer.valueOf(autoGrantedValue) : null // autoGrantedValue ); if (qualType != null) { log.info("Created qualification type: " + qualType.getQualificationTypeId()); FileWriter writer = new FileWriter(propertiesFile + ".success"); try { writer.write(QUALTYPE + System.getProperty("line.separator")); writer.write(qualType.getQualificationTypeId() + System.getProperty("line.separator")); } finally { writer.close(); } log.info("You can take the test here: " + service.getWebsiteURL() + "/mturk/requestqualification?qualificationId=" + qualType.getQualificationTypeId()); return true; } } catch (ParseErrorException parseEx) { try { QAPValidator.validate(test); log.error("The qualification question is not valid: " + parseEx.getLocalizedMessage(), parseEx); } catch (ValidationException valEx) { log.error("The qualification question is not valid: " + valEx.getLocalizedMessage(), valEx); } catch (IOException ioEx) { log.error("The qualification question is not valid: " + parseEx.getLocalizedMessage(), ioEx); } } catch (ObjectAlreadyExistsException exitsEx) { log.error("The qualification type for name '" + qualName + "' already exists.\n"); return false; } catch (Exception e) { log.error("Error creating qualification type: " + e.getLocalizedMessage(), e); return false; } return false; }
From source file:org.pentaho.platform.plugin.action.jfreereport.components.JFreeReportGenerateDefinitionComponent.java
@Override protected boolean executeAction() { boolean result = true; try {// w w w . ja v a2 s. c o m ReportSpec reportSpec = getReportSpec(); if (reportSpec != null) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ReportGenerationUtility.createJFreeReportXML(reportSpec, outputStream, 0, 0, false, "", 0, 0); //$NON-NLS-1$ String reportDefinition = new String(outputStream.toByteArray()); addTempParameterObject(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN, reportDefinition); // if that parameter is not defined, we do query for backward compatibility. if (!isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY) || "true".equals(getInputParameter( //$NON-NLS-1$ AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTTEMP_PERFQRY))) { try { addTempParameterObject(AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT, getResultSet(reportSpec)); } catch (Exception e) { result = false; } } } } catch (FileNotFoundException ex) { error(ex.getLocalizedMessage()); result = false; } return result; }
From source file:org.apache.ambari.server.security.encryption.FileBasedCredentialStoreService.java
/** * Writes the specified KeyStore to a file. * * @param keyStore the KeyStore to write to a file * @param keyStoreFile the File in which to store the KeyStore data * @throws AmbariException if an error occurs while writing the KeyStore data *///from w w w . j a va 2 s . co m private void putKeyStore(KeyStore keyStore, File keyStoreFile) throws AmbariException { LOG.debug("Writing key store to {}", keyStoreFile.getAbsolutePath()); FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(new File(keyStoreDir, KEYSTORE_FILENAME)); writeKeyStore(keyStore, outputStream); } catch (FileNotFoundException e) { throw new AmbariException( String.format("Failed to open the key store file: %s", e.getLocalizedMessage()), e); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:net.straylightlabs.tivolibre.DecoderApp.java
private void decode(InputStream input, OutputStream output, DecoderOptions options) { try (BufferedInputStream inputStream = new BufferedInputStream(input); BufferedOutputStream outputStream = new BufferedOutputStream(output)) { TivoDecoder decoder = new TivoDecoder.Builder().input(inputStream).output(outputStream).mak(options.mak) .compatibilityMode(options.compatibilityMode).build(); boolean decodeSuccessful; if (options.noVideo) { decodeSuccessful = decoder.decodeMetadata(); } else {/*from ww w . jav a 2 s . c om*/ decodeSuccessful = decoder.decode(); } if (decodeSuccessful && options.dumpMetadata) { dumpMetadata(decoder); } if (decodeSuccessful && options.pytivoMetadata) { dumpPytivoMetadata(decoder, options.pytivoMetadataPath); } } catch (FileNotFoundException e) { logger.error("Error: {}", e.getLocalizedMessage()); } catch (IOException e) { logger.error("Error reading/writing files: {}", e.getLocalizedMessage()); } }
From source file:org.apache.ambari.server.security.encryption.FileBasedCredentialStore.java
/** * Writes the specified KeyStore to a file. * * @param keyStore the KeyStore to write to a file * @param keyStoreFile the File in which to store the KeyStore data * @throws AmbariException if an error occurs while writing the KeyStore data *///from w ww. ja va 2 s. co m private void putKeyStore(KeyStore keyStore, File keyStoreFile) throws AmbariException { LOG.debug("Writing key store to {}", keyStoreFile.getAbsolutePath()); FileOutputStream outputStream = null; try { outputStream = new FileOutputStream(this.keyStoreFile); writeKeyStore(keyStore, outputStream); } catch (FileNotFoundException e) { throw new AmbariException( String.format("Failed to open the key store file: %s", e.getLocalizedMessage()), e); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:org.apache.ambari.server.security.encryption.FileBasedCredentialStoreService.java
/** * Reads the key store data from the specified file. If the file does not exist, a new KeyStore * will be created./*from w w w .j av a 2 s . co m*/ * * @param keyStoreFile a File pointing to the key store file * @param keyStoreType the type of key store data to read (or create) * @return the loaded KeyStore * @throws AmbariException if the Master Key Service is not set * @see CredentialStoreServiceImpl#loadCredentialStore() */ private KeyStore getKeyStore(final File keyStoreFile, String keyStoreType) throws AmbariException { KeyStore keyStore; FileInputStream inputStream; if (keyStoreFile.exists()) { LOG.debug("Reading key store from {}", keyStoreFile.getAbsolutePath()); try { inputStream = new FileInputStream(keyStoreFile); } catch (FileNotFoundException e) { throw new AmbariException( String.format("Failed to open the key store file: %s", e.getLocalizedMessage()), e); } } else { LOG.debug("Key store file not found in {}. Returning new (non-persisted) KeyStore", keyStoreFile.getAbsolutePath()); inputStream = null; } try { keyStore = loadKeyStore(inputStream, keyStoreType); } finally { IOUtils.closeQuietly(inputStream); } return keyStore; }
From source file:com.qumasoft.guitools.compare.FileContentsListModel.java
FileContentsListModel(File file, CompareFilesForGUI compareResult, boolean isFirstFile, FileContentsListModel firstFileListModel) { super();//from ww w. ja va 2 s .c o m this.currentDifferenceIndex = -1; BufferedReader fileReader = null; if (file.canRead()) { try { fileReader = new BufferedReader(new FileReader(file)); int lineIndex = 0; while (true) { String line = fileReader.readLine(); if (line == null) { break; } String formattedLine = formatLine(line); ContentRow row = new ContentRow(formattedLine, line, compareResult, lineIndex, isFirstFile); if (!isFirstFile) { // If this is the 2nd file, for replacement lines figure out where in the line things are different. if (row.getRowType() == ContentRow.ROWTYPE_REPLACE) { System.out.println("lineIndex: [" + lineIndex + "]"); ContentRow firstModelRow = firstFileListModel.get(lineIndex); row.decorateDifferences(firstModelRow); firstModelRow.decorateDifferences(row); } } if (row.getBlankRowsBefore() > 0) { for (int i = 0; i < row.getBlankRowsBefore(); i++) { addBlankRow(row.getDelta()); } } addElement(row); if (row.getBlankRowsAfter() > 0) { for (int i = 0; i < row.getBlankRowsAfter(); i++) { addBlankRow(row.getDelta()); } } lineIndex++; } } catch (java.io.FileNotFoundException e) { LOGGER.log(Level.WARNING, "Caught exception: " + e.getClass().toString() + ": " + e.getLocalizedMessage()); } catch (java.io.IOException e) { LOGGER.log(Level.WARNING, "Caught exception: " + e.getClass().toString() + ": " + e.getLocalizedMessage()); } finally { try { if (fileReader != null) { fileReader.close(); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Caught exception: " + e.getClass().toString() + ": " + e.getLocalizedMessage()); } } } }
From source file:org.apache.ambari.server.security.encryption.FileBasedCredentialStore.java
/** * Reads the key store data from the specified file. If the file does not exist, a new KeyStore * will be created.//www. j a va2 s . c om * * @param keyStoreFile a File pointing to the key store file * @param keyStoreType the type of key store data to read (or create) * @return the loaded KeyStore * @throws AmbariException if the Master Key Service is not set * @see AbstractCredentialStore#loadCredentialStore() */ private KeyStore getKeyStore(final File keyStoreFile, String keyStoreType) throws AmbariException { KeyStore keyStore; FileInputStream inputStream; if (keyStoreFile.exists()) { if (keyStoreFile.length() > 0) { LOG.debug("Reading key store from {}", keyStoreFile.getAbsolutePath()); try { inputStream = new FileInputStream(keyStoreFile); } catch (FileNotFoundException e) { throw new AmbariException( String.format("Failed to open the key store file: %s", e.getLocalizedMessage()), e); } } else { LOG.debug("The key store file found in {} is empty. Returning new (non-persisted) KeyStore", keyStoreFile.getAbsolutePath()); inputStream = null; } } else { LOG.debug("Key store file not found in {}. Returning new (non-persisted) KeyStore", keyStoreFile.getAbsolutePath()); inputStream = null; } try { keyStore = loadKeyStore(inputStream, keyStoreType); } finally { IOUtils.closeQuietly(inputStream); } return keyStore; }
From source file:org.geotools.coverage.io.util.Utilities.java
public static Properties loadPropertiesFromURL(URL propsURL) { final Properties properties = new Properties(); InputStream stream = null;//from www . j a v a2 s . com InputStream openStream = null; try { openStream = propsURL.openStream(); stream = new BufferedInputStream(openStream); properties.load(stream); } catch (FileNotFoundException e) { if (LOGGER.isLoggable(Level.SEVERE)) LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); return null; } catch (IOException e) { if (LOGGER.isLoggable(Level.SEVERE)) LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); return null; } finally { if (stream != null) IOUtils.closeQuietly(stream); if (openStream != null) IOUtils.closeQuietly(openStream); } return properties; }
From source file:im.ene.lab.toro.sample.activity.MainActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode != 1000) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { try {/* w ww .jav a2 s.c om*/ Log.e(TAG, "onResume: " + Arrays.toString(Util.loadMovieFolder())); } catch (FileNotFoundException e) { Log.e(TAG, "onResume: " + e.getLocalizedMessage()); e.printStackTrace(); } } }