List of usage examples for java.io File toString
public String toString()
From source file:com.rtg.launcher.CommonFlags.java
/** * Returns true if the input file is the stdin/stdout indicator * @param file to test/*from w w w . j av a 2 s.co m*/ * @return true if the file indicates stdin/stdout should be used */ public static boolean isStdio(File file) { return isStdio(file.toString()); }
From source file:com.photon.phresco.service.util.DependencyUtils.java
/** * Extracts the given compressed file (of type tar, targz, and zip) into given location. * See also//from ww w . ja v a 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, String customerId) throws PhrescoException { if (isDebugEnabled) { LOGGER.debug("DependencyUtils.extractFiles:Entry"); LOGGER.info(ServiceConstants.DEPENDENCY_UTIL_EXTRACT_FILES, "contentURL=\"" + contentURL + "\"", "folderName=\"" + folderName + "\"", ServiceConstants.PATH_EQUALS_SLASH + path.getName() + "\"", ServiceConstants.CUSTOMER_ID_EQUALS_SLASH + customerId + "\""); } assert !StringUtils.isEmpty(contentURL); PhrescoServerFactory.initialize(); 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, customerId); fos = new FileOutputStream(archive); out = new BufferedOutputStream(fos); IOUtils.copy(inputStream, out); out.flush(); out.close(); fos.close(); ArchiveType archiveType = getArchiveType(extension); if (isDebugEnabled) { LOGGER.debug("extractFiles() path=" + path.getPath()); } ArchiveUtil.extractArchive(archive.toString(), path.getAbsolutePath(), folderName, archiveType); archive.delete(); if (isDebugEnabled) { LOGGER.debug("DependencyUtils.extractFiles:Exit"); } } catch (FileNotFoundException e) { LOGGER.error(ServiceConstants.DEPENDENCY_UTIL_EXTRACT_FILES, ServiceConstants.STATUS_FAILURE, "message=\"" + e.getLocalizedMessage() + "\""); return; } catch (IOException e) { LOGGER.error(ServiceConstants.DEPENDENCY_UTIL_EXTRACT_FILES, ServiceConstants.STATUS_FAILURE, "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e); } catch (PhrescoException pe) { LOGGER.error(ServiceConstants.DEPENDENCY_UTIL_EXTRACT_FILES, ServiceConstants.STATUS_FAILURE, "message=\"" + pe.getLocalizedMessage() + "\""); if (pe.getCause() instanceof FileNotFoundException) { return; } throw pe; } finally { Utility.closeStream(fos); Utility.closeStream(out); } }
From source file:org.webinos.android.util.ModuleUtils.java
public static boolean copyFile(File src, File dest) { boolean result = true; if (src.isDirectory()) { result = copyDir(src, dest);/* w ww .j av a 2 s. co m*/ } else { FileInputStream fis = null; FileOutputStream fos = null; try { int count; byte[] buf = new byte[1024]; fis = new FileInputStream(src); fos = new FileOutputStream(dest); while ((count = fis.read(buf, 0, 1024)) != -1) fos.write(buf, 0, count); } catch (IOException e) { Log.v(TAG, "moveFile exception: aborting; exception: " + e + "; src = " + src.toString() + "; dest = " + dest.toString()); return false; } finally { try { if (fis != null) fis.close(); if (fos != null) fos.close(); } catch (IOException ieo) { } } } return result; }
From source file:de.julielab.jtbd.TokenizerApplication.java
/** * writes an ArrayList of Strings to a file * * @param lines/* www .j a v a2 s .c o m*/ * the ArrayList * @param outFile */ static void writeFile(final ArrayList<String> lines, final File outFile) { try { final FileWriter fw = new FileWriter(outFile); for (int i = 0; i < lines.size(); i++) fw.write(lines.get(i) + "\n"); fw.close(); } catch (final Exception e) { System.err.println("ERR: error writing file: " + outFile.toString()); e.printStackTrace(); System.exit(-1); } }
From source file:edu.umass.cs.gnsserver.installer.GNSInstaller.java
private static void loadHostsFiles(String configName) { List<HostSpec> nsHosts = null; File hostsFile = null; try {//from www . j a va 2 s. c om hostsFile = fileSomewhere(configName + FILESEPARATOR + NS_HOSTS_FILENAME, confFolderPath); nsHosts = HostFileLoader.loadHostFile(hostsFile.toString()); } catch (Exception e) { // should not happen as we've already verified this above System.out.println("Problem loading the NS host file " + hostsFile + " : " + e); System.exit(1); } for (HostSpec spec : nsHosts) { String hostname = spec.getName(); String id = spec.getId(); hostTable.put(hostname, new HostInfo(hostname, id, false, null)); } List<HostSpec> lnsHosts = null; try { hostsFile = fileSomewhere(configName + FILESEPARATOR + LNS_HOSTS_FILENAME, confFolderPath); lnsHosts = HostFileLoader.loadHostFile(hostsFile.toString()); // should not happen as we've already verified this above } catch (Exception e) { System.out.println("Problem loading the LNS host file " + hostsFile + e); System.exit(1); } // FIXME: BROKEN FOR IDLESS LNS HOSTS for (HostSpec spec : lnsHosts) { String hostname = spec.getName(); //String id = spec.getId(); HostInfo hostEntry = hostTable.get(hostname); if (hostEntry != null) { hostEntry.setCreateLNS(true); } else { hostTable.put(hostname, new HostInfo(hostname, null, true, null)); } } }
From source file:Main.java
public static String[] getMountedVolumes() { final String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // we can read the External Storage... //Retrieve the primary External Storage: final File primaryExternalStorage = Environment.getExternalStorageDirectory(); //Retrieve the External Storages root directory: String externalStorageRootDir = null; if ((externalStorageRootDir = primaryExternalStorage.getParent()) == null) { // no parent... return (new String[] { "ONLY A SINGLE VOLUME HAS BEEN DETECTED!", (Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)" : "(INTERNAL STORAGE)") + " PRIMARY STORAGE: " + primaryExternalStorage }); } else {//from www .j a va 2s. c o m final File externalStorageRoot = new File(externalStorageRootDir); final File[] files = externalStorageRoot.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { // TODO Auto-generated method stub File file = new File(dir, filename); if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden()) { return true; } return false; } }); //.listFiles(); List<String> data = new ArrayList<String>(); if (files.length > 1) { data.add("MULTIPLE VOLUMES HAS BEEN DETECTED!"); data.add("Enumerating detected volumes . . ."); } else { data.add("ONLY A SINGLE VOLUME HAS BEEN DETECTED!"); } for (final File file : files) { if (file.isDirectory() && file.canRead() && file.canWrite() && !file.isHidden() && (files.length > 0)) { // it is a real directory (not a USB drive)... if (file.toString().equals(primaryExternalStorage.toString())) data.add((Environment.isExternalStorageRemovable() ? "(REMOVABLE SD-CARD)" : "(INTERNAL Memory)") + " PRIMARY STORAGE: " + file.getAbsolutePath()); else { data.add(((file.toString().contains("usb") || file.toString().contains("USB")) ? "MOUNTED USB" : "MOUNTED") + " STORAGE: " + file.getAbsolutePath()); } } } return data.toArray(new String[data.size()]); } } else { // we cannot read the External Storage..., return null return null; } }
From source file:net.yacy.yacy.java
/** * Loads the configuration from the data-folder. * FIXME: Why is this called over and over again from every method, instead * of setting the configurationdata once for this class in main? * * @param mes Where are we called from, so that the errormessages can be * more descriptive./*from w w w . j av a2s. co m*/ * @param homePath Root-path where all the information is to be found. * @return Properties read from the configurationfile. */ private static Properties configuration(final String mes, final File homePath) { ConcurrentLog.config(mes, "Application Root Path: " + homePath.toString()); // read data folder final File dataFolder = new File(homePath, "DATA"); if (!(dataFolder.exists())) { ConcurrentLog.severe(mes, "Application was never started or root path wrong."); System.exit(-1); } final Properties config = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(new File(homePath, "DATA/SETTINGS/yacy.conf")); config.load(fis); } catch (final FileNotFoundException e) { ConcurrentLog.severe(mes, "could not find configuration file."); System.exit(-1); } catch (final IOException e) { ConcurrentLog.severe(mes, "could not read configuration file."); System.exit(-1); } finally { if (fis != null) { try { fis.close(); } catch (final IOException e) { ConcurrentLog.logException(e); } } } return config; }
From source file:Hash.Hash.java
public static String getFullHash(File file) throws FileNotFoundException, IOException { MessageDigest md5Digest = null; try {//from ww w .j a v a 2 s. c o m md5Digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException ex) { return EMPTYHASH; } byte[] digestDef = md5Digest.digest(); byte[] digest = null; try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(file.toString())); DigestInputStream in = new DigestInputStream(fileStream, md5Digest);) { byte[] buffer = new byte[4096]; in.on(true); while (in.read(buffer) != -1) { } digest = md5Digest.digest(); } if (digest == null) { return EMPTYHASH; } if (Arrays.equals(digest, digestDef)) { return EMPTYHASH; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < digest.length; ++i) { sb.append(Integer.toHexString((digest[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); }
From source file:com.depas.utils.FileUtils.java
public static String extractPathRelativeToDirectory(File chrootIn, File absolutePathIn) { if (chrootIn == null || absolutePathIn == null) { throw new IllegalArgumentException("The arguments must be non-null."); }//from w ww . java 2s. c o m File chroot = chrootIn; File absolutePath = absolutePathIn; // Canonization will turn things like "/home/dpa/dir/../dir" into "/home/dpa/dir". try { chroot = chroot.getCanonicalFile(); } catch (Exception ex) { logger.warn("Failed to obtain canonical form of the 'chroot' file [" + chroot.toString() + "].", ex); } try { absolutePath = absolutePath.getCanonicalFile(); } catch (Exception ex) { logger.warn( "Failed to obtain canonical form of the 'absolutePath' file [" + absolutePath.toString() + "].", ex); } String result = ""; String delim = ""; // safety limit of 200 iterations in case there is a loop in the file system for (int i = 0; i < 200 && absolutePath.getParentFile() != null; i++) { if (chroot.equals(absolutePath)) { return !result.isEmpty() ? result : "."; } result = absolutePath.getName() + delim + result; delim = "/"; absolutePath = absolutePath.getParentFile(); } // could not find a match return null; }
From source file:com.rtg.launcher.CommonFlags.java
/** * Gets the AVR model to use for prediction. If the user has supplied a model name, it will be first * searched for as an actual file name, or secondly as a name within the environmental model directory * (if configured)//from ww w. ja v a 2 s .c o m * * * @param flags shared flags * @param anonymous true if the model was registered as the only anonymous flag * @return a File pointing at the specified AVR model, or null if no AVR model is to be used * @throws InvalidParamsException if the user specified a model that does not exist, or a models directory which does * not exist or is not a directory. */ public static File getAvrModel(final CFlags flags, boolean anonymous) { File avrModel = defaultAvrModel(); final Flag flag = anonymous ? flags.getAnonymousFlag(0) : flags.getFlag(AVR_MODEL_FILE_FLAG); if (flag != null && flag.isSet()) { final String modelsDir = Environment.getEnvironmentMap().get(ENVIRONMENT_MODELS_DIR); final File userModel = (File) flag.getValue(); if (AVR_NONE_NAME.equals(userModel.toString())) { return null; } else if (userModel.exists()) { avrModel = userModel; } else if (modelsDir != null) { avrModel = new File(modelsDir, userModel.getName()); } if (avrModel == null || !avrModel.exists()) { throw new InvalidParamsException( "The specified AVR model could not be found: " + userModel.toString()); } } return avrModel; }