List of usage examples for java.io File toString
public String toString()
From source file:com.github.houbin217jz.thumbnail.Thumbnail.java
public static void doResize(File src, File dst, Integer width, Integer height, Double ratio) { try {/*from ww w . j av a 2 s . c o m*/ Builder<File> builder = Thumbnails.of(src); if ((width == null || height == null) && ratio != null) { builder.scale(ratio).toFile(dst); } if ((width != null && height != null) && ratio == null) { builder.size(width, height).toFile(dst); } } catch (IOException e) { System.out.println("Error"); System.out.println("src:" + src.toString()); System.out.println("dst:" + dst.toString()); } }
From source file:dk.statsbiblioteket.util.Files.java
/** * Delete the file or directory given by <code>path</code> (recursively if * <code>path</code> is a directory). * * @param path a {@link File} representing the file or directory to be * deleted./*from w w w .ja v a 2s . c om*/ * @throws IOException if the path doesn't exist or could not be deleted. */ public static void delete(File path) throws IOException { log.trace("delete(" + path + ") called"); if (!path.exists()) { throw new FileNotFoundException(path.toString()); } if (path.isFile()) { if (!path.delete()) { throw new IOException("Could not delete the file '" + path + "'"); } return; } for (String child : path.list()) { delete(new File(path, child)); } if (!path.delete()) { throw new IOException("Could not delete the folder '" + path + "'"); } }
From source file:DiskIO.java
/** * Ensures the existence of the directory specified by the parameter. If the * directory does not exist, an attempt is performed to create it including * all necessary parent directories that may be implied by the * specification. ### HELPME : against what should a relative pathname be * made absolute? ### ### We need to set the installation directory * somewhere! ####// ww w . j av a2 s.c o m * * @param dir * File specifying the intended directory name; if the specified * name is a relative path, it is always made absolute against * the program's <b>installationDirectory </b>. * @return <b>true </b> if and only if the specified file exists and is a * directory */ public static boolean ensureDirectory(File dir) { if (dir == null) { throw new IllegalArgumentException("dir = null"); } boolean success = true; if (!dir.isDirectory()) { success = !dir.isFile() && dir.mkdirs(); if (success) { LOG.info("Created directory: " + dir.toString()); } else { LOG.severe("failed while trying to create directory: " + dir.toString()); } } return success; }
From source file:net.centro.rtb.monitoringcenter.util.ConfigFileUtil.java
public static void fillConfigBuilderFromFile(File configFile, MonitoringCenterConfig.Builder configBuilder) { MonitoringCenterConfigDto configFromFile = null; if (configFile != null && configFile.exists()) { try {//w ww .java2 s.com configFromFile = objectMapper.readValue(configFile, MonitoringCenterConfigDto.class); } catch (IOException e) { throw new ConfigException("Could not process config file: " + configFile.toString(), e); } } if (configFromFile != null) { NamingConfigDto namingConfigFromFile = configFromFile.getNamingConfig(); if (namingConfigFromFile != null) { if (namingConfigFromFile.getApplicationName() != null) { configBuilder.applicationName(namingConfigFromFile.getApplicationName()); } configBuilder.datacenterName(namingConfigFromFile.getDatacenterName()); configBuilder.nodeGroupName(namingConfigFromFile.getNodeGroupName()); configBuilder.nodeId(namingConfigFromFile.getNodeId()); if (namingConfigFromFile.getMetricNamePostfixPolicy() != null && namingConfigFromFile .getMetricNamePostfixPolicy() != MetricNamePostfixPolicyDto.UNKNOWN) { configBuilder.metricNamePostfixPolicy(convertMetricNamePostfixPolicyToEntity( namingConfigFromFile.getMetricNamePostfixPolicy())); } if (namingConfigFromFile.getAppendTypeToHealthCheckNames() != null) { configBuilder .appendTypeToHealthCheckNames(namingConfigFromFile.getAppendTypeToHealthCheckNames()); } } MetricCollectionConfigDto collectionConfigFromFile = configFromFile.getMetricCollectionConfig(); if (collectionConfigFromFile != null) { if (collectionConfigFromFile.getEnableSystemMetrics() != null) { configBuilder.enableSystemMetrics(collectionConfigFromFile.getEnableSystemMetrics()); } if (collectionConfigFromFile.getEnableTomcatMetrics() != null) { configBuilder.enableTomcatMetrics(collectionConfigFromFile.getEnableTomcatMetrics()); } } MetricReportingConfigDto reportingConfigFromFile = configFromFile.getMetricReportingConfig(); if (reportingConfigFromFile != null) { GraphiteReporterConfigDto graphiteReporterConfigFromFile = reportingConfigFromFile .getGraphiteReporterConfig(); if (graphiteReporterConfigFromFile != null) { GraphiteReporterConfig.Builder graphiteReporterConfigBuilder = GraphiteReporterConfig.builder(); if (graphiteReporterConfigFromFile.getEnableReporter() != null) { graphiteReporterConfigBuilder .enableReporter(graphiteReporterConfigFromFile.getEnableReporter()); } if (graphiteReporterConfigFromFile.getEnableBatching() != null) { graphiteReporterConfigBuilder .enableBatching(graphiteReporterConfigFromFile.getEnableBatching()); } if (graphiteReporterConfigFromFile.getReportingIntervalInSeconds() != null) { graphiteReporterConfigBuilder.reportingInterval( graphiteReporterConfigFromFile.getReportingIntervalInSeconds(), TimeUnit.SECONDS); } HostAndPort address = graphiteReporterConfigFromFile.getAddress(); if (address != null) { graphiteReporterConfigBuilder.address(address.getHost(), address.getPort()); } if (graphiteReporterConfigFromFile.getStartsWithFilters() != null) { graphiteReporterConfigBuilder .startsWithFilters(graphiteReporterConfigFromFile.getStartsWithFilters()); } if (graphiteReporterConfigFromFile.getBlockedStartsWithFilters() != null) { graphiteReporterConfigBuilder.blockedStartsWithFilters( graphiteReporterConfigFromFile.getBlockedStartsWithFilters()); } configBuilder.graphiteReporterConfig(graphiteReporterConfigBuilder.build()); } } } }
From source file:com.ikanow.aleph2.analytics.spark.utils.SparkTechnologyUtils.java
/**Checks if an aleph2 JAR file with bad internal JARs is cached, does some excising if not * @param local_file/*from w w w.jav a 2s . co m*/ * @param root_path * @param fc * @return * @throws IOException */ public static Tuple3<File, Path, FileStatus> removeSparkConflictsAndCache(final String local_file, final String root_path, final FileContext fc) throws IOException { final String renamed_local_file = local_file.replaceFirst(".jar", "_sparkVersion.jar"); final File f = new File(renamed_local_file); final Tuple2<File, Path> f_p = Tuples._2T(f, new Path(root_path + "/" + f.getName())); final FileStatus fs = Lambdas.get(() -> { try { return fc.getFileStatus(f_p._2()); } catch (Exception e) { return null; } }); if (null == fs) { //cache doesn't exist // Create a new copy without akka in tmp File f_tmp = File.createTempFile("aleph2-temp", ".jar"); JarBuilderUtil.mergeJars(Arrays.asList(local_file), f_tmp.toString(), ImmutableSet.of("akka", "scala", "com/typesafe/conf", "reference.conf", //(these definitely need to be removed) "org/jboss/netty", //(not sure about this, can't imagine i actually need it though? If so try putting back in) "org/apache/curator", "org/apache/zookeeper")); //(not sure about these, can try putting them back in if needed) return Tuples._3T(f_tmp, f_p._2(), null); } else return Tuples._3T(f_p._1(), f_p._2(), fs); }
From source file:org.webinos.android.util.ModuleUtils.java
public static void uninstall(String module) { /* if no module was specified, it is an error */ if (module == null || module.isEmpty()) { Log.v(TAG, "uninstall: no module specified"); return;/*from w w w.j a va2 s.c om*/ } File moduleLocation = locateModule(module, null); if (moduleLocation == null) { Log.v(TAG, "uninstall: specified module does not exist: " + module); return; } if (!deleteFile(moduleLocation)) { Log.v(TAG, "uninstall: unable to delete: " + module + "; attempting to delete " + moduleLocation.toString()); return; } Log.v(TAG, "uninstall: success; module = " + module + ", location = " + moduleLocation.toString()); }
From source file:org.webinos.android.util.ModuleUtils.java
public static void install(Context ctx, String module, String path) { moduleDir.mkdirs();/*from ww w . j a v a2 s . c o m*/ File moduleResource; boolean remove_tmp_resource = false; /* if no path was specified, it is an error */ if (path == null || path.isEmpty()) { Log.v(TAG, "install: no path specified"); return; } /* resolve expected module type from path */ ModuleType modType = guessModuleType(path); if (modType == null) { Log.v(TAG, "install: unable to determine module type: path = " + path); return; } /* guess the module name, if not already specified */ if (module == null || module.isEmpty()) { module = guessModuleName(path, modType); } /* download module if http or https */ if (path.startsWith("http://") || path.startsWith("https://")) { String filename = ModuleUtils.getResourceUriHash(path); try { moduleResource = downloadResource(new URI(path), filename); remove_tmp_resource = true; } catch (IOException e) { Log.v(TAG, "install: aborting (unable to download resource); exception: " + e + "; resource = " + path); return; } catch (URISyntaxException e) { Log.v(TAG, "install: aborting (invalid URI specified for resource); exception: " + e + "; resource = " + path); return; } /* extract to temp file if an asset */ } else if (path.startsWith(AssetUtils.ASSET_URI)) { try { String filename = ModuleUtils.getResourceUriHash(path); String destination = new File(resourceDir, filename).getAbsolutePath(); moduleResource = AssetUtils.writeAssetToFile(ctx, path.substring(AssetUtils.ASSET_URI.length()), destination); remove_tmp_resource = true; } catch (IOException e) { Log.v(TAG, "install: aborting (unable to extract resource); exception: " + e + "; resource = " + path); return; } } else { moduleResource = new File(path); } /* unpack if necessary */ if (modType.unpacker != null) { try { moduleResource = unpack(moduleResource, module, modType); remove_tmp_resource = true; } catch (IOException e) { Log.v(TAG, "install: aborting (unable to unpack resource); exception: " + e + "; resource = " + path); return; } } /* copy processed package to modules dir */ File installLocation = getModuleFile(module, modType); if (installLocation.exists()) { if (!deleteFile(installLocation)) { Log.v(TAG, "install: aborting (unable to delete old module version); resource = " + path + ", destination = " + installLocation.toString()); return; } } if (copyFile(moduleResource, installLocation)) { if (remove_tmp_resource) deleteFile(moduleResource); Log.v(TAG, "install: success; resource = " + path + ", destination = " + installLocation.toString()); return; } Log.v(TAG, "install: aborting (unable to copy resource); resource = " + path + ", destination = " + installLocation.toString()); }
From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtility.java
/** * Creates the JHOVE context and stores its configuration in a default temp folder. * Use {@link JhoveContext#destroy() } to remove temp folder. * * @return the context/*from ww w .j av a2 s . c o m*/ * @throws MetsExportException failure */ public static JhoveContext createContext() throws MetsExportException { File temp = new File(FileUtils.getTempDirectory(), "jhove" + UUID.randomUUID().toString()); if (!temp.mkdir()) { throw new MetsExportException("Cannot create " + temp.toString()); } temp.deleteOnExit(); return createContext(temp); }
From source file:edu.umass.cs.utils.Util.java
public static ArrayList<String> recursiveFind(String dir, String regex) { ArrayList<String> matches = new ArrayList<String>(); for (File f : new File(dir).listFiles()) { if (f.toString().matches(regex)) matches.add(f.toString());//w ww . ja v a 2 s . c om if (f.isDirectory()) matches.addAll(recursiveFind(f.toString(), regex)); } return matches; }
From source file:Main.java
public static File[] getMountedVolumesAsFile() { 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 File[] { primaryExternalStorage }); } else {//from ww w . j a v a 2 s .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<File> data = new ArrayList<File>(); 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(file); else { if (!file.toString().contains("usb") || !file.toString().contains("USB")) { data.add(file); } } } } return data.toArray(new File[data.size()]); } } else { // we cannot read the External Storage..., return null return null; } }