List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:org.wso2.carbon.integration.test.client.HttpEventPublisherClient.java
/** * Messages will be read from the given filepath and an ArrayList will be returned (messagesList) * * @param filePath Text file to be read// ww w . jav a 2 s . c o m */ private static List<String> readMsg(String filePath) { List<String> messagesList = new ArrayList<String>(); BufferedReader bufferedReader = null; StringBuffer message = new StringBuffer(""); final String asterixLine = "*****"; try { String line; bufferedReader = new BufferedReader(new FileReader(filePath)); while ((line = bufferedReader.readLine()) != null) { if ((line.equals(asterixLine.trim()) && !"".equals(message.toString().trim()))) { messagesList.add(message.toString()); message = new StringBuffer(""); } else { message = message.append(String.format("\n%s", line)); } } if (!"".equals(message.toString().trim())) { messagesList.add(message.toString()); } } catch (FileNotFoundException e) { log.error("Error in reading file " + filePath, e); } catch (IOException e) { log.error("Error in reading file " + filePath, e); } finally { try { if (bufferedReader != null) { bufferedReader.close(); } } catch (IOException e) { log.error("Error occurred when closing the file : " + e.getMessage(), e); } } return messagesList; }
From source file:de.xirp.chart.ChartUtil.java
/** * Returns a {@link org.jfree.data.category.CategoryDataset} * generated from a CSV {@link java.io.File}. * /*w ww . ja v a 2 s .c o m*/ * @param csvFile * The file to read the values from. * @return A <code>CategoryDataset</code> generated from a csv * file. * @see org.jfree.data.category.CategoryDataset */ public static CategoryDataset getCategoryDatasetFromCSV(File csvFile) { CSV csv = new CSV(',', '"'); CategoryDataset dataset = null; try { FileReader fr = new FileReader(csvFile); dataset = csv.readCategoryDataset(fr); } catch (FileNotFoundException e) { logClass.error("Error: " + e.getMessage() //$NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } catch (IOException e) { logClass.error("Error: " + e.getMessage() //$NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } return dataset; }
From source file:com.cisco.dvbu.ps.common.scriptutil.ScriptUtil.java
/** * Create a command file for UNIX or Windows from name value pairs strings constructed based on passed in xml content * @param xmlFilePath xml File Path//from w ww . ja v a2 s .co m * @param nodeName String return name values for passed in node name and node value. * is treated as all nodes * @param nodeValue String return name values for passed in node name and node value. * is treated as all node values * @param options additional options to return the node name or attributes such as "-noid -noattributes" * @param commandOutputFile The fully qualifed path of the command output file * @param commandHeader The command file header such as #!/bin/bash * @param commandType The type of command file [UNIX|WINDOWS] {use export for UNIX, use set for WINDOWS) * UNIX: export name="value" * WINDOWS: set name=value * usage createCommandFileFromXML xmlFilePath * * "-noid -noattributes" /Users/rthummal/mywork/clients/ps/CisDeployTool/resources/abc.sh #!/bin/bash UNIX * usage createCommandFileFromXML xmlFilePath hostname localhost "" C:\opt\pdtool/abc.bat "echo off" WINDOWS * usage createCommandFileFromXML xmlFilePath hostname * "-noid" /opt/pdtool/abc.sh #!/bin/bash UNIX */ public static void createCommandFileFromXML(String xmlFilePath, String nodeName, String nodeValue, String options, String commandOutputFile, String commandHeader, String commandType) { boolean win = false; String cmdPrefix = "export "; if (commandType != null && commandType.equals("WINDOWS")) { win = true; cmdPrefix = "set "; } String nameValuePairs = XMLUtils.getNameValuePairsFromXML(xmlFilePath, null, null, nodeName, nodeValue, options); if (nameValuePairs != null) { StringBuffer sb = new StringBuffer(); sb.append(commandHeader + "\n"); StringTokenizer st = new StringTokenizer(nameValuePairs, "|"); while (st.hasMoreTokens()) { sb.append(cmdPrefix); String nameValuePair = st.nextToken(); if (!win) { nameValuePair = nameValuePair.replace("=", "=\""); nameValuePair += "\""; } sb.append(nameValuePair + "\n"); } try { Writer out = new OutputStreamWriter(new FileOutputStream(commandOutputFile)); out.write(sb.toString()); out.flush(); } catch (FileNotFoundException e) { logger.error("Could not wirte to command file " + commandOutputFile, e); throw new ValidationException(e.getMessage(), e); } catch (IOException e) { logger.error("Could not wirte to command file " + commandOutputFile, e); throw new ValidationException(e.getMessage(), e); } } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setTrayIconDisplay(boolean display) { sDisplaySystemTray = display;// w ww . ja va 2 s. c om Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java
/** * Get the workbook and returns its sheets * @param excelMappingsDirectory//from w w w . j a v a 2s. co m * @param fileName * @return Map<SheetID, SheetName> */ static Workbook loadWorkbook(String excelMappingsDirectory, String fileName) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(new File(excelMappingsDirectory, fileName)); } catch (FileNotFoundException e) { LOGGER.warn("Loading the workbook from directory " + excelMappingsDirectory + " and file " + fileName + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } try { if (fileName.endsWith("xls") || fileName.endsWith("XLS")) { return new HSSFWorkbook(inputStream); } else { if (fileName.endsWith("xlsx") || fileName.endsWith("XLSX")) { return new XSSFWorkbook(inputStream); } } } catch (IOException e) { LOGGER.warn("Getting the excel sheets failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setDebugging(boolean debugging) { if (sDebugging) writeLog("debugging stopped"); sDebugging = debugging;/*from w w w . ja va 2 s . c om*/ if (sDebugging) writeLog("debugging started"); Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } }
From source file:com.cisco.dvbu.ps.common.util.PropertyManager.java
private static void repairPropertyFile(String file) throws CompositeException { StringBuilder stringBuilder = null; boolean repairSetNeeded = false; boolean repairExportNeeded = false; try {/* w ww . ja v a 2 s . c o m*/ BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { if (!line.trim().startsWith("#")) { if (line.trim().toLowerCase().startsWith("set ")) { line = line.replace("set ", "").trim(); repairSetNeeded = true; } if (line.trim().toLowerCase().startsWith("export ")) { line = line.replace("export ", "").trim(); repairExportNeeded = true; } } stringBuilder.append(line); stringBuilder.append(ls); } if (stringBuilder != null && (repairSetNeeded || repairExportNeeded)) { // close the original file reader.close(); // write out the repaired file StringBuilder repairStringBuilder = new StringBuilder(); ; String dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"; repairStringBuilder .append("# PDTool repaired file (" + CommonUtils.getCurrentDateAsString(dateFormat) + "):"); if (repairSetNeeded) repairStringBuilder.append(" [Removed \"set \"]"); if (repairExportNeeded) repairStringBuilder.append(" [Removed \"export \"]"); repairStringBuilder.append(ls); CommonUtils.createFileWithContent(file, repairStringBuilder.toString()); CommonUtils.appendContentToFile(file, stringBuilder.toString()); } } catch (FileNotFoundException e) { throw new CompositeException(e.getMessage(), e); } catch (IOException e) { throw new CompositeException(e.getMessage(), e); } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
protected static void setPassphrase(String passphrase) { Properties prop = new Properties(); try {/*from ww w . j a v a 2 s . com*/ prop.load(new FileInputStream(sProperties)); prop.setProperty(sPassphraseKey, passphrase); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (OS == OS_WIN) { KeyStore ks = getKeyStore(); if (ks != null) { SecretKey sk = getSecretKey(ks); if (ks != null) { try { ks.setKeyEntry(TAP_LOCK, sk, sPassphrase.toCharArray(), null); ks.store(new FileOutputStream(sKeystore), sPassphrase.toCharArray()); } catch (KeyStoreException e) { writeLog("change key password: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { writeLog("change key password: " + e.getMessage()); } catch (CertificateException e) { writeLog("change key password: " + e.getMessage()); } catch (FileNotFoundException e) { writeLog("change key password: " + e.getMessage()); } catch (IOException e) { writeLog("change key password: " + e.getMessage()); } } } } sPassphrase = passphrase; }
From source file:com.iStudy.Study.Renren.Util.java
/** * ??/*from w w w. j av a 2 s . com*/ * * @param file * @return * @throws IOException */ public static byte[] fileToByteArray(File file) { try { return streamToByteArray(new FileInputStream(file)); } catch (FileNotFoundException e) { logger(e.getMessage()); return null; } }
From source file:ee.ria.xroad.asyncdb.AsyncDBIntegrationTest.java
private static void validateSavedMessage(int requestNo, List<String> itemsToBeContained) throws Exception { try {//ww w. j av a 2 s. c om String filePath = getMessageDetailsFilePath(requestNo, MessageQueue.MESSAGE_FILE_NAME); LOG.debug("Inspecting SOAP message on file path: '{}'", filePath); String fileContent = FileUtils.readFileToString(new File(filePath), StandardCharsets.UTF_8); LOG.debug("File content is: '{}'", fileContent); for (String item : itemsToBeContained) { if (!StringUtils.contains(fileContent, item)) { throw new IntegrationTestFailedException( "Saved message does not contain expected item '" + item + "'."); } } } catch (FileNotFoundException e) { throw new IntegrationTestFailedException(e.getMessage()); } }