public InfoWriter(Configuration config, String infoPath) throws IOException { this.config = config; this.infoPath = infoPath; if (infoPath != null) { this.infoFile = new File(infoPath); if (!infoFile.getParentFile().exists()) { infoFile.getParentFile().mkdirs(); } } else { this.infoFile = null; } }
public CompressedFile(File file) { this.file = file; this.gz = new File(file.getParentFile(),file.getName()+".gz"); }
public static void ensureFileDirectory(File file) { if (file == null) { return; } File parentFile = file.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } }
public static boolean isSymbolicLink(File parent, String name) throws IOException { if (parent == null) { File f = new File(name); parent = f.getParentFile(); name = f.getName(); } File toTest = new File(parent.getCanonicalPath(), name); return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath()); }
public FileHandle parent () { File parent = file.getParentFile(); if (parent == null) { if (type == FileType.Absolute) parent = new File("/"); else parent = new File(""); } return new HeadlessFileHandle(parent, type); }
private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException { String classPath = manifest.getMainAttributes().getValue(attributeName); if(classPath==null) return; // attribute not found for (String s : classPath.split(separator)) { File file = resolve(archive, s); if(file.getName().contains("*")) { // handle wildcard FileSet fs = new FileSet(); File dir = file.getParentFile(); fs.setDir(dir); fs.setIncludes(file.getName()); for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { paths.add(new File(dir,included)); } } else { if(!file.exists()) throw new IOException("No such file: "+file); paths.add(file); } } }
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(); }
File file = new File("C:\\user\\Desktop\\dir1\\dir2\\filename.txt"); file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file);
@Override public void visit(File f, String relativePath) throws IOException { if (f.isFile()) { File target = new File(dest, relativePath); mkdirsE(target.getParentFile()); Path targetPath = fileToPath(writing(target)); exceptionEncountered = exceptionEncountered || !tryCopyWithAttributes(f, targetPath); if (exceptionEncountered) { Files.copy(fileToPath(f), targetPath, StandardCopyOption.REPLACE_EXISTING); if (!logMessageShown) { LOGGER.log(Level.INFO, "JENKINS-52325: Jenkins failed to retain attributes when copying to {0}, so proceeding without attributes.", dest.getAbsolutePath()); logMessageShown = true; } } count.incrementAndGet(); } } private boolean tryCopyWithAttributes(File f, Path targetPath) {
void openOutputStream_noParent(final boolean createFile) throws Exception { final File file = new File("test.txt"); assertNull(file.getParentFile()); try { if (createFile) { TestUtils.createLineBasedFile(file, new String[]{"Hello"}); } try (FileOutputStream out = FileUtils.openOutputStream(file)) { out.write(0); } assertTrue(file.exists()); } finally { if (!file.delete()) { file.deleteOnExit(); } } }
private static boolean createOrExistsFile(final File file) { if (file == null) return false; if (file.exists()) return file.isFile(); if (!createOrExistsDir(file.getParentFile())) return false; try { return file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } }
public static void createLineBasedFile(final File file, final String[] data) throws IOException { if (file.getParentFile() != null && !file.getParentFile().exists()) { throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); } try (final PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) { for (final String element : data) { output.println(element); } } }
@Before public void setUp() throws IOException { testDir = temporaryFolder.newFolder("testDir"); testFile = new File(testDir, "test.dat"); try (OutputStream outputStream = new FileOutputStream(testFile)) { outputStream.write(StringUtils.toUtf8(content)); } Assert.assertTrue(testFile.getParentFile().equals(testDir)); }
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 invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { symlinking(f); Util.createSymlink(f.getParentFile(), target, f.getName(), listener); return null; } }
public void streamToFile(InputStream stream, File dest) throws IOException { dest.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(dest, true); try { IOUtils.copyLarge(stream, out); } finally { IOUtils.closeQuietly(out); } }
public void on() { try { file.getParentFile().mkdirs(); Files.newOutputStream(file.toPath()).close(); get(); // update state } catch (IOException | InvalidPathException e) { LOGGER.log(Level.WARNING, "Failed to touch "+file); } }
private boolean checkFile(File file) { if (file.isFile()) { fileChooser.setCurrentDirectory(file.getParentFile()); return true; } else { String message = "File Not Found: "+file.getAbsolutePath(); displayError("File Not Found Error", message); return false; } }
public static void copyFile(InputStream from, File to) throws IOException { if (! to.getParentFile().exists()) { to.getParentFile().mkdirs(); } try (OutputStream os = new FileOutputStream(to)) { byte[] buffer = new byte[65536]; int count = from.read(buffer); while (count > 0) { os.write(buffer, 0, count); count = from.read(buffer); } } }
static public void main (String[] args) throws Exception { Settings settings = null; String input = null, output = null, packFileName = "pack.atlas"; switch (args.length) { case 4: settings = new Json().fromJson(Settings.class, new FileReader(args[3])); case 3: packFileName = args[2]; case 2: output = args[1]; case 1: input = args[0]; break; default: System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]"); System.exit(0); } if (output == null) { File inputFile = new File(input); output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath(); } if (settings == null) settings = new Settings(); process(settings, input, output, packFileName); } }