public File getCurrentWorkingDirectory() { return new File(".").getAbsoluteFile(); }
@SuppressWarnings("ResultOfMethodCallIgnored") private static File toDirectory(String path) { if (path == null) { return null; } File f = new File(path); f.mkdirs(); if (!f.isDirectory()) { return null; } try { return f.getAbsoluteFile(); } catch (Exception ignored) { return f; } }
public AtomicFileOutputStream(File f) throws FileNotFoundException { // Code unfortunately must be duplicated below since we can't assign // anything // before calling super super(new FileOutputStream(new File(f.getParentFile(), f.getName() + TMP_EXTENSION))); origFile = f.getAbsoluteFile(); tmpFile = new File(f.getParentFile(), f.getName() + TMP_EXTENSION) .getAbsoluteFile(); }
public static File prepareFile(String filename) { File file = new File(filename); File parent = file.getAbsoluteFile().getParentFile(); if (!parent.exists()) { //noinspection ResultOfMethodCallIgnored parent.mkdirs(); } return file; }
/** * Returns true if this package is already installed * * @return true if this package is installed */ public boolean isInstalled() { File packageDir = new File(m_packageHome.getAbsoluteFile() + File.separator + m_packageMetaData.get("PackageName") + File.separator + "Description.props"); return (packageDir.exists()); }
protected void createSubDir(String propertyName, Path parent, String subDirName) { Path newPath = new Path(parent, subDirName); File newDir = new File(newPath.toString()).getAbsoluteFile(); if (deleteOnExit()) newDir.deleteOnExit(); conf.set(propertyName, newDir.getAbsolutePath()); }
@Override public File getParentFile(final File file) { File tmp = file.getAbsoluteFile().getParentFile(); if (tmp == null) { tmp = new File("."); // as a fix for bug #41474 we use "." if getParentFile returns null } return tmp; }
public GoPluginDescriptor build(File pluginJarFile, boolean isBundledPlugin) { if (!pluginJarFile.exists()) { throw new RuntimeException(String.format("Plugin jar does not exist: %s", pluginJarFile.getAbsoluteFile())); } try (JarFile jarFile = new JarFile(pluginJarFile)) { ZipEntry entry = jarFile.getEntry(PLUGIN_XML); if (entry == null) { return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin); } try (InputStream pluginXMLStream = jarFile.getInputStream(entry)) { return GoPluginDescriptorParser.parseXML(pluginXMLStream, pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin); } } catch (Exception e) { LOGGER.warn("Could not load plugin with jar filename:{}", pluginJarFile.getName(), e); String cause = e.getCause() != null ? String.format("%s. Cause: %s", e.getMessage(), e.getCause().getMessage()) : e.getMessage(); return GoPluginDescriptor.usingId(pluginJarFile.getName(), pluginJarFile.getAbsolutePath(), getBundleLocation(bundlePathLocation, pluginJarFile.getName()), isBundledPlugin) .markAsInvalid(Arrays.asList(String.format("Plugin with ID (%s) is not valid: %s", pluginJarFile.getName(), cause)), e); } }
static List<File> matchingFiles( File fileWithRegexInName ) { File parent = fileWithRegexInName.getAbsoluteFile().getParentFile(); if ( parent == null || !parent.exists() ) { throw new IllegalArgumentException( "Directory of " + fileWithRegexInName + " doesn't exist" ); } final Pattern pattern = Pattern.compile( fileWithRegexInName.getName() ); List<File> files = new ArrayList<>(); for ( File file : parent.listFiles() ) { if ( pattern.matcher( file.getName() ).matches() ) { files.add( file ); } } return files; }
public GraphDatabaseService newImpermanentDatabase( File storeDir ) { File absoluteDirectory = storeDir.getAbsoluteFile(); GraphDatabaseBuilder databaseBuilder = newImpermanentDatabaseBuilder( absoluteDirectory ); databaseBuilder.setConfig( GraphDatabaseSettings.active_database, absoluteDirectory.getName() ); databaseBuilder.setConfig( GraphDatabaseSettings.databases_root_path, absoluteDirectory.getParentFile().getAbsolutePath() ); return databaseBuilder.newGraphDatabase(); }
@Override public void loadConfigurationManager() throws Exception { if (RESOURCE_GROUPS_CONFIGURATION.exists()) { Map<String, String> properties = new HashMap<>(loadProperties(RESOURCE_GROUPS_CONFIGURATION)); String configurationManagerName = properties.remove(CONFIGURATION_MANAGER_PROPERTY_NAME); checkArgument(!isNullOrEmpty(configurationManagerName), "Resource groups configuration %s does not contain %s", RESOURCE_GROUPS_CONFIGURATION.getAbsoluteFile(), CONFIGURATION_MANAGER_PROPERTY_NAME); setConfigurationManager(configurationManagerName, properties); } }
if (!deobfMapFile.exists()) { return; LOG.info("Loading obfuscation map from: {}", deobfMapFile.getAbsoluteFile()); try { List<String> lines = FileUtils.readLines(deobfMapFile, MAP_FILE_CHARSET); LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.getAbsolutePath(), e);
private void writeTestFile(File file) { File parent = file.getAbsoluteFile().getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { logger.warn("Couldn't create directory: {}", parent); } } try (FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8.name())) { osw.append(sb); } catch (FileNotFoundException e) { logger.error("Failed to open test file ({}).", file, e); } catch (UnsupportedEncodingException e) { logger.error("Failed to open writer.", e); } catch (IOException e) { logger.error("Failed to write test file ({}).", file, e); } }
private void unzipApkFile(File file, File destFile) throws TinkerPatchException, IOException { String apkName = file.getName(); if (!apkName.endsWith(TypedValue.FILE_APK)) { throw new TinkerPatchException( String.format("input apk file path must end with .apk, yours %s\n", apkName) ); } String destPath = destFile.getAbsolutePath(); Logger.d("UnZipping apk to %s", destPath); FileOperation.unZipAPk(file.getAbsoluteFile().getAbsolutePath(), destPath); }
private void initCompletedTasks() { File completedTaskDir = getCompletedTaskDir(); log.info("Looking for any previously completed tasks on disk[%s].", completedTaskDir); completedTaskDir.mkdirs(); if (!completedTaskDir.isDirectory()) { throw new ISE("Completed Tasks Dir [%s] does not exist/not-a-directory.", completedTaskDir); } for (File taskFile : completedTaskDir.listFiles()) { try { String taskId = taskFile.getName(); TaskAnnouncement taskAnnouncement = jsonMapper.readValue(taskFile, TaskAnnouncement.class); if (taskId.equals(taskAnnouncement.getTaskId())) { completedTasks.put(taskId, taskAnnouncement); log.info("Found completed task[%s] with status[%s].", taskId, taskAnnouncement.getStatus()); } else { throw new ISE("Corrupted completed task on disk[%s].", taskFile.getAbsoluteFile()); } } catch (IOException ex) { throw new ISE(ex, "Failed to read completed task from disk at [%s]. Ignored.", taskFile.getAbsoluteFile()); } } }
@Test public void requestSQRestart_updates_shareMemory_file() throws IOException { File tmpDir = temp.newFolder().getAbsoluteFile(); settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath()); settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER); ProcessCommandWrapperImpl underTest = new ProcessCommandWrapperImpl(settings.asConfig()); underTest.requestSQRestart(); try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(tmpDir, PROCESS_NUMBER)) { assertThat(processCommands.askedForRestart()).isTrue(); } }
private String getAbsoluteName() { File f = getAbsoluteFile(); String name = f.getPath(); if (f.isDirectory() && name.charAt(name.length() - 1) != separatorChar) { // Directories must end with a slash name = name + "/"; } if (separatorChar != '/') { // Must convert slashes. name = name.replace(separatorChar, '/'); } return name; }
@Override public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { f = f.getAbsoluteFile(); mkdirs(f.getParentFile()); return new RemoteOutputStream(Files.newOutputStream(fileToPath(writing(f)))); } }
public static File prepareFile(String filename) { File file = new File(filename); File parent = file.getAbsoluteFile().getParentFile(); if (!parent.exists()) { //noinspection ResultOfMethodCallIgnored parent.mkdirs(); } return file; }
public static boolean isSymlink(File file) throws IOException { if (file == null) throw new NullPointerException("File must not be null"); File canon; if (file.getParent() == null) { canon = file; } else { File canonDir = file.getParentFile().getCanonicalFile(); canon = new File(canonDir, file.getName()); } return !canon.getCanonicalFile().equals(canon.getAbsoluteFile()); }