List of usage examples for java.io File toString
public String toString()
From source file:io.sloeber.core.managers.Manager.java
/** * Given a platform.txt file find the platform in the platform manager * * @param platformTxt/*from w ww.j ava2s. c o m*/ * @return the found platform otherwise null */ public static ArduinoPlatform getPlatform(File platformTxt) { String searchString = platformTxt.toString(); for (PackageIndex index : packageIndices) { for (Package pkg : index.getPackages()) { for (ArduinoPlatform curPlatform : pkg.getPlatforms()) { String curFile = curPlatform.getPlatformFile().toString(); if (searchString.equals(curFile)) { return curPlatform; } } } } return null; }
From source file:com.photon.phresco.service.dependency.impl.DependencyUtils.java
/** * Extracts the given compressed file (of type tar, targz, and zip) into given location. * See also//from ww w . java 2s .c o m * {@link ArchiveType} and {@link ArchiveUtil} * @param contentURL * @param path * @throws PhrescoException */ public static void extractFiles(String contentURL, String folderName, File path) throws PhrescoException { if (isDebugEnabled) { S_LOGGER.debug( "Entering Method DependencyUtils.extractFiles(String contentURL, String folderName, File path)"); } assert !StringUtils.isEmpty(contentURL); String extension = getExtension(contentURL); File archive = new File(Utility.getPhrescoTemp(), UUID.randomUUID().toString() + extension); FileOutputStream fos = null; OutputStream out = null; try { InputStream inputStream = PhrescoServerFactory.getRepositoryManager().getArtifactAsStream(contentURL); fos = new FileOutputStream(archive); out = new BufferedOutputStream(fos); IOUtils.copy(inputStream, out); out.flush(); out.close(); fos.close(); ArchiveType archiveType = getArchiveType(extension); if (isDebugEnabled) { S_LOGGER.debug("extractFiles() path=" + path.getPath()); } ArchiveUtil.extractArchive(archive.toString(), path.getAbsolutePath(), folderName, archiveType); archive.delete(); } catch (FileNotFoundException e) { return; } catch (IOException e) { throw new PhrescoException(e); } catch (PhrescoException pe) { if (pe.getCause() instanceof FileNotFoundException) { return; } throw pe; } finally { Utility.closeStream(fos); Utility.closeStream(out); } }
From source file:edu.cuny.cat.Game.java
/** * creates multiple market/specialist clients, each an instance of * {@link MarketClient}, based on parameter files in the specified directory * and its subdirectories. Each of these parameter files define a set of * market clients using the specified parameter base. * /*from w ww. ja v a2s. c o m*/ * For example * * <pre> * cat.specialist.optional.dir = params/elites * cat.specialist.optional.base = elites * </pre> * * specifies to look for parameter files in the directory * <code>params/elites</code> and all market clients are configured using the * parameter base <code>elites</code>. * * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") public static Collection<? extends MarketClient> createOptionalMarkets() throws InstantiationException, IllegalAccessException { final Parameter optionalParam = new Parameter(Game.P_CAT).push(Game.P_SPECIALIST).push(Game.P_OPTIONAL); final ParameterDatabase parameters = Galaxy.getInstance().getTyped(Game.P_CAT, ParameterDatabase.class); if (!parameters.exists(optionalParam.push(Game.P_DIR)) && !parameters.exists(optionalParam.push(Game.P_BASE))) { // no optional markets defined Game.logger.info("no optional market defined at " + optionalParam); return null; } final File dir = parameters.getFile(optionalParam.push(Game.P_DIR), null); if ((dir == null) || !dir.exists() || !dir.isDirectory()) { Game.logger.fatal("Directory for optional markets does NOT exist !"); Game.logger.fatal(dir.toString()); Utils.fatalError(); return null; } else { final String optionalBase = parameters.getString(optionalParam.push(Game.P_BASE), null); Game.logger.info("\n"); if (optionalBase == null) { Game.logger.info("No optional markets configured."); Game.logger.info("\n"); return null; } else { Game.logger.info("creating optional markets defined in " + dir + " at " + optionalBase + " ..."); final Collection<MarketClient> marketColl = new ArrayList<MarketClient>(); final Collection<File> files = FileUtils.listFiles(dir, new SuffixFileFilter(".params"), DirectoryFileFilter.INSTANCE); final ParameterDatabase root = new ParameterDatabase(); ParameterDatabase parametersPerFile = null; Collection<? extends MarketClient> marketCollPerFile = null; final Parameter base = new Parameter(optionalBase); for (final File file : files) { try { Game.logger.info("reading " + file.toString()); parametersPerFile = new ParameterDatabase(file); } catch (final FileNotFoundException e) { e.printStackTrace(); continue; } catch (final IOException e) { e.printStackTrace(); continue; } root.addParent(parameters); root.addParent(parametersPerFile); marketCollPerFile = Game.createMarkets(root, base); marketColl.addAll(marketCollPerFile); root.removeParents(); } return marketColl; } } }
From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java
public static void loadHistory(RuntimeBean runtime, File source) throws IOException { InputStream is = new FileInputStream(source); Reader rdr = new InputStreamReader(is, "utf-8"); JSONArray jtranss;//www . ja v a2 s . c o m try { jtranss = (JSONArray) (mParser.parse(rdr)); } catch (ParseException e) { throw new IOException(e); } rdr.close(); List<TransactionBean> transs = FromJSONLogic.fromJSONTransactions(jtranss, runtime.getApp()); runtime.setHistory(transs); runtime.firePropertyChange("history", null, runtime.getHistory()); setProp("app.history", source.toString()); }
From source file:jeplus.TRNSYSWinTools.java
/** * Create working directory and prepare input files for simulation * * @param workdir The directory to be created * @return Preparation successful or not *///from w w w. ja v a 2 s .c om public static boolean prepareWorkDir(String workdir) { boolean success = true; // Create the directory File dir = new File(workdir); if (!dir.exists()) { success = dir.mkdirs(); } else if (!dir.isDirectory()) { System.err.println(dir.toString() + " is present but not a directory."); success = false; } if (success) { // Copying all include and external files to the work directory // success = success && fileCopy(weatherfile, workdir + EPlusConfig.getEPDefEPW()); // if (! success) // System.err.println("TRNSYSWinTools.prepareWorkDir(): cannot copy all neccessray files to the working directory."); File[] files = dir.listFiles(); for (File file : files) { file.delete(); } } return success; }
From source file:fr.ens.biologie.genomique.eoulsan.actions.EMRExecAction.java
/** * Run Eoulsan in hadoop mode./*ww w.ja v a 2s. c om*/ * @param workflowFile workflow file * @param designFile design file * @param s3Path path of data on S3 file system * @param jobDescription job description */ private static void run(final File workflowFile, final File designFile, final DataFile s3Path, final String jobDescription) { checkNotNull(workflowFile, "paramFile is null"); checkNotNull(designFile, "designFile is null"); checkNotNull(s3Path, "s3Path is null"); getLogger().info("Parameter file: " + workflowFile); getLogger().info("Design file: " + designFile); final String desc; if (jobDescription == null) { desc = "no job description"; } else { desc = jobDescription.trim(); } try { // Test if workflow file exists if (!workflowFile.exists()) { throw new FileNotFoundException(workflowFile.toString()); } // Test if design file exists if (!designFile.exists()) { throw new FileNotFoundException(designFile.toString()); } // Create ExecutionArgument object final ExecutorArguments arguments = new ExecutorArguments(workflowFile, designFile); arguments.setJobDescription(desc); // Create the log File Main.getInstance().createLogFiles(arguments.logPath(Globals.LOG_FILENAME), arguments.logPath(Globals.OTHER_LOG_FILENAME)); // Create executor final Executor e = new Executor(arguments); // Launch executor e.execute(Lists.newArrayList((Module) new LocalUploadModule(s3Path), new AWSElasticMapReduceExecModule(), new TerminalModule()), null); } catch (FileNotFoundException e) { Common.errorExit(e, "File not found: " + e.getMessage()); } catch (Throwable e) { Common.errorExit(e, "Error while executing " + Globals.APP_NAME_LOWER_CASE + ": " + e.getMessage()); } }
From source file:com.cloudera.sqoop.manager.MySQLUtils.java
/** * Writes the user's password to a tmp file with 0600 permissions. * @return the filename used./* www .j a v a 2 s . co m*/ */ public static String writePasswordFile(Configuration conf) throws IOException { // Create the temp file to hold the user's password. String tmpDir = conf.get(ConfigurationConstants.PROP_JOB_LOCAL_DIRECTORY, "/tmp/"); File tempFile = File.createTempFile("mysql-cnf", ".cnf", new File(tmpDir)); // Make the password file only private readable. DirectImportUtils.setFilePermissions(tempFile, "0600"); // If we're here, the password file is believed to be ours alone. The // inability to set chmod 0600 inside Java is troublesome. We have to // trust that the external 'chmod' program in the path does the right // thing, and returns the correct exit status. But given our inability to // re-read the permissions associated with a file, we'll have to make do // with this. String password = conf.get(PASSWORD_KEY); BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile))); w.write("[client]\n"); w.write("password=" + password + "\n"); w.close(); return tempFile.toString(); }
From source file:com.distrimind.madkit.kernel.MadkitProperties.java
/** * Return an <code>InputStream</code> on a file. pathname could be relative to * (1) the actual MaDKit class path, which is preferable considering jar export, * or (2) the user.dir, or it could be an absolute path. The returned input * stream should be closed once done./*from www. ja v a 2 s.c o m*/ * * @param file * A pathname string If the <code>pathname</code> argument is * <code>null</code> * @return an <code>InputStream</code> by opening a connection to an actual * file, or <code>null</code> if the file is not found. * * @throws IOException if IO problem occurs */ public static InputStream getInputStream(final File file) throws IOException { // closed when used InputStream is = file.exists() ? new FileInputStream(file) : MadkitClassLoader.getLoader().getResourceAsStream(file.toString()); if (is == null) throw new FileNotFoundException(file.toString()); return is; }
From source file:dk.statsbiblioteket.util.Files.java
/** * Move a file with the same semantics as the standard Unix {@code move} * command.//ww w .ja v a2s . c o m * * In contrast to the standard Java {@link File#renameTo} this method * does extensive sanity checking and throws appropriate exceptions * if something is wrong. * * This method will cause quite a bit of {@code stat} dancing on the * file system, so don't use this method in performance critical regions. * * If {@code dest} is a directory {@code source} will be moved there keeping * its base name. * If {@code dest} does not exist {@code source} will be renamed to * {@code dest}. * * @param source a writable file or directory * @param dest either an existing writable directory, or non-existing file * with existing parent directory * @param overwrite if true and {@code dest} exists and is a regular * file it will be deleted before moving {@code source} * here * @throws FileNotFoundException if either {@code source} or the parent * directory of {@code dest} does not exist * @throws FileAlreadyExistsException if {@code dest} exists and is a * regular file. If {@code overwrite} * is {@code true} this exception will * never be thrown * @throws FilePermissionException if {@code source} or {@code dest} is not * writable * @throws InvalidFileTypeException if the parent of {@code dest} is a * regular file * @throws IOException if there is an unknown error during the move * operation */ public static void move(File source, File dest, boolean overwrite) throws IOException { if (source == null) { throw new NullPointerException("Move source location is null"); } if (dest == null) { throw new NullPointerException("Move destination is null"); } /* source checks */ if (!source.exists()) { throw new FileNotFoundException(source.toString()); } if (!source.canWrite()) { throw new FilePermissionException(source, Files.Permission.writable); } /* dest checks */ File destParent = dest.getParentFile(); if (dest.exists() && dest.isFile() && !overwrite) { throw new FileAlreadyExistsException(dest); } if (!destParent.exists()) { throw new FileNotFoundException("Parent directory of " + dest + " " + "does not exist"); } if (destParent.isFile()) { throw new InvalidFileTypeException(destParent, Files.Type.file); } if (dest.isFile() && !destParent.canWrite()) { throw new FilePermissionException(destParent, Files.Permission.writable); } /* If dest is a dir, move the file into it, keeping the base name */ if (dest.isDirectory()) { if (!dest.canWrite()) { throw new FilePermissionException(dest, Files.Permission.writable); } dest = new File(dest, source.getName()); } if (dest.exists()) { if (!overwrite) { throw new FileAlreadyExistsException(dest); } log.trace("Overwriting " + dest); Files.delete(dest); } log.trace("Set to move " + source + " to " + dest); // On some platform File.renameTo fails on the first runs. See // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213298 boolean result = false; for (int i = 0; i < 10; i++) { result = source.renameTo(dest); if (result) { break; } System.gc(); try { Thread.sleep(50); } catch (InterruptedException e) { // Abort the move operation break; } log.trace("Retrying move (" + i + ")"); } if (!result) { log.debug("Atomic move failed. Falling back to copy/delete"); copy(source, dest, overwrite); delete(source); } log.debug("Moved " + source + " to " + dest); }
From source file:edu.umass.cs.gnsserver.installer.GNSInstaller.java
private static void loadConfig(String configName) { File configFile = fileSomewhere(configName + FILESEPARATOR + INSTALLER_CONFIG_FILENAME, confFolderPath); InstallConfig installConfig = new InstallConfig(configFile.toString()); keyFile = installConfig.getKeyFile(); System.out.println("Key File: " + keyFile); userName = installConfig.getUsername(); System.out.println("User Name: " + userName); dataStoreType = installConfig.getDataStoreType(); System.out.println("Data Store Type: " + dataStoreType); hostType = installConfig.getHostType(); System.out.println("Host Type: " + hostType); installPath = installConfig.getInstallPath(); if (installPath == null) { installPath = DEFAULT_INSTALL_PATH; }/*from w w w . j av a 2 s . c om*/ System.out.println("Install Path: " + installPath); // javaCommand = installConfig.getJavaCommand(); if (javaCommand == null) { javaCommand = DEFAULT_JAVA_COMMAND; } System.out.println("Java Command: " + javaCommand); }