List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:fr.wseduc.webdav.WebDav.java
private void put(Message<JsonObject> message) { String filePath = message.body().getString("file"); if (filePath == null || filePath.trim().isEmpty()) { sendError(message, "Invalid file."); return;/*from w w w . ja v a2s. co m*/ } FileInputStream fis; try { fis = new FileInputStream(filePath); } catch (FileNotFoundException e) { sendError(message, "Invalid file.", e); return; } String uri = message.body().getString("uri"); Sardine sardine = getSardine(uri, message); if (sardine == null) return; try { sardine.put(uri, fis); sendOK(message); } catch (IOException e) { sendError(message, e.getMessage(), e); } }
From source file:com.sshtools.j2ssh.authentication.UserGridCredential.java
private static GSSCredential retrieveRemoteProxy(SshConnectionProperties properties, int proxyType, int lifetimeHours) throws IOException { GSSCredential gsscredential = null; CoGProperties cogproperties = CoGProperties.getDefault(); String hostname = DEFAULT_MYPROXY_SERVER; hostname = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_MYPROXY_HOSTNAME, hostname); String username = System.getProperty("user.name"); username = PreferencesStore.get(SshTerminalPanel.PREF_MYPROXY_UNAME, username); if (properties instanceof SshToolsConnectionProfile) { SshToolsConnectionProfile profile = (SshToolsConnectionProfile) properties; hostname = profile.getApplicationProperty(SshTerminalPanel.PREF_DEFAULT_MYPROXY_HOSTNAME, hostname); username = profile.getApplicationProperty(SshTerminalPanel.PREF_MYPROXY_UNAME, username); }// w ww . j a va 2 s. c o m do { boolean flag = false; StringBuffer stringbuffer = new StringBuffer(); StringBuffer stringbuffer1 = new StringBuffer(); StringBuffer stringbuffer2 = new StringBuffer(); if (myProxyPrompt != null) { myProxyPrompt.setHost(hostname); myProxyPrompt.setAccountName(username); boolean flag1 = myProxyPrompt.doGet(properties.getWindow(), stringbuffer, stringbuffer1, stringbuffer2); myProxyPrompt.setError(""); if (flag1) throw new IOException("Canceled by user."); if (myProxyPrompt.getAnother()) return null; StringBuffer stringbufferF = new StringBuffer(); StringBuffer stringbufferP = new StringBuffer(); if (myProxyPrompt.getBrowser()) { gsscredential = chooseCert(proxyType, lifetimeHours, properties); if (gsscredential == null) continue; else return gsscredential; } if (myProxyPrompt.keyBased(stringbufferF, stringbufferP)) { try { KeyStore store = null; String passphrase = stringbufferP.toString(); File keyfile = new File(stringbufferF.toString()); Security.addProvider(new BouncyCastleProvider()); store = KeyStore.getInstance("PKCS12", "BC"); FileInputStream in = new FileInputStream(keyfile); store.load(in, passphrase.toCharArray()); Enumeration e = store.aliases(); if (!e.hasMoreElements()) { JOptionPane.showMessageDialog(properties.getWindow(), "Could not access your certificate: no certificates found in file.", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); continue; } String alias = (String) e.nextElement(); java.security.cert.Certificate cert = store.getCertificate(alias); Key key = store.getKey(alias, passphrase.toCharArray()); if (!(cert instanceof X509Certificate)) { JOptionPane.showMessageDialog(properties.getWindow(), "Could not access your certificate: bad certificate type.", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); continue; } if (!(key instanceof PrivateKey)) { JOptionPane.showMessageDialog(properties.getWindow(), "Could not access your certificate: bad key type.", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); continue; } BouncyCastleCertProcessingFactory factory = BouncyCastleCertProcessingFactory.getDefault(); GlobusCredential globuscredential = factory.createCredential( new X509Certificate[] { (X509Certificate) cert }, (PrivateKey) key, cogproperties.getProxyStrength(), lifetimeHours * 3600, proxyType, (X509ExtensionSet) null); if (globuscredential != null) { if (SAVE_PKCS12_PROXY) { ProxyHelper.saveProxy(globuscredential, properties); } try { globuscredential.verify(); gsscredential = new GlobusGSSCredentialImpl(globuscredential, 1); } catch (Exception exception1) { exception1.printStackTrace(); StringWriter stringwriter1 = new StringWriter(); exception1.printStackTrace(new PrintWriter(stringwriter1)); log.debug(stringwriter1); if (exception1.getMessage().indexOf("Expired credentials") >= 0) { JOptionPane.showMessageDialog(properties.getWindow(), "Your certificate has expired, please renew your certificate or try another method for authentication.", "GSI-SSHTerm Authentication", JOptionPane.ERROR_MESSAGE); continue; } else { errorReport(properties.getWindow(), "Could not load your certificate", exception1); continue; } } } return gsscredential; } catch (java.io.FileNotFoundException exception) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("Certificate: could not find file"); continue; } catch (Exception exception) { if (exception.getMessage().indexOf("Illegal key size") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); errorReport(properties.getWindow(), "To use this PKCS#12 file you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files\n (see http://java.sun.com/javase/downloads/index.jsp for Java 6 and http://java.sun.com/javase/downloads/index_jdk5.jsp for Java 5)", exception); continue; } else if (exception.getMessage().indexOf("wrong password") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("Certificate: wrong password?"); continue; } else { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); errorReport(properties.getWindow(), "Unknown problem while loading your certificate", exception); continue; } } } } CertUtil.init(); // save username if changed: if (!stringbuffer1.toString().equals(username)) { PreferencesStore.put(SshTerminalPanel.PREF_LAST_MYPROXY_USERNAME, stringbuffer1.toString()); } String port_S = DEFAULT_MYPROXY_PORT; port_S = PreferencesStore.get(SshTerminalPanel.PREF_MYPROXY_PORT, port_S); if (properties instanceof SshToolsConnectionProfile) { SshToolsConnectionProfile profile = (SshToolsConnectionProfile) properties; port_S = profile.getApplicationProperty(SshTerminalPanel.PREF_MYPROXY_PORT, port_S); } int port = 7512; try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_MYPROXY_PORT + ", property value= " + port_S + ")."); } MyProxy myproxy = null; myproxy = new MyProxy(stringbuffer.toString(), port); try { gsscredential = myproxy.get(null, stringbuffer1.toString(), stringbuffer2.toString(), lifetimeHours * 3600); if (SAVE_MYPROXY_PROXY) { GlobusCredential proxy = ((GlobusGSSCredentialImpl) gsscredential).getGlobusCredential(); ProxyHelper.saveProxy(proxy, properties); } log.debug("A proxy has been received for user " + stringbuffer1); return gsscredential; } catch (Exception exception) { if (exception.getMessage().indexOf("Credentials do not exist") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: No credentials on server (wrong username?)"); } else if (exception.getMessage().indexOf("Bad password") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Bad username and/or password"); } else if (exception.getMessage() .indexOf("Failed to map username too DN via grid-mapfile CA failed to map user") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Bad username/password"); } else if (exception.getMessage().indexOf("PAM authentication failed") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Bad username/password"); } else if (exception.getMessage().indexOf("credentials have expired") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Credentials on server has expired"); } else if (exception.getMessage().indexOf(stringbuffer.toString()) >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Could not connect to MyProxy server"); } else if (exception.getMessage().indexOf("Password must be at least 6 characters long") >= 0) { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); myProxyPrompt.setError("MyProxy: Password must be at least 6 characters long."); } else { exception.printStackTrace(); StringWriter stringwriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringwriter)); log.debug(stringwriter); errorReport(properties.getWindow(), "Unknown problem while accessing MyProxy", exception); continue; } } } while (true); }
From source file:com.cyberway.issue.crawler.frontier.BdbFrontier.java
public void initialize(CrawlController c) throws FatalConfigurationException, IOException { this.controller = c; // fill in anything from a checkpoint recovery first (because // usual initialization will skip initQueueOfQueues in checkpoint) if (c.isCheckpointRecover()) { // If a checkpoint recover, copy old values from serialized // instance into this Frontier instance. Do it this way because // though its possible to serialize BdbFrontier, its currently not // possible to set/remove frontier attribute plugging the // deserialized object back into the settings system. // The below copying over is error-prone because its easy // to miss a value. Perhaps there's a better way? Introspection? BdbFrontier f = null;/* w ww . jav a 2 s . c o m*/ try { f = (BdbFrontier) CheckpointUtils.readObjectFromFile(this.getClass(), c.getCheckpointRecover().getDirectory()); } catch (FileNotFoundException e) { throw new FatalConfigurationException("Failed checkpoint " + "recover: " + e.getMessage()); } catch (IOException e) { throw new FatalConfigurationException("Failed checkpoint " + "recover: " + e.getMessage()); } catch (ClassNotFoundException e) { throw new FatalConfigurationException("Failed checkpoint " + "recover: " + e.getMessage()); } this.nextOrdinal = f.nextOrdinal; this.totalProcessedBytes = f.totalProcessedBytes; this.liveDisregardedUriCount = f.liveDisregardedUriCount; this.liveFailedFetchCount = f.liveFailedFetchCount; this.processedBytesAfterLastEmittedURI = f.processedBytesAfterLastEmittedURI; this.liveQueuedUriCount = f.liveQueuedUriCount; this.liveSucceededFetchCount = f.liveSucceededFetchCount; this.lastMaxBandwidthKB = f.lastMaxBandwidthKB; this.readyClassQueues = f.readyClassQueues; this.inactiveQueues = reinit(f.inactiveQueues, "inactiveQueues"); this.retiredQueues = reinit(f.retiredQueues, "retiredQueues"); this.snoozedClassQueues = f.snoozedClassQueues; this.inProcessQueues = f.inProcessQueues; super.initialize(c); wakeQueues(); } else { // perform usual initialization super.initialize(c); } }
From source file:forseti.JGestionArchivos.java
public JGestionArchivos() { m_StatusS3 = OKYDOKY;/*from w w w . j a v a2 s . c o m*/ m_Error = ""; m_Archivos = new Vector(); try { FileReader file = new FileReader("/usr/local/forseti/bin/.forseti_pac"); BufferedReader buff = new BufferedReader(file); boolean eof = false; while (!eof) { String line = buff.readLine(); if (line == null) eof = true; else { try { StringTokenizer st = new StringTokenizer(line, "="); String key = st.nextToken(); String value = st.nextToken(); if (key.equals("SERV")) m_HOST = value; if (key.equals("PURL")) m_URL = value; else if (key.equals("PASS")) m_S3_PASSWORD = value; else if (key.equals("USER")) m_S3_USERNAME = value; } catch (NoSuchElementException e) { m_StatusS3 = ERROR; m_Error = "La informacion de conexin al servicio Amazon S3 forseti parece estar mal configurada"; } } } buff.close(); } catch (FileNotFoundException e1) { m_StatusS3 = ERROR; m_Error = "Error de archivos S3: " + e1.getMessage(); } catch (IOException e1) { m_StatusS3 = ERROR; m_Error = "Error de Entrada/Salida S3: " + e1.getMessage(); } }
From source file:com.plugin.base64.Base64ImagePlugin.java
private boolean saveImage(String b64String, String fileName, String dirName, Boolean overwrite, CallbackContext callbackContext) { boolean result = false; try {/* ww w .j a va 2 s . c o m*/ //Directory and File File dir = new File(dirName); if (!dir.exists()) { dir.mkdirs(); } File file = new File(dirName, fileName); //Avoid overwriting a file if (!overwrite && file.exists()) { Log.v(TAG, "File already exists"); // return new PluginResult(PluginResult.Status.OK, "File already exists!"); callbackContext.error("File already exists!"); return false; } //Decode Base64 back to Binary format byte[] decodedBytes = Base64.decodeBase64(b64String.getBytes()); //Save Binary file to phone file.createNewFile(); FileOutputStream fOut = new FileOutputStream(file); fOut.write(decodedBytes); fOut.close(); Log.v(TAG, "Saved successfully"); callbackContext.success(file.getPath()); // return new PluginResult(PluginResult.Status.OK, "Saved successfully!"); result = true; } catch (FileNotFoundException e) { Log.v(TAG, "File not Found"); // return new PluginResult(PluginResult.Status.ERROR, "File not Found!"); callbackContext.error("File not Found!"); result = false; } catch (IOException e) { Log.v(TAG, e.getMessage()); // return new PluginResult(PluginResult.Status.ERROR, e.getMessage()); callbackContext.error("Exception :" + e.getMessage()); result = false; } return result; }
From source file:com.tresys.jalop.utils.jnltest.PublisherImpl.java
/** * Write status information about a record out to disk. * @param lri The {@link LocalRecordInfo} object output stats for. * @return <code>true</code> If the data was successfully written out. * <code>false</code> otherwise. *///w w w . ja v a2 s . co m @SuppressWarnings("unchecked") final boolean dumpStatus(final String serialId, final Map<String, String> statusMap) { final JSONParser p = new JSONParser(); JSONObject status; File statusFile; BufferedOutputStream w; final File serialDir = new File(this.inputRoot, SID_FORMATER.format(Long.valueOf(serialId))); try { statusFile = new File(serialDir, STATUS_FILENAME); if (!statusFile.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("The '" + STATUS_FILENAME + "' file does not exist so creating it."); } statusFile.createNewFile(); status = new JSONObject(); } else { status = (JSONObject) p.parse(new FileReader(statusFile)); } status.putAll(statusMap); w = new BufferedOutputStream(new FileOutputStream(statusFile)); w.write(status.toJSONString().getBytes("utf-8")); w.close(); } catch (final FileNotFoundException e) { LOGGER.error("Failed to open status file for writing:" + e.getMessage()); return false; } catch (final ParseException e) { if (LOGGER.isInfoEnabled()) { LOGGER.info("'" + STATUS_FILENAME + "' file"); } status = new JSONObject(); } catch (final UnsupportedEncodingException e) { LOGGER.error("cannot find UTF-8 encoder?"); return false; } catch (final IOException e) { LOGGER.error("failed to write to the status file, aborting"); return false; } return true; }
From source file:datascript.tools.DataScriptTool.java
private AST parsePackage() throws Exception { String pkgFileName = ToolContext.getFullName(); System.out.println("Parsing " + pkgFileName); // set up lexer, parser and token buffer try {/* www.j a v a 2 s .c o m*/ FileInputStream is = new FileInputStream(pkgFileName); DataScriptLexer lexer = new DataScriptLexer(is); lexer.setFilename(pkgFileName); lexer.setTokenObjectClass("datascript.antlr.util.FileNameToken"); TokenStreamHiddenTokenFilter filter = new TokenStreamHiddenTokenFilter(lexer); filter.discard(DataScriptParserTokenTypes.WS); filter.discard(DataScriptParserTokenTypes.COMMENT); filter.hide(DataScriptParserTokenTypes.DOC); parser = new DataScriptParser(filter); } catch (java.io.FileNotFoundException fnfe) { ToolContext.logError((parser == null) ? null : (TokenAST) parser.getAST(), fnfe.getMessage()); } if (parser == null) return null; parser.setContext(context); // must call this to see file name in error messages parser.setFilename(pkgFileName); // use custom node class containing line information parser.setASTNodeClass("datascript.antlr.util.TokenAST"); // parse file and get root node of syntax tree parser.translationUnit(); AST retVal = parser.getAST(); if (context.getErrorCount() != 0 || retVal == null) throw new ParserException("DataScriptParser: Parser errors."); String pkgName = ToolContext.getFileName(); pkgName = pkgName.substring(0, pkgName.lastIndexOf(".ds")); TokenAST node = (TokenAST) retVal.getFirstChild(); if (node.getType() != DataScriptParserTokenTypes.PACKAGE || node.getText().equals(pkgName)) ToolContext.logWarning(node, "filename and package name do not match!"); return retVal; }
From source file:com.sec.ose.osi.ui.frm.main.identification.autoidentify.JPanImportSPDX.java
private void launchSPDXAutoIdentify() { AutoIdentifyOptions autoIdentifyOptions = new AutoIdentifyOptions(); autoIdentifyOptions.setIdentifyWhenExistingOnlyOneSamePathFile(getJCheckSamePath().isSelected()); autoIdentifyOptions.setIdentifyRecentCreatedPackageInfo(getJCheckRecentInfo().isSelected()); autoIdentifyOptions.setOverwrite(getJCheckOverwrite().isSelected()); List<String> filePathList = new ArrayList<String>(); for (JPanLocation tmpLocation : getJPanSPDXLocationList()) filePathList.add(tmpLocation.getPath()); UESPDXAutoIdentify ue = new UESPDXAutoIdentify(); ue.setProjectName(IdentifyMediator.getInstance().getSelectedProjectName()); ue.setAutoIdentifyOptions(autoIdentifyOptions); ue.setSPDXFilePathList(filePathList); UIResponseObserver observer = UserRequestHandler.getInstance().handle(UserRequestHandler.SPDX_AUTO_IDENTIFY, ue, true, false);//from w ww .j a va 2 s . c o m SPDXAutoIdentifyResult autoIdentifyResult = new SPDXAutoIdentifyResult( (AutoIdentifyResult) observer.getReturnValue()); // Log to file String autoIdentifyResultLogFilePath = Property.FOLDER_LOGS + File.separator + "OSI_AI_RESULT_" + DateUtil.getCurrentTime("%1$tY%1$tm%1$td_%1$tH%1$tM") + ".log"; File logFile = new File(autoIdentifyResultLogFilePath); PrintWriter pw = null; try { pw = new PrintWriter(logFile); pw.println(autoIdentifyResult.getSummary()); pw.println("-------------------------------------------------------"); pw.println(autoIdentifyResult.getSourceSPDXPackagesInfo()); pw.println("-------------------------------------------------------"); pw.println(autoIdentifyResult.getFailDetails()); pw.close(); } catch (FileNotFoundException e) { log.error( "Cannot write autoIdentifyResult to " + autoIdentifyResultLogFilePath + ", " + e.getMessage()); } finally { if (pw != null) pw.close(); } // show result JDlgIdentifyResult.getInstance().setAutoIdentifyResult(autoIdentifyResult); JDlgIdentifyResult.getInstance().setVisible(true); }
From source file:com.microsoft.tfs.client.common.ui.framework.compare.NonWorkspaceFileNode.java
@Override protected InputStream createStream() throws CoreException { FileInputStream fileInputStream; try {/*from ww w . j a va 2 s. c o m*/ fileInputStream = new FileInputStream(file); } catch (final FileNotFoundException e) { throw new CoreException( new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0, e.getMessage(), e)); } return new BufferedInputStream(fileInputStream); }
From source file:com.cmput301w15t15.travelclaimsapp.FileManager.java
/** * Saves claimlist to file and attempts to save online if there is an internet connection. * /*from w w w . j ava2s . c om*/ * @param ClaimList claimList * @param String username */ public void saveClaimLInFile(ClaimList claimList, String username) { Thread thread = new onlineSaveClaimListThread(claimList, username); thread.start(); try { //openFileOutput is a Activity method FileOutputStream fos = context.openFileOutput(CLAIMLISTFILENAME, 0); OutputStreamWriter osw = new OutputStreamWriter(fos); gson.toJson(claimList, osw); osw.flush(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Log.d(TAG, "saveClaimLInFile could not find file: " + e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block Log.d(TAG, "saveClaimLInFile did not work: " + e.getMessage()); } }