List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:fsi_admin.JAwsS3Conn.java
private boolean obtenInfoAWSS3(String IP, String host, String servidor, String basedatos, String usuario, String password, StringBuffer S3BUKT, StringBuffer S3USR, StringBuffer S3PASS, StringBuffer msj, MutableDouble COSTO, MutableDouble SALDO, MutableBoolean COBRAR) { JPACServidoresSet bd = new JPACServidoresSet(null); bd.ConCat(true);/*from w w w. j a va 2 s. c om*/ bd.m_Where = "ID_Servidor = '" + JUtil.p(servidor) + "' and Usuario = '" + JUtil.p(usuario) + "' and Pass = '" + JUtil.q(password) + "' and Status = 'A'"; bd.Open(); if (bd.getNumRows() == 0) // No existe registro de este servidor { msj.append( "ERROR: La autenticacin a este servidor ha fallado, verifica que tu clave de servidor, usuario y contrasea sean las correctas y vuelve a intentarlo"); return false; } else //Si existe el servidor, entonces da los datos para el SMTP { try { FileReader file = new FileReader("/usr/local/forseti/bin/.forseti_awss3"); BufferedReader buff = new BufferedReader(file); boolean eof = false; //masProp = new Properties(); while (!eof) { String line = buff.readLine(); System.out.println(line); if (line == null) { eof = true; } else { try { StringTokenizer st = new StringTokenizer(line, "="); String key = st.nextToken(); String value = st.nextToken(); if (key.equals("BUKT")) S3BUKT.append(value); else if (key.equals("PASS")) S3PASS.append(value); else if (key.equals("USER")) S3USR.append(value); } catch (NoSuchElementException e) { msj.append("ERROR: La informacion del servicio Amazon S3 parece estar mal configurada"); return false; } } } buff.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); msj.append("Error de archivos AWS S3: " + e1.getMessage()); return false; } catch (IOException e1) { e1.printStackTrace(); msj.append("Error de Entrada/Salida AWS S3: " + e1.getMessage()); return false; } JSrvServiciosBDSet srv = new JSrvServiciosBDSet(null); srv.ConCat(true); srv.m_Where = "ID_Servidor = '" + JUtil.p(servidor) + "' and Basedatos = '" + JUtil.p(basedatos) + "' and Status = 'A'"; srv.Open(); if (srv.getNumRows() == 0) // No existe registro de este servidor { msj.append( "ERROR: La autenticacin a este servidor es correcta, sin embargo, la base de datos a la que se intenta dar servicio est bloqueada o no se ha dado de alta an en este servidor"); return false; } else { //System.out.println("CostoS3MB: " + srv.getAbsRow(0).getCostoS3MB() + " Saldo: " + srv.getAbsRow(0).getSaldo() + " CobrarS3MB: " + srv.getAbsRow(0).getCobrarS3MB()); COSTO.setValue(srv.getAbsRow(0).getCostoS3MB()); SALDO.setValue(srv.getAbsRow(0).getSaldo()); COBRAR.setValue(srv.getAbsRow(0).getCobrarS3MB()); //System.out.println("Costo: " + COSTO + " Saldo: " + SALDO + " Cobrar: " + COBRAR); return true; } } }
From source file:com.ibm.bi.dml.parser.antlr4.DMLParserWrapper.java
/** * This function is supposed to be called directly only from DmlSyntacticValidator when it encounters 'import' * @param fileName//ww w . j a v a 2 s. c om * @return null if atleast one error */ public DMLProgram doParse(String fileName, String dmlScript, HashMap<String, String> argVals) throws ParseException { DMLProgram dmlPgm = null; org.antlr.v4.runtime.ANTLRInputStream in; try { if (dmlScript == null) { dmlScript = readDMLScript(fileName); } InputStream stream = new ByteArrayInputStream(dmlScript.getBytes()); in = new org.antlr.v4.runtime.ANTLRInputStream(stream); // else { // if(!(new File(fileName)).exists()) { // throw new ParseException("ERROR: Cannot open file:" + fileName); // } // in = new org.antlr.v4.runtime.ANTLRInputStream(new java.io.FileInputStream(fileName)); // } } catch (FileNotFoundException e) { throw new ParseException("ERROR: Cannot find file:" + fileName); } catch (IOException e) { throw new ParseException("ERROR: Cannot open file:" + fileName); } catch (LanguageException e) { throw new ParseException("ERROR: " + e.getMessage()); } DmlprogramContext ast = null; CustomDmlErrorListener errorListener = new CustomDmlErrorListener(); try { DmlLexer lexer = new DmlLexer(in); org.antlr.v4.runtime.CommonTokenStream tokens = new org.antlr.v4.runtime.CommonTokenStream(lexer); DmlParser antlr4Parser = new DmlParser(tokens); boolean tryOptimizedParsing = false; // For now no optimization, since it is not able to parse integer value. if (tryOptimizedParsing) { // Try faster and simpler SLL antlr4Parser.getInterpreter().setPredictionMode(PredictionMode.SLL); antlr4Parser.removeErrorListeners(); antlr4Parser.setErrorHandler(new BailErrorStrategy()); try { ast = antlr4Parser.dmlprogram(); // If successful, no need to try out full LL(*) ... SLL was enough } catch (ParseCancellationException ex) { // Error occurred, so now try full LL(*) for better error messages tokens.reset(); antlr4Parser.reset(); if (fileName != null) { errorListener.pushCurrentFileName(fileName); // DmlSyntacticErrorListener.currentFileName.push(fileName); } else { errorListener.pushCurrentFileName("MAIN_SCRIPT"); // DmlSyntacticErrorListener.currentFileName.push("MAIN_SCRIPT"); } // Set our custom error listener antlr4Parser.addErrorListener(errorListener); antlr4Parser.setErrorHandler(new DefaultErrorStrategy()); antlr4Parser.getInterpreter().setPredictionMode(PredictionMode.LL); ast = antlr4Parser.dmlprogram(); } } else { // Set our custom error listener antlr4Parser.removeErrorListeners(); antlr4Parser.addErrorListener(errorListener); errorListener.pushCurrentFileName(fileName); // Now do the parsing ast = antlr4Parser.dmlprogram(); } } catch (Exception e) { throw new ParseException("ERROR: Cannot parse the program:" + fileName); } try { // Now convert the parse tree into DMLProgram // Do syntactic validation while converting org.antlr.v4.runtime.tree.ParseTree tree = ast; // And also do syntactic validation org.antlr.v4.runtime.tree.ParseTreeWalker walker = new ParseTreeWalker(); DmlSyntacticValidatorHelper helper = new DmlSyntacticValidatorHelper(errorListener); DmlSyntacticValidator validator = new DmlSyntacticValidator(helper, errorListener.peekFileName(), argVals); walker.walk(validator, tree); errorListener.popFileName(); if (errorListener.isAtleastOneError()) { return null; } dmlPgm = createDMLProgram(ast); } catch (Exception e) { throw new ParseException("ERROR: Cannot translate the parse tree into DMLProgram:" + e.getMessage()); } return dmlPgm; }
From source file:fr.paris.lutece.portal.service.csv.CSVReaderService.java
/** * Read a CSV file and call the method/*from w w w . j a v a 2s .c om*/ * {@link #readLineOfCSVFile(String[], int, Locale, String) * readLineOfCSVFile} for * each of its lines. * @param strPath Path if the file to read in the file system. * @param nColumnNumber Number of columns of each lines. Use 0 to skip * column number check (for example if every lines don't have the * same number of columns) * @param bCheckFileBeforeProcessing Indicates if the file should be check * before processing any of its line. If it is set to true, then * then no line is processed if the file has any error. * @param bExitOnError Indicates if the processing of the CSV file should * end on the first error, or at the end of the file. * @param bSkipFirstLine Indicates if the first line of the file should be * skipped or not. * @param locale the locale * @param strBaseUrl The base URL * @return Returns the list of errors that occurred during the processing of * the file. The returned list is sorted * @see CSVMessageDescriptor#compareTo(CSVMessageDescriptor) * CSVMessageDescriptor.compareTo(CSVMessageDescriptor) for information * about sort */ public List<CSVMessageDescriptor> readCSVFile(String strPath, int nColumnNumber, boolean bCheckFileBeforeProcessing, boolean bExitOnError, boolean bSkipFirstLine, Locale locale, String strBaseUrl) { java.io.File file = new java.io.File(strPath); try { FileReader fileReader = new FileReader(file); CSVReader csvReader = new CSVReader(fileReader, getCSVSeparator(), getCSVEscapeCharacter()); return readCSVFile(fileReader, csvReader, nColumnNumber, bCheckFileBeforeProcessing, bExitOnError, bSkipFirstLine, locale, strBaseUrl); } catch (FileNotFoundException e) { AppLogService.error(e.getMessage(), e); } List<CSVMessageDescriptor> listErrors = new ArrayList<CSVMessageDescriptor>(); CSVMessageDescriptor errorDescription = new CSVMessageDescriptor(CSVMessageLevel.ERROR, 0, I18nService.getLocalizedString(MESSAGE_NO_FILE_FOUND, locale)); listErrors.add(errorDescription); return listErrors; }
From source file:edu.hawaii.soest.kilonalu.dvp2.DavisWxXMLSink.java
/** * Export data to disk.//ww w .ja v a2 s. c o m */ public boolean export() { logger.debug("DavisWxXMLSink.export() called."); if (setup(this.getServerName(), this.getServerPort(), this.getRBNBClientName())) { try { ChannelMap requestMap = new ChannelMap(); String fullSourceName = "/KNHIGCampusDataTurbine" + "/" + this.getRBNBClientName() + "/"; int channelIndex = 0; // add the barTrendAsString field data channelIndex = requestMap.Add(fullSourceName + "barTrendAsString"); // Falling Slowly // add the barometer field data channelIndex = requestMap.Add(fullSourceName + "barometer"); // 29.9 // add the insideTemperature field data channelIndex = requestMap.Add(fullSourceName + "insideTemperature"); // 83.9 // add the insideHumidity field data channelIndex = requestMap.Add(fullSourceName + "insideHumidity"); // 51 // add the outsideTemperature field data channelIndex = requestMap.Add(fullSourceName + "outsideTemperature"); // 76.7 // add the windSpeed field data channelIndex = requestMap.Add(fullSourceName + "windSpeed"); // 5 // add the tenMinuteAverageWindSpeed field data channelIndex = requestMap.Add(fullSourceName + "tenMinuteAverageWindSpeed"); // 4 // add the windDirection field data channelIndex = requestMap.Add(fullSourceName + "windDirection"); // 80 // add the outsideHumidity field data channelIndex = requestMap.Add(fullSourceName + "outsideHumidity"); // 73 // add the rainRate field data channelIndex = requestMap.Add(fullSourceName + "rainRate"); // 0.0 // add the uvRadiation field data channelIndex = requestMap.Add(fullSourceName + "uvRadiation"); // 0 // add the solarRadiation field data channelIndex = requestMap.Add(fullSourceName + "solarRadiation"); // 0.0 // add the dailyRain field data channelIndex = requestMap.Add(fullSourceName + "dailyRain"); // 0.0 // add the monthlyRain field data channelIndex = requestMap.Add(fullSourceName + "monthlyRain"); // 0.0 // add the forecastAsString field data channelIndex = requestMap.Add(fullSourceName + "forecastAsString"); // Partially Cloudy // make the request to the DataTurbine for the above channels sink.Request(requestMap, 0.0, 0.0, "newest"); ChannelMap responseMap = sink.Fetch(3000); // fetch with 5 sec timeout // then parse the results to and build the XML output int index = responseMap.GetIndex(fullSourceName + "barTrendAsString"); if (index >= 0) { // convert sec to millisec double timestamp = responseMap.GetTimes(index)[0]; long unixTime = (long) (timestamp * 1000.0); // get the updateDate Date updateDate = new Date(unixTime); String updateDateString = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG) .format(updateDate); // create the ad hoc XML file from the data from the DataTurbine this.fileOutputStream = new FileOutputStream(xmlFile); StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append("<wx>\n"); sb.append(" <updatetime>" + updateDateString + "</updatetime>\n"); sb.append(" <barotrend>" + responseMap .GetDataAsString(responseMap.GetIndex(fullSourceName + "barTrendAsString"))[0] + "</barotrend>\n"); sb.append(" <baropress>" + String.format("%5.3f", (Object) (new Float(responseMap.GetDataAsFloat32( responseMap.GetIndex(fullSourceName + "barometer"))[0]))) + "</baropress>\n"); sb.append( " <outtemp>" + String.format("%4.1f", (Object) (new Float(responseMap.GetDataAsFloat32(responseMap .GetIndex(fullSourceName + "outsideTemperature"))[0]))) + "</outtemp>\n"); sb.append( " <intemp>" + String.format("%4.1f", (Object) (new Float(responseMap.GetDataAsFloat32(responseMap .GetIndex(fullSourceName + "insideTemperature"))[0]))) + "</intemp>\n"); sb.append(" <inrelhum>" + String.format("%3d", (Object) (new Integer(responseMap.GetDataAsInt32( responseMap.GetIndex(fullSourceName + "insideHumidity"))[0]))) + "</inrelhum>\n"); sb.append(" <outrelhum>" + String.format("%3d", (Object) (new Integer(responseMap.GetDataAsInt32( responseMap.GetIndex(fullSourceName + "outsideHumidity"))[0]))) + "</outrelhum>\n"); sb.append(" <windspd>" + String.format("%3d", (Object) (new Integer(responseMap.GetDataAsInt32( responseMap.GetIndex(fullSourceName + "windSpeed"))[0]))) + "</windspd>\n"); sb.append(" <winddir>" + String.format("%3d", (Object) (new Integer(responseMap.GetDataAsInt32( responseMap.GetIndex(fullSourceName + "windDirection"))[0]))) + "</winddir>\n"); sb.append(" <windavg>" + String.format("%3d", (Object) (new Integer(responseMap.GetDataAsInt32(responseMap .GetIndex(fullSourceName + "tenMinuteAverageWindSpeed"))[0]))) + "</windavg>\n"); sb.append(" <todayrain>" + String.format("%4.2f", (Object) (new Float(responseMap.GetDataAsFloat32( responseMap.GetIndex(fullSourceName + "dailyRain"))[0]))) + "</todayrain>\n"); sb.append(" <monthrain>" + String.format("%4.2f", (Object) (new Float(responseMap.GetDataAsFloat32( responseMap.GetIndex(fullSourceName + "monthlyRain"))[0]))) + "</monthrain>\n"); sb.append(" <rainrate>" + String.format("%4.2f", (Object) (new Float(responseMap.GetDataAsFloat32( responseMap.GetIndex(fullSourceName + "rainRate"))[0]))) + "</rainrate>\n"); sb.append(" <uv>" + String.format("%4d", (Object) (new Integer(responseMap.GetDataAsInt32( responseMap.GetIndex(fullSourceName + "uvRadiation"))[0]))) + "</uv>\n"); sb.append(" <solrad>" + String.format("%4.0f", (Object) (new Float(responseMap.GetDataAsFloat32( responseMap.GetIndex(fullSourceName + "solarRadiation"))[0]))) + "</solrad>\n"); sb.append(" <forecast>" + responseMap .GetDataAsString(responseMap.GetIndex(fullSourceName + "forecastAsString"))[0] + "</forecast>\n"); sb.append("</wx>\n"); logger.info("\n" + sb.toString()); this.fileOutputStream.write(sb.toString().getBytes()); this.fileOutputStream.close(); } else { logger.debug("The index is out of bounds: " + index); } } catch (java.io.FileNotFoundException fnfe) { logger.debug("Error: Unable to open XML output file for writing."); logger.debug("Error message: " + fnfe.getMessage()); disconnect(); return false; } catch (java.io.IOException ioe) { logger.debug("Error: There was a problem writing to the XML file."); logger.debug("Error message: " + ioe.getMessage()); disconnect(); return false; } catch (com.rbnb.sapi.SAPIException sapie) { logger.debug("Error: There was a problem with the DataTurbine connection."); logger.debug("Error message: " + sapie.getMessage()); disconnect(); return false; } return true; } else { return false; } }
From source file:egat.cli.neresponse.NEResponseCommandHandler.java
protected void processSymmetricGame(MutableSymmetricGame game) throws CommandProcessingException { InputStream inputStream = null; try {// ww w . jav a 2 s . c o m inputStream = new FileInputStream(profilePath); } catch (FileNotFoundException e) { throw new CommandProcessingException(e); } try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); StrategyHandler handler = new StrategyHandler(); parser.parse(inputStream, handler); Strategy strategy = handler.getStrategy(); findNEResponse(strategy, game); } catch (NonexistentPayoffException e) { System.err.println(String.format("Could not calculate regret. %s", e.getMessage())); } catch (ParserConfigurationException e) { throw new CommandProcessingException(e); } catch (SAXException e) { throw new CommandProcessingException(e); } catch (IOException e) { throw new CommandProcessingException(e); } }
From source file:com.symbian.utils.config.ConfigUtils.java
/** * Save the Configuration settings to files. * /*w w w . j a v a2s .co m*/ * @param aPrefFile * The Java Preference file to export/save. * * @throws IOException * If the saving doesn't work. */ public void exportConfig(final File aPrefFile) throws IOException { try { iPrefrences.exportNode(new FileOutputStream(aPrefFile)); } catch (FileNotFoundException lFileNotFoundException) { throw new IOException("Cannot create new properties file: " + aPrefFile.getPath() + ": " + lFileNotFoundException.getMessage()); } catch (IOException lIOException) { throw new IOException( "Properties file I/O error: " + aPrefFile.getPath() + ": " + lIOException.getMessage()); } catch (BackingStoreException lBackingStoreException) { throw new IOException( "Backing Store error: " + aPrefFile.getPath() + ": " + lBackingStoreException.getMessage()); } }
From source file:com.symbian.utils.config.ConfigUtils.java
/** * load the Configuration settings from files. * /*from w w w.j a v a2s .c om*/ * @param aPrefFile * The Java Preference file to import/load. * * @throws IOException * If the load doesn't work. */ public void importConfig(final File aPrefFile) throws IOException { try { Preferences.importPreferences(new FileInputStream(aPrefFile)); iPrefrences = Preferences.userRoot().node(iNodeName); } catch (FileNotFoundException lFileNotFoundException) { throw new IOException("Cannot create new properties file: " + aPrefFile.getPath() + ": " + lFileNotFoundException.getMessage()); } catch (IOException lIOException) { throw new IOException( "Properties file I/O error: " + aPrefFile.getPath() + ", " + lIOException.getMessage()); } catch (InvalidPreferencesFormatException lIPFE) { throw new IOException( "Prefrences files are not valid: " + aPrefFile.getPath() + ", " + lIPFE.getMessage()); } }
From source file:edu.uoc.pelp.engine.aem.BasicCodeAnalyzer.java
@Override public TestResult test(TestData test) { StringBuffer exeOutput = new StringBuffer(); // Perform the execution Long startTime = new Long(System.currentTimeMillis()); int retVal;// w ww .j a v a 2 s.c o m try { retVal = execute(test.getInputStream(), exeOutput, test.getMaxTime()); } catch (FileNotFoundException ex) { retVal = -1; exeOutput.append("\nTEST ERROR:\n"); exeOutput.append(ex.getMessage()); } catch (AEMPelpException ex) { retVal = -1; exeOutput.append("\nERROR:\n"); exeOutput.append(ex.getMessage()); } Long endTime = new Long(System.currentTimeMillis()); // Store the results, preserving activity information TestResult result; if (test instanceof ActivityTest) { ActivityTestResult newResult = new ActivityTestResult(); ActivityTest actTest = (ActivityTest) test; newResult.setTestID(actTest.getID()); result = newResult; } else { result = new TestResult(); } result.setElapsedTime(endTime - startTime); // Compare the output and exepcted output if (retVal < 0) { result.setResult(false, "ERROR: Timeout or execution error"); } else { boolean sameOutput; try { sameOutput = test.checkResult(exeOutput.toString()); } catch (FileNotFoundException ex) { sameOutput = false; } result.setResult(sameOutput, exeOutput.toString()); } return result; }
From source file:com.ikon.util.DocConverter.java
/** * TIFF to PDF conversion/*ww w. j ava 2s . co m*/ */ public void tiff2pdf(File input, File output) throws ConversionException { RandomAccessFileOrArray ra = null; Document doc = null; try { // Open PDF doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(output)); PdfContentByte cb = writer.getDirectContent(); doc.open(); //int pages = 0; // Open TIFF ra = new RandomAccessFileOrArray(input.getPath()); int comps = TiffImage.getNumberOfPages(ra); for (int c = 0; c < comps; ++c) { Image img = TiffImage.getTiffImage(ra, c + 1); if (img != null) { log.debug("tiff2pdf - page {}", c + 1); if (img.getScaledWidth() > 500 || img.getScaledHeight() > 700) { img.scaleToFit(500, 700); } img.setAbsolutePosition(20, 20); //doc.add(new Paragraph("page " + (c + 1))); cb.addImage(img); doc.newPage(); //++pages; } } } catch (FileNotFoundException e) { throw new ConversionException("File not found: " + e.getMessage(), e); } catch (DocumentException e) { throw new ConversionException("Document exception: " + e.getMessage(), e); } catch (IOException e) { throw new ConversionException("IO exception: " + e.getMessage(), e); } finally { if (ra != null) { try { ra.close(); } catch (IOException e) { // Ignore } } if (doc != null) { doc.close(); } } }