List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:com.moviejukebox.tools.FileTools.java
/** * Returns the parent folder name only; used when searching for artwork... * * @param file/*from w w w. j a v a2s. c om*/ * @return */ public static String getParentFolderName(File file) { if (file == null) { return ""; } String path = file.getParent(); return path.substring(path.lastIndexOf(File.separator) + 1); }
From source file:de.xirp.profile.Executable.java
/** * Returns the working directory where the executable is located * in./* w ww. ja v a 2 s .c om*/ * * @return The working directory. */ @XmlTransient public String getWorkingDirectory() { File f = new File(path); return f.getParent(); }
From source file:com.google.gdocsfs.GoogleDocs.java
public Document getDocument(String path) { if (path.equals("/")) { return root; }/*from ww w. java 2 s . c o m*/ File file = new File(path); Document parent = getDocument(file.getParent()); return parent instanceof Folder ? ((Folder) parent).getDocument(file.getName()) : null; }
From source file:com.ikanow.aleph2.analytics.spark.services.SparkCompilerService.java
/** Compiles a scala class * @param script/* w w w. ja v a 2 s .c o m*/ * @param clazz_name * @return * @throws IOException * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException */ public Tuple2<ClassLoader, Object> buildClass(final String script, final String clazz_name, final Optional<IBucketLogger> logger) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { final String relative_dir = "./script_classpath/"; new File(relative_dir).mkdirs(); final File source_file = new File(relative_dir + clazz_name + ".scala"); FileUtils.writeStringToFile(source_file, script); final String this_path = LiveInjector.findPathJar(this.getClass(), "./dummy.jar"); final File f = new File(this_path); final File fp = new File(f.getParent()); final String classpath = Arrays.stream(fp.listFiles()).map(ff -> ff.toString()) .filter(ff -> ff.endsWith(".jar")).collect(Collectors.joining(":")); // Need this to make the URL classloader be used, not the system classloader (which doesn't know about Aleph2..) final Settings s = new Settings(); s.classpath().value_$eq(System.getProperty("java.class.path") + classpath); s.usejavacp().scala$tools$nsc$settings$AbsSettings$AbsSetting$$internalSetting_$eq(true); final StoreReporter reporter = new StoreReporter(); final Global g = new Global(s, reporter); final Run r = g.new Run(); r.compile(JavaConverters.asScalaBufferConverter(Arrays.<String>asList(source_file.toString())).asScala() .toList()); if (reporter.hasErrors() || reporter.hasWarnings()) { final String errors = "Compiler: Errors/warnings (**to get to user script line substract 22**): " + JavaConverters.asJavaSetConverter(reporter.infos()).asJava().stream() .map(info -> info.toString()).collect(Collectors.joining(" ;; ")); logger.ifPresent(l -> l.log(reporter.hasErrors() ? Level.ERROR : Level.DEBUG, false, () -> errors, () -> "SparkScalaInterpreterTopology", () -> "compile")); //ERROR: if (reporter.hasErrors()) { System.err.println(errors); } } // Move any class files (eg including sub-classes) Arrays.stream(fp.listFiles()).filter(ff -> ff.toString().endsWith(".class")) .forEach(Lambdas.wrap_consumer_u(ff -> { FileUtils.moveFile(ff, new File(relative_dir + ff.getName())); })); // Create a JAR file... Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); final JarOutputStream target = new JarOutputStream(new FileOutputStream("./script_classpath.jar"), manifest); Arrays.stream(new File(relative_dir).listFiles()).forEach(Lambdas.wrap_consumer_i(ff -> { JarEntry entry = new JarEntry(ff.getName()); target.putNextEntry(entry); try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(ff))) { byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) break; target.write(buffer, 0, count); } target.closeEntry(); } })); target.close(); final String created = "Created = " + new File("./script_classpath.jar").toURI().toURL() + " ... " + Arrays.stream(new File(relative_dir).listFiles()).map(ff -> ff.toString()) .collect(Collectors.joining(";")); logger.ifPresent(l -> l.log(Level.DEBUG, true, () -> created, () -> "SparkScalaInterpreterTopology", () -> "compile")); final Tuple2<ClassLoader, Object> o = Lambdas.get(Lambdas.wrap_u(() -> { _cl.set(new java.net.URLClassLoader( Arrays.asList(new File("./script_classpath.jar").toURI().toURL()).toArray(new URL[0]), Thread.currentThread().getContextClassLoader())); Object o_ = _cl.get().loadClass("ScriptRunner").newInstance(); return Tuples._2T(_cl.get(), o_); })); return o; }
From source file:com.mindquarry.desktop.workspace.conflict.ReplaceConflict.java
public void beforeUpdate() throws ClientException, IOException { File file = new File(status.getPath()); switch (action) { case UNKNOWN: // client did not set a conflict resolution log.error("AddConflict with no action set: " + status.getPath()); break;//from w w w .ja v a 2 s.c o m case RENAME: log.info("renaming " + file.getAbsolutePath() + " to " + newName); File source = new File(status.getPath()); File destination = new File(source.getParent(), newName); if (source.isDirectory()) { FileUtils.copyDirectory(source, destination); removeDotSVNDirectories(destination.getPath()); } else { FileUtils.copyFile(source, destination); } client.add(destination.getPath(), true, true); client.remove(new String[] { file.getPath() }, null, true); break; case REPLACE: log.info("replacing with new file/folder from server: " + status.getPath()); client.revert(file.getPath(), true); if (status.getRepositoryTextStatus() == StatusKind.replaced) { FileUtils.forceDelete(file); } break; } }
From source file:cz.incad.vdkcommon.VDKJobData.java
public void load() throws Exception { File fdef = FileUtils.toFile(Options.class.getResource("/cz/incad/vdkcommon/job.json")); String json = FileUtils.readFileToString(fdef, "UTF-8"); opts = new JSONObject(json); File f = new File(this.configFile); this.configDir = f.getParent(); this.configSimpleName = f.getName().split("\\.")[0]; this.statusFile = this.configDir + File.separator + "status" + File.separator + this.configSimpleName + ".status"; if (f.exists() && f.canRead()) { json = FileUtils.readFileToString(f, "UTF-8"); JSONObject confCustom = new JSONObject(json); Iterator keys = confCustom.keys(); while (keys.hasNext()) { String key = (String) keys.next(); opts.put(key, confCustom.get(key)); }//from www .j a va 2 s .c o m } Iterator keys = runtimeOptions.keys(); while (keys.hasNext()) { String key = (String) keys.next(); opts.put(key, runtimeOptions.get(key)); } logger.info("VDKJobData loaded"); }
From source file:gov.nih.nci.caintegrator.application.analysis.grid.preprocess.PreprocessDatasetGridRunner.java
private File replaceGctFileWithPreprocessed(File gctFile, File zipFile) throws IOException { File zipFileDirectory = new File(zipFile.getParent().concat("/tempPreprocessedZipDir")); FileUtils.deleteDirectory(zipFileDirectory); FileUtils.forceMkdir(zipFileDirectory); FileUtils.waitFor(zipFileDirectory, TIMEOUT_SECONDS); Cai2Util.isValidZipFile(zipFile); ZipUtilities.unzip(zipFile, zipFileDirectory); FileUtils.waitFor(zipFileDirectory, TIMEOUT_SECONDS); Cai2Util.printDirContents(zipFileDirectory); if (zipFileDirectory.list() != null) { if (zipFileDirectory.list().length != 1) { int dirListlength = zipFileDirectory.list().length; FileUtils.deleteDirectory(zipFileDirectory); throw new IllegalStateException("The zip file returned from PreprocessDataset" + " should have exactly 1 file instead of " + dirListlength); }//w w w .ja v a 2s. c o m } else { String zipFileDirectoryPath = zipFileDirectory.getAbsolutePath(); FileUtils.deleteDirectory(zipFileDirectory); throw new IllegalStateException( "The zip file directory list at path: " + zipFileDirectoryPath + "is null."); } String[] files = zipFileDirectory.list(); File preprocessedFile = new File(zipFileDirectory, files[0]); FileUtils.deleteQuietly(gctFile); // Remove the non-preprocessed file FileUtils.moveFile(preprocessedFile, gctFile); // move to gctFile FileUtils.deleteQuietly(zipFile); FileUtils.deleteDirectory(zipFileDirectory); return gctFile; }
From source file:com.amalto.core.servlet.UploadFile.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); String path = getServletConfig().getServletContext().getRealPath("/"); //$NON-NLS-1$ File webAppPath = new File(path); containerWebAppsPath = webAppPath.getParent(); if (LOG.isDebugEnabled()) { LOG.debug("container webapps path-->" + path); //$NON-NLS-1$ }//from w w w . ja va 2 s.c om }
From source file:com.tealeaf.Downloader.java
protected void write(File f, String contents) { try {//from w w w . j a va2s . co m if (!f.exists()) { File dir = new File(f.getParent()); dir.mkdirs(); f.createNewFile(); } FileWriter fw = new FileWriter(f); fw.write(contents); fw.close(); } catch (IOException e) { logger.log(e); } }
From source file:com.nary.io.FileUtils.java
private static List<Map<String, cfData>> createFileVector(List<File> files, File rootdir, boolean recurse) { if (files == null) return null; String rootDirString = rootdir.getAbsolutePath(); List<Map<String, cfData>> resultVector = new ArrayList<Map<String, cfData>>(); int rootprefix = 1 + rootDirString.length(); for (int i = 0; i < files.size(); i++) { File f = files.get(i); Map<String, cfData> hm = new FastMap<String, cfData>(); if (recurse) { // Make this a relative path hm.put("name", new cfStringData(f.getAbsolutePath().substring(rootprefix))); hm.put("directory", new cfStringData(rootDirString)); } else {//from w ww .j a va 2 s .c o m hm.put("name", new cfStringData(f.getName())); hm.put("directory", new cfStringData(f.getParent())); } hm.put("size", new cfNumberData(f.length())); if (f.isDirectory()) { hm.put("type", new cfStringData("Dir")); } else { hm.put("type", new cfStringData("File")); } hm.put("datelastmodified", new cfDateData(f.lastModified())); StringBuilder attrs = new StringBuilder(); if (!f.canWrite()) attrs.append('R'); if (f.isHidden()) attrs.append('H'); hm.put("attributes", new cfStringData(attrs.toString())); hm.put("mode", new cfStringData("")); resultVector.add(hm); } return resultVector; }