List of usage examples for java.io File getParentFile
public File getParentFile()
null
if this pathname does not name a parent directory. From source file:com.taobao.android.builder.tools.asm.ClassNameRenamer.java
public static void rewriteDataBinderMapper(File dir, String fromName, String toName, File Clazz) throws IOException { FileInputStream fileInputStream = new FileInputStream(Clazz); ClassReader in1 = new ClassReader(fileInputStream); ClassWriter cw = new ClassWriter(0); Set<String> renames = new HashSet<String>(); renames.add(fromName);/*from ww w . j ava 2s.co m*/ in1.accept(new ClassRenamer(cw, renames, toName), 8); File destClass = new File(dir, toName + ".class"); destClass.getParentFile().mkdirs(); FileOutputStream fileOutputStream = new FileOutputStream(destClass); fileOutputStream.write(cw.toByteArray()); IOUtils.closeQuietly(fileOutputStream); IOUtils.closeQuietly(fileInputStream); }
From source file:de.huxhorn.lilith.tools.CreateMd5Command.java
public static boolean createMd5(File input) { final Logger logger = LoggerFactory.getLogger(CreateMd5Command.class); if (!input.isFile()) { if (logger.isWarnEnabled()) logger.warn("{} isn't a file!", input.getAbsolutePath()); return false; }/*from w w w . ja va 2 s . c o m*/ File output = new File(input.getParentFile(), input.getName() + ".md5"); try { FileInputStream fis = new FileInputStream(input); byte[] md5 = ApplicationPreferences.getMD5(fis); if (md5 == null) { if (logger.isWarnEnabled()) { logger.warn("Couldn't calculate checksum for {}!", input.getAbsolutePath()); } return false; } FileOutputStream fos = new FileOutputStream(output); fos.write(md5); fos.close(); if (logger.isInfoEnabled()) { logger.info("Wrote checksum of {} to {}.", input.getAbsolutePath(), output.getAbsolutePath()); logger.info("MD5: {}", Hex.encodeHexString(md5)); } } catch (IOException e) { if (logger.isWarnEnabled()) logger.warn("Exception while creating checksum!", e); return false; } return true; }
From source file:com.bb.extensions.plugin.unittests.internal.utilities.FileUtils.java
/** * Delete the File/Directory, all files underneath (if it is a Directory) * and all parent Directories which are empty. * //from w w w.j a v a 2 s . c o m * @param dir * The Directory to delete * @return True if the File was deleted successfully false otherwise */ public static boolean deleteFileAndEmptyParentDirectories(File dir) { File parentDirectory = dir.getParentFile(); if (!deleteDirectoryRecursive(dir)) { return false; } while (true) { dir = parentDirectory; parentDirectory = dir.getParentFile(); if (!deleteDirectoryIfEmpty(dir)) { break; } } return true; }
From source file:com.bedatadriven.renjin.appengine.AppEngineContextFactory.java
@VisibleForTesting static String findHomeDirectory(File servletContextRoot, String sexpClassPath) throws IOException { LOG.fine("Found SEXP in '" + sexpClassPath); File jarFile = jarFileFromResource(sexpClassPath); StringBuilder homePath = new StringBuilder(); homePath.append('/').append(jarFile.getName()).append("!/r"); File parent = jarFile.getParentFile(); while (!servletContextRoot.equals(parent)) { if (parent == null) { throw new IllegalStateException( "Expected the renjin-core jar to be in the WEB-INF, bound found it in:\n" + jarFile.toString() + "\nAre you sure you are running in a servlet environment?"); }// w w w . j a v a 2s. co m homePath.insert(0, parent.getName()); homePath.insert(0, '/'); parent = parent.getParentFile(); } homePath.insert(0, "jar:file://"); return homePath.toString(); }
From source file:com.taobao.android.builder.tools.solib.NativeSoUtils.java
/** * abiso/*ww w.j ava2s .c om*/ * * @param supportAbis * @param removeSoFiles * @param dirs * @return */ public static Map<String, Multimap<String, File>> getAbiSoFiles(Set<String> supportAbis, Set<String> removeSoFiles, List<File> dirs) { Map<String, Multimap<String, File>> result = new HashMap<String, Multimap<String, File>>(); IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles); for (File dir : dirs) { Collection<File> files = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE); for (File file : files) { File parentFolder = file.getParentFile(); String parentName = parentFolder.getName(); String shortName = getSoShortName(file); Multimap<String, File> maps = result.get(parentName); if (null == maps) { maps = HashMultimap.create(10, 3); } maps.put(shortName, file); result.put(parentName, maps); } } return result; }
From source file:com.twosigma.beakerx.kernel.magic.command.ClasspathAddMvnDepsCellMagicCommandTest.java
private static void unzipRepo() { try {/*from ww w.j a va2 s . com*/ ZipFile zipFile = new ZipFile(BUILD_PATH + "/testMvnCache.zip"); Enumeration<?> enu = zipFile.entries(); while (enu.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enu.nextElement(); String name = BUILD_PATH + "/" + zipEntry.getName(); File file = new File(name); if (name.endsWith("/")) { file.mkdirs(); continue; } File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException { final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { final ZipArchiveEntry entry = entries.nextElement(); final File entryDestination = getDestinationFile(destination, entry.getName()); if (entry.isDirectory()) { entryDestination.mkdirs();/*from w ww . j a v a 2 s.com*/ } else { entryDestination.getParentFile().mkdirs(); final InputStream in = zipFile.getInputStream(entry); try (final OutputStream out = new FileOutputStream(entryDestination)) { IOUtils.copy(in, out); IOUtils.closeQuietly(in); } } } }
From source file:org.kairosdb.testclient.QueryTests.java
@SuppressWarnings("ConstantConditions") private static List<String> findTestDirectories(File directory, String matchingDirectoryName) { List<String> matchingDirectories = new ArrayList<String>(); for (File file : directory.listFiles()) { if (file.isDirectory()) { if (file.getParentFile().getName().equals(matchingDirectoryName)) { matchingDirectories.add(file.getName()); } else matchingDirectories.addAll(findTestDirectories(file, matchingDirectoryName)); }/* w ww .jav a 2 s . co m*/ } return matchingDirectories; }
From source file:com.codenvy.commons.lang.TarUtils.java
public static void untar(InputStream in, File targetDir) throws IOException { final TarArchiveInputStream tarIn = new TarArchiveInputStream(in); byte[] b = new byte[BUF_SIZE]; TarArchiveEntry tarEntry;/*from w ww. j ava2 s . c o m*/ while ((tarEntry = tarIn.getNextTarEntry()) != null) { final File file = new File(targetDir, tarEntry.getName()); if (tarEntry.isDirectory()) { file.mkdirs(); } else { final File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } try (FileOutputStream fos = new FileOutputStream(file)) { int r; while ((r = tarIn.read(b)) != -1) { fos.write(b, 0, r); } } } } }
From source file:com.scaniatv.LangFileUpdater.java
/** * Method that updates a custom lang file. * //w ww .j a v a2 s.c o m * @param stringArray * @param langFile */ public static void updateCustomLang(String stringArray, String langFile) { final StringBuilder sb = new StringBuilder(); final JSONArray array = new JSONArray(stringArray); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); sb.append("$.lang.register('" + obj.getString("id") + "', '" + sanitizeResponse(obj.getString("response")) + "');\n"); } try { langFile = CUSTOM_LANG_ROOT + langFile.replaceAll("\\\\", "/"); File file = new File(langFile); boolean exists = true; // Make sure the folder exists. if (!file.getParentFile().isDirectory()) { file.getParentFile().mkdirs(); } // This is used if we need to load the script or not. if (!file.exists()) { exists = false; } // Write the data. Files.write(Paths.get(langFile), sb.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); // If the script doesn't exist, load it. if (!exists) { ScriptManager.loadScript(file); } } catch (IOException ex) { com.gmt2001.Console.err.printStackTrace(ex); } }