List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.polyvi.xface.extension.capture.XCaptureScreenImpl.java
/** * ?,url?/*from w w w . j a v a 2 s.c o m*/ */ private void getFileUri(Bitmap bitmap, String savePath, CompressFormat mimeType) { /** ?? */ mkDir(savePath); File pic = new File(savePath); String absPath = pic.getAbsolutePath(); FileOutputStream fos = null; try { fos = new FileOutputStream(pic); bitmap.compress(mimeType, HIGHQUALITY, fos); fos.flush(); fos.close(); mCallbackContext.success(getResult(ResultCode.SUCCESS, pic.getAbsolutePath())); } catch (FileNotFoundException e) { String msg = "File Not Found! Path is " + absPath; XLog.e(CLASS_NAME, msg); mCallbackContext.error(getResult(ResultCode.IO_ERROR, msg)); } catch (IOException e) { String msg = e.getMessage(); XLog.e(CLASS_NAME, msg); mCallbackContext.error(getResult(ResultCode.IO_ERROR, msg)); } }
From source file:fNIRs.FNIRsStats.java
private static Scanner makeScanner(File file) { FileReader reader;// ww w. ja v a 2s . co m try { // the file may or may not exist at this point reader = new FileReader(file); } catch (FileNotFoundException fnf_exception) { // WE WILL PROBABLY WANT TO INTEGRATE THIS INTO THE GUI // Print the name of the missing file: localError(fnf_exception.getMessage()); return null; } catch (Exception ex) { localError("unknown problem creating FileReader for \"" + file + "\": " + ex.getMessage()); return null; } // create Scanner to read easily from the input files: Scanner s = new Scanner(new BufferedReader(reader)); s.useLocale(Locale.US); // tell the scanner that numbers in the input // are formatted with decimal points, not // commas, etc. return s; }
From source file:com.l2jfree.gameserver.scripting.L2ScriptEngineManager.java
private void executeAllScriptsInDirectory(File dir, boolean recurseDown, int maxDepth, int currentDepth) { if (dir.isDirectory()) { for (File file : dir.listFiles()) { if (file.isDirectory() && recurseDown && maxDepth > currentDepth) { if (VERBOSE_LOADING) { _log.info("Entering folder: " + file.getName()); }// ww w . ja v a2 s. c om this.executeAllScriptsInDirectory(file, recurseDown, maxDepth, currentDepth + 1); } else if (file.isFile()) { try { String name = file.getName(); int lastIndex = name.lastIndexOf('.'); String extension; if (lastIndex != -1) { extension = name.substring(lastIndex + 1); ScriptEngine engine = getEngineByExtension(extension); if (engine != null) { this.executeScript(engine, file); } } } catch (FileNotFoundException e) { // should never happen _log.error(e.getMessage(), e); } catch (ScriptException e) { reportScriptFileError(file, e); //_log.error(e.getMessage(),e); } } } } else { throw new IllegalArgumentException( "The argument directory either doesnt exists or is not an directory."); } }
From source file:forge.download.GuiDownloadService.java
@Override public void run() { Proxy p = getProxy();//from www .ja v a 2s .c o m int bufferLength; int iCard = 0; byte[] buffer = new byte[1024]; for (Entry<String, String> kv : files.entrySet()) { if (cancel) { break; } String url = kv.getValue(); final File fileDest = new File(kv.getKey()); final File base = fileDest.getParentFile(); FileOutputStream fos = null; try { // test for folder existence if (!base.exists() && !base.mkdir()) { // create folder if not found System.out.println("Can't create folder" + base.getAbsolutePath()); } URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection(p); // don't allow redirections here -- they indicate 'file not found' on the server conn.setInstanceFollowRedirects(false); conn.connect(); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { conn.disconnect(); System.out.println(url); System.out.println("Skipped Download for: " + fileDest.getPath()); update(++iCard, fileDest); skipped++; continue; } fos = new FileOutputStream(fileDest); InputStream inputStream = conn.getInputStream(); while ((bufferLength = inputStream.read(buffer)) > 0) { fos.write(buffer, 0, bufferLength); } } catch (final ConnectException ce) { System.out.println("Connection refused for url: " + url); } catch (final MalformedURLException mURLe) { System.out.println("Error - possibly missing URL for: " + fileDest.getName()); } catch (final FileNotFoundException fnfe) { String formatStr = "Error - the LQ picture %s could not be found on the server. [%s] - %s"; System.out.println(String.format(formatStr, fileDest.getName(), url, fnfe.getMessage())); } catch (final Exception ex) { Log.error("LQ Pictures", "Error downloading pictures", ex); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { System.out.println("error closing output stream"); } } } update(++iCard, fileDest); } }
From source file:com.example.cuisoap.agrimac.homePage.machineDetail.machineInfoFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData();/*from ww w . j a v a 2s . com*/ Log.e("uri", uri.toString()); ContentResolver cr = context.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); bitmap = ImageUtils.comp(bitmap); switch (requestCode) { case 1: license_uri1 = uri; license_pic1.setImageBitmap(bitmap); license_pic1.setVisibility(View.VISIBLE); license1.setVisibility(View.GONE); license_pic1.setOnClickListener(myOnClickListener); machineDetailData.machine_license_filepath1 = ImageUtils.saveMyBitmap(bitmap, null); break; case 2: license_uri2 = uri; license_pic2.setImageBitmap(bitmap); license_pic2.setVisibility(View.VISIBLE); license2.setVisibility(View.GONE); license_pic2.setOnClickListener(myOnClickListener); machineDetailData.machine_license_filepath2 = ImageUtils.saveMyBitmap(bitmap, null); break; } } 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.moviejukebox.tools.WebBrowser.java
@SuppressWarnings("resource") public String request(URL url, Charset charset) throws IOException { LOG.debug("Requesting {}", url.toString()); // get the download limit for the host ThreadExecutor.enterIO(url);//from w w w.ja v a 2 s .c om StringWriter content = new StringWriter(10 * 1024); try { URLConnection cnx = null; try { cnx = openProxiedConnection(url); sendHeader(cnx); readHeader(cnx); InputStreamReader inputStreamReader = null; BufferedReader bufferedReader = null; try (InputStream inputStream = cnx.getInputStream()) { // If we fail to get the URL information we need to exit gracefully if (charset == null) { inputStreamReader = new InputStreamReader(inputStream, getCharset(cnx)); } else { inputStreamReader = new InputStreamReader(inputStream, charset); } bufferedReader = new BufferedReader(inputStreamReader); String line; while ((line = bufferedReader.readLine()) != null) { content.write(line); } // Attempt to force close connection // We have HTTP connections, so these are always valid content.flush(); } catch (FileNotFoundException ex) { LOG.error("URL not found: {}", url.toString()); } catch (IOException ex) { LOG.error("Error getting URL {}, {}", url.toString(), ex.getMessage()); } finally { // Close resources if (bufferedReader != null) { try { bufferedReader.close(); } catch (Exception ex) { /* ignore */ } } if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (Exception ex) { /* ignore */ } } } } catch (SocketTimeoutException ex) { LOG.error("Timeout Error with {}", url.toString()); } finally { if (cnx != null) { if (cnx instanceof HttpURLConnection) { ((HttpURLConnection) cnx).disconnect(); } } } return content.toString(); } finally { content.close(); ThreadExecutor.leaveIO(); } }
From source file:com.aliyun.oss.perftests.PerftestRunner.java
public void buildScenario(final String scenarioTypeString) { File confFile = new File(System.getProperty("user.dir") + File.separator + "runner_conf.xml"); InputStream input = null;//from w ww .j a va 2 s . c om try { input = new FileInputStream(confFile); } catch (FileNotFoundException e) { log.error(e); Assert.fail(e.getMessage()); } SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(input); Element root = doc.getRootElement(); scenario = new TestScenario(); scenario.setHost(root.getChildText("host")); scenario.setAccessId(root.getChildText("accessid")); scenario.setAccessKey(root.getChildText("accesskey")); scenario.setBucketName(root.getChildText("bucket")); scenario.setType(determineScenarioType(scenarioTypeString)); Element target = root.getChild(scenarioTypeString); if (target != null) { scenario.setContentLength(Long.parseLong(target.getChildText("size"))); scenario.setPutThreadNumber(Integer.parseInt(target.getChildText("putthread"))); scenario.setGetThreadNumber(Integer.parseInt(target.getChildText("getthread"))); scenario.setDurationInSeconds(Integer.parseInt(target.getChildText("time"))); scenario.setGetQPS(Integer.parseInt(target.getChildText("getqps"))); scenario.setPutQPS(Integer.parseInt(target.getChildText("putqps"))); } else { log.error("Unable to locate XML element " + scenarioTypeString); Assert.fail("Unable to locate XML element " + scenarioTypeString); } } catch (JDOMException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } catch (IOException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
From source file:datascript.instance.DataScriptInstanceTool.java
private AST parsePackage() throws Exception { String fileName = ToolContext.getFullName(); System.out.println("Parsing " + fileName); // set up lexer, parser and token buffer try {//from w w w.ja v a 2 s . c o m FileInputStream is = new FileInputStream(fileName); DataScriptLexer lexer = new DataScriptLexer(is); lexer.setFilename(fileName); 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(fileName); // 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.torchmind.stockpile.server.service.api.ProfileService.java
/** * Fetches a profile by proxying a join request. * * @param username a username.//w ww. j a va 2 s .c o m * @param serverId a serverId hash. * @return a profile. */ @Nonnull public Profile join(@Nonnull String username, @Nonnull String serverId) { try { return this.fetchProfile(new URL(String.format(JOIN_URL_TEMPLATE, username, serverId))); } catch (FileNotFoundException ex) { throw new NoSuchProfileException(username); } catch (TooManyRequestsException | IOException ex) { throw new ServiceException("Could not poll profile from session server: " + ex.getMessage(), ex); } }
From source file:com.clustercontrol.agent.log.LogfileMonitor.java
/** * ?//ww w . j av a 2 s . c om */ private boolean openFile() { m_log.info("openFile : filename=" + status.rsFilePath.getName()); closeFile(); FileChannel fc = null; // try { if (checkPrefix()) status.rotate(); fc = FileChannel.open(Paths.get(getFilePath()), StandardOpenOption.READ); long filesize = fc.size(); if (filesize > LogfileMonitorConfig.fileMaxSize) { // ???????? // message.log.agent.1={0}? // message.log.agent.3=?????? // message.log.agent.5={0} byte? String[] args1 = { getFilePath() }; String[] args2 = { String.valueOf(filesize) }; sendMessage(PriorityConstant.TYPE_INFO, MessageConstant.AGENT.getMessage(), MessageConstant.MESSAGE_LOG_FILE_SIZE_EXCEEDED_UPPER_BOUND.getMessage(), MessageConstant.MESSAGE_LOG_FILE.getMessage(args1) + ", " + MessageConstant.MESSAGE_LOG_FILE_SIZE_BYTE.getMessage(args2)); } // ?? // ?open?init=true?? // ??open?init=false??? fc.position(status.position); fileChannel = fc; return true; } catch (FileNotFoundException e) { m_log.info("openFile : " + e.getMessage()); if (m_initFlag) { // ???????? // message.log.agent.1={0}? // message.log.agent.2=??????? String[] args = { getFilePath() }; sendMessage(PriorityConstant.TYPE_INFO, MessageConstant.AGENT.getMessage(), MessageConstant.MESSAGE_LOG_FILE_NOT_FOUND.getMessage(), MessageConstant.MESSAGE_LOG_FILE.getMessage(args)); } return false; } catch (SecurityException e) { m_log.info("openFile : " + e.getMessage()); if (m_initFlag) { // ?? // message.log.agent.1={0}? // message.log.agent.4=???????? String[] args = { getFilePath() }; sendMessage(PriorityConstant.TYPE_WARNING, MessageConstant.AGENT.getMessage(), MessageConstant.MESSAGE_LOG_FAILED_TO_READ_FILE.getMessage(), MessageConstant.MESSAGE_LOG_FILE.getMessage(args) + "\n" + e.getMessage()); } return false; } catch (IOException e) { m_log.info("openFile : " + e.getMessage()); if (m_initFlag) { // ?? // message.log.agent.1={0}? // message.log.agent.4=???????? String[] args = { getFilePath() }; sendMessage(PriorityConstant.TYPE_INFO, MessageConstant.AGENT.getMessage(), MessageConstant.MESSAGE_LOG_FAILED_TO_READ_FILE.getMessage(), MessageConstant.MESSAGE_LOG_FILE.getMessage(args)); } return false; } finally { // ?????????????? if (fc != null && fileChannel == null) { try { fc.close(); } catch (IOException e) { m_log.warn(e.getMessage(), e); } } m_initFlag = false; } }