List of usage examples for java.io FileNotFoundException getLocalizedMessage
public String getLocalizedMessage()
From source file:fr.cs.examples.conversion.PropagatorConversion.java
/** Program entry point. * @param args program arguments (unused here) *//*from w w w . j av a 2s.c om*/ public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // gravity field NormalizedSphericalHarmonicsProvider provider = GravityFieldFactory.getNormalizedProvider(2, 0); double mu = provider.getMu(); // inertial frame Frame inertialFrame = FramesFactory.getEME2000(); // Initial date AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 01, 23, 30, 00.000, TimeScalesFactory.getUTC()); // Initial orbit (GTO) final double a = 24396159; // semi major axis in meters final double e = 0.72831215; // eccentricity final double i = FastMath.toRadians(7); // inclination final double omega = FastMath.toRadians(180); // perigee argument final double raan = FastMath.toRadians(261); // right ascention of ascending node final double lM = 0; // mean anomaly Orbit initialOrbit = new KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu); final double period = initialOrbit.getKeplerianPeriod(); // Initial state definition final SpacecraftState initialState = new SpacecraftState(initialOrbit); // Adaptive step integrator with a minimum step of 0.001 and a maximum step of 1000 final double minStep = 0.001; final double maxStep = 1000.; final double dP = 1.e-2; final OrbitType orbType = OrbitType.CARTESIAN; final double[][] tol = NumericalPropagator.tolerances(dP, initialOrbit, orbType); final AbstractIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]); // Propagator NumericalPropagator numProp = new NumericalPropagator(integrator); numProp.setInitialState(initialState); numProp.setOrbitType(orbType); // Force Models: // 1 - Perturbing gravity field (only J2 is considered here) ForceModel gravity = new HolmesFeatherstoneAttractionModel( FramesFactory.getITRF(IERSConventions.IERS_2010, true), provider); // Add force models to the propagator numProp.addForceModel(gravity); // Propagator factory PropagatorBuilder builder = new KeplerianPropagatorBuilder(mu, inertialFrame, OrbitType.KEPLERIAN, PositionAngle.TRUE); // Propagator converter PropagatorConverter fitter = new FiniteDifferencePropagatorConverter(builder, 1.e-6, 5000); // Resulting propagator KeplerianPropagator kepProp = (KeplerianPropagator) fitter.convert(numProp, 2 * period, 251); // Step handlers StatesHandler numStepHandler = new StatesHandler(); StatesHandler kepStepHandler = new StatesHandler(); // Set up operating mode for the propagator as master mode // with fixed step and specialized step handler numProp.setMasterMode(60., numStepHandler); kepProp.setMasterMode(60., kepStepHandler); // Extrapolate from the initial to the final date numProp.propagate(initialDate.shiftedBy(10. * period)); kepProp.propagate(initialDate.shiftedBy(10. * period)); // retrieve the states List<SpacecraftState> numStates = numStepHandler.getStates(); List<SpacecraftState> kepStates = kepStepHandler.getStates(); // Print the results on the output file File output = new File(new File(System.getProperty("user.home")), "elements.dat"); PrintStream stream = new PrintStream(output); stream.println("# date Anum Akep Enum Ekep Inum Ikep LMnum LMkep"); for (SpacecraftState numState : numStates) { for (SpacecraftState kepState : kepStates) { if (numState.getDate().compareTo(kepState.getDate()) == 0) { stream.println(numState.getDate() + " " + numState.getA() + " " + kepState.getA() + " " + numState.getE() + " " + kepState.getE() + " " + FastMath.toDegrees(numState.getI()) + " " + FastMath.toDegrees(kepState.getI()) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(numState.getLM(), FastMath.PI)) + " " + FastMath.toDegrees(MathUtils.normalizeAngle(kepState.getLM(), FastMath.PI))); break; } } } stream.close(); System.out.println("Results saved as file " + output); File output1 = new File(new File(System.getProperty("user.home")), "elts_pv.dat"); PrintStream stream1 = new PrintStream(output1); stream.println("# date pxn pyn pzn vxn vyn vzn pxk pyk pzk vxk vyk vzk"); for (SpacecraftState numState : numStates) { for (SpacecraftState kepState : kepStates) { if (numState.getDate().compareTo(kepState.getDate()) == 0) { final double pxn = numState.getPVCoordinates().getPosition().getX(); final double pyn = numState.getPVCoordinates().getPosition().getY(); final double pzn = numState.getPVCoordinates().getPosition().getZ(); final double vxn = numState.getPVCoordinates().getVelocity().getX(); final double vyn = numState.getPVCoordinates().getVelocity().getY(); final double vzn = numState.getPVCoordinates().getVelocity().getZ(); final double pxk = kepState.getPVCoordinates().getPosition().getX(); final double pyk = kepState.getPVCoordinates().getPosition().getY(); final double pzk = kepState.getPVCoordinates().getPosition().getZ(); final double vxk = kepState.getPVCoordinates().getVelocity().getX(); final double vyk = kepState.getPVCoordinates().getVelocity().getY(); final double vzk = kepState.getPVCoordinates().getVelocity().getZ(); stream1.println(numState.getDate() + " " + pxn + " " + pyn + " " + pzn + " " + vxn + " " + vyn + " " + vzn + " " + pxk + " " + pyk + " " + pzk + " " + vxk + " " + vyk + " " + vzk); break; } } } stream1.close(); System.out.println("Results saved as file " + output1); } catch (OrekitException oe) { System.err.println(oe.getLocalizedMessage()); System.exit(1); } catch (FileNotFoundException fnfe) { System.err.println(fnfe.getLocalizedMessage()); System.exit(1); } }
From source file:opendap.metacat.URLClassifier.java
public static void main(String args[]) { URLClassifier classifier;//w w w. j a va2 s . c o m CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("v", "verbose", false, "Be verbose"); options.addOption("h", "help", false, "Usage information"); options.addOption("c", "cache-name", true, "Cache name prefixes; read DDX URLs from cache files with this name prefix."); options.addOption("r", "read-only", false, "Just read an already-writen URLGroups file and print its contents."); options.addOption("o", "output", true, "Write files using this name as the prefix."); boolean verbose; String cacheName; String output; try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("url_classifier [options] --cache-name <name prefix>", options); return; } verbose = line.hasOption("verbose"); cacheName = line.getOptionValue("cache-name"); output = line.getOptionValue("output"); if (cacheName == null || cacheName.isEmpty()) throw new Exception("--cache-name must be given"); if (output == null || output.isEmpty()) output = cacheName; boolean readOnly = line.hasOption("read-only"); if (readOnly) verbose = true; classifier = new URLClassifier(cacheName, readOnly); PrintStream ps = null; if (verbose) { ps = new PrintStream("classifier_" + output + ".txt"); ps.println("Classification for: " + output); ps.println("Starting classification: " + (new Date()).toString()); } if (!readOnly) classifier.classifyURLs(ps); if (ps != null) { classifier.printClassifications(ps); classifier.printCompleteClassifications(ps); } if (!readOnly) classifier.groups.saveState(output); } catch (FileNotFoundException e) { System.err.println("File error: " + e.getLocalizedMessage()); e.printStackTrace(); return; } catch (Exception e) { System.err.println("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } }
From source file:Main.java
public static void copyfile(File source, File dest) { try {/*ww w .ja v a 2 s .co m*/ InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(dest); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, e.getLocalizedMessage()); } }
From source file:com.cloud.usage.UsageServer.java
static private void initLog4j() { File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); if (file != null) { System.out.println("log4j configuration found at " + file.getAbsolutePath()); try {/*from w ww . j a v a 2 s. c o m*/ Log4jConfigurer.initLogging(file.getAbsolutePath()); } catch (FileNotFoundException e) { s_logger.info("[ignored] log initialisation ;)" + e.getLocalizedMessage(), e); } DOMConfigurator.configureAndWatch(file.getAbsolutePath()); } else { file = PropertiesUtil.findConfigFile("log4j-cloud.properties"); if (file != null) { System.out.println("log4j configuration found at " + file.getAbsolutePath()); try { Log4jConfigurer.initLogging(file.getAbsolutePath()); } catch (FileNotFoundException e) { s_logger.info("[ignored] log properties initialization :)" + e.getLocalizedMessage(), e); } PropertyConfigurator.configureAndWatch(file.getAbsolutePath()); } } }
From source file:org.springframework.data.hadoop.pig.PigUtils.java
private static void registerScriptForPig07X(PigServer pig, InputStream in, Map<String, String> params) throws IOException { try {//from w w w. j a va 2 s .c o m // transform the map type to list type which can been accepted by ParameterSubstitutionPreprocessor List<String> paramList = new ArrayList<String>(); if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { paramList.add(entry.getKey() + "=" + entry.getValue()); } } // do parameter substitution ParameterSubstitutionPreprocessor psp = new ParameterSubstitutionPreprocessor(50); StringWriter writer = new StringWriter(); psp.genSubstitutedFile(new BufferedReader(new InputStreamReader(in)), writer, null, null); GruntParser grunt = new GruntParser(new StringReader(writer.toString())); grunt.setInteractive(false); grunt.setParams(pig); grunt.parseStopOnError(true); } catch (FileNotFoundException e) { LogFactory.getLog(PigServer.class).error(e.getLocalizedMessage()); throw new IOException(e.getCause()); } catch (org.apache.pig.tools.pigscript.parser.ParseException e) { LogFactory.getLog(PigServer.class).error(e.getLocalizedMessage()); throw new IOException(e.getCause()); } catch (org.apache.pig.tools.parameters.ParseException e) { LogFactory.getLog(PigServer.class).error(e.getLocalizedMessage()); throw new IOException(e.getCause()); } }
From source file:org.totschnig.myexpenses.Utils.java
static boolean copy(File src, File dst) { FileChannel srcC;//ww w .jav a 2 s.c o m try { srcC = new FileInputStream(src).getChannel(); FileChannel dstC = new FileOutputStream(dst).getChannel(); dstC.transferFrom(srcC, 0, srcC.size()); srcC.close(); dstC.close(); return true; } catch (FileNotFoundException e) { Log.e("MyExpenses", e.getLocalizedMessage()); } catch (IOException e) { Log.e("MyExpenses", e.getLocalizedMessage()); } return false; }
From source file:org.mrgeo.data.accumulo.utils.AccumuloConnector.java
public static Connector getConnector(File f) throws DataProviderException { Properties p = new Properties(); try {// w w w . j av a 2 s. co m p.load(new FileInputStream(f)); } catch (FileNotFoundException fnfe) { throw new DataProviderException(fnfe.getLocalizedMessage()); } catch (Exception e) { throw new DataProviderException( "problem loading connector for file " + f.getAbsolutePath() + " - " + e.getMessage()); } return getConnector(p); }
From source file:com.nextgis.mobile.map.RemoteTMSLayer.java
protected static void create(final MapBase map, String layerName, String layerUrl, int tmsType) { String sErr = map.getContext().getString(R.string.error_occurred); try {//from ww w . ja v a 2 s . c o m File outputPath = map.cretateLayerStorage(); //create layer description file JSONObject oJSONRoot = new JSONObject(); oJSONRoot.put(JSON_NAME_KEY, layerName); oJSONRoot.put(JSON_URL_KEY, layerUrl); oJSONRoot.put(JSON_VISIBILITY_KEY, true); oJSONRoot.put(JSON_TYPE_KEY, LAYERTYPE_TMS); oJSONRoot.put(JSON_TMSTYPE_KEY, tmsType); //send message to handler to show error or add new layer File file = new File(outputPath, LAYER_CONFIG); FileUtil.createDir(outputPath); FileUtil.writeToFile(file, oJSONRoot.toString()); if (map.getMapEventsHandler() != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_HASERROR_KEY, false); bundle.putString(BUNDLE_MSG_KEY, map.getContext().getString(R.string.message_layer_added)); bundle.putInt(BUNDLE_TYPE_KEY, MSGTYPE_LAYER_ADDED); bundle.putSerializable(BUNDLE_PATH_KEY, outputPath); Message msg = new Message(); msg.setData(bundle); map.getMapEventsHandler().sendMessage(msg); } return; } catch (FileNotFoundException e) { Log.d(TAG, "Exception: " + e.getLocalizedMessage()); sErr += ": " + e.getLocalizedMessage(); } catch (JSONException e) { Log.d(TAG, "Exception: " + e.getLocalizedMessage()); sErr += ": " + e.getLocalizedMessage(); } catch (IOException e) { Log.d(TAG, "Exception: " + e.getLocalizedMessage()); sErr += ": " + e.getLocalizedMessage(); } //if we here something wrong occurred Toast.makeText(map.getContext(), sErr, Toast.LENGTH_SHORT).show(); }
From source file:org.apache.jorphan.test.AllTests.java
/** * An overridable method that initializes the logging for the unit test run, * using the properties file passed in as the second argument. * /*from w w w . ja v a 2 s. co m*/ * @param args */ protected static void initializeLogging(String[] args) { if (args.length >= 2) { Properties props = new Properties(); InputStream inputStream = null; try { System.out.println("Setting up logging props using file: " + args[1]); inputStream = new FileInputStream(args[1]); props.load(inputStream); LoggingManager.initializeLogging(props); } catch (FileNotFoundException e) { System.out.println(e.getLocalizedMessage()); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); } finally { JOrphanUtils.closeQuietly(inputStream); } } }
From source file:models.utils.FileIoUtils.java
/** * 20130927 Fixed Memory Leak. Dont use line by line, just use apache * commons io!! so simple and easy!//from w ww . j a v a 2 s.co m * * @param filePath * @return */ public static String readFileToString(String filePath) { String fileContentString = null; try { VirtualFile vf = VirtualFile.fromRelativePath(filePath); File realFile = vf.getRealFile(); fileContentString = FileUtils.readFileToString(realFile); models.utils.LogUtils.printLogNormal("Completed read file with file size: " + fileContentString.toString().length() / VarUtils.CONVERSION_1024 + " KB. Path: " + filePath + " at " + DateUtils.getNowDateTimeStr()); } catch (java.io.FileNotFoundException e) { models.utils.LogUtils.printLogError("File Not Found exception." + e.getLocalizedMessage()); fileContentString = "File Not Found exception. This file may have been removed. " + filePath; } catch (Throwable e) { models.utils.LogUtils.printLogError("Error in readConfigFile." + e.getLocalizedMessage()); e.printStackTrace(); fileContentString = "File Not Found exception. This file may have been removed. " + filePath; } return fileContentString.toString(); }