/** Returns true if this file is a directory. Always returns false for classpath files. On Android, an FileType#Internal handle * to an empty directory will return false. On the desktop, an FileType#Internal handle to a directory on the classpath will * return false. */ public boolean isDirectory () { if (type == FileType.Classpath) return false; return file().isDirectory(); }
/** Returns the last modified time in milliseconds for this file. Zero is returned if the file doesn't exist. Zero is returned * for {@link FileType#Classpath} files. On Android, zero is returned for FileType#Internal files. On the desktop, zero is * returned for FileType#Internal files on the classpath. */ public long lastModified () { return file().lastModified(); }
/** Returns true if this file is a directory. Always returns false for classpath files. On Android, an FileType#Internal handle * to an empty directory will return false. On the desktop, an FileType#Internal handle to a directory on the classpath will * return false. */ public boolean isDirectory () { if (type == FileType.Classpath) return false; return file().isDirectory(); }
/** Returns the last modified time in milliseconds for this file. Zero is returned if the file doesn't exist. Zero is returned * for {@link FileType#Classpath} files. On Android, zero is returned for FileType#Internal files. On the desktop, zero is * returned for FileType#Internal files on the classpath. */ public long lastModified () { return file().lastModified(); }
/** Deletes this file or empty directory and returns success. Will not delete a directory that has children. * @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean delete () { if (type == FileType.Classpath) throw new RuntimeException("Cannot delete a classpath file: " + file); return file().delete(); }
/** Deletes this file or empty directory and returns success. Will not delete a directory that has children. * @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean delete () { if (type == FileType.Classpath) throw new RuntimeException("Cannot delete a classpath file: " + file); return file().delete(); }
/** @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean mkdirs () { if (type == FileType.Classpath) throw new RuntimeException("Cannot mkdirs with a classpath file: " + file); return file().mkdirs(); }
/** @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean mkdirs () { if (type == FileType.Classpath) throw new RuntimeException("Cannot mkdirs with a classpath file: " + file); return file().mkdirs(); }
/** Returns true if the file exists. On Android, a {@link FileType#Classpath} or FileType#Internal handle to a directory will * always return false. */ public boolean exists () { if (type == FileType.Classpath) return FileDescriptor.class.getResource("/" + file.getPath().replace('\\', '/')) != null; return file().exists(); }
/** Returns true if the file exists. On Android, a {@link FileType#Classpath} or FileType#Internal handle to a directory will * always return false. */ public boolean exists () { if (type == FileType.Classpath) return FileDescriptor.class.getResource("/" + file.getPath().replace('\\', '/')) != null; return file().exists(); }
/** Deletes this file or directory and all children, recursively. * @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean deleteDirectory () { if (type == FileType.Classpath) throw new RuntimeException("Cannot delete a classpath file: " + file); return deleteDirectory(file()); }
/** Deletes this file or directory and all children, recursively. * @throw RuntimeException if this file handle is a {@link FileType#Classpath} or FileType#Internal file. */ public boolean deleteDirectory () { if (type == FileType.Classpath) throw new RuntimeException("Cannot delete a classpath file: " + file); return deleteDirectory(file()); }
/** Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a * directory. On the desktop, an FileType#Internal handle to a directory on the classpath will return a zero length array. * @throw RuntimeException if this file is an {@link FileType#Classpath} file. */ public FileDescriptor[] list () { if (type == FileType.Classpath) throw new RuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileDescriptor[0]; FileDescriptor[] handles = new FileDescriptor[relativePaths.length]; for (int i = 0, n = relativePaths.length; i < n; i++) handles[i] = child(relativePaths[i]); return handles; }
/** Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a * directory. On the desktop, an FileType#Internal handle to a directory on the classpath will return a zero length array. * @throw RuntimeException if this file is an {@link FileType#Classpath} file. */ public FileDescriptor[] list () { if (type == FileType.Classpath) throw new RuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileDescriptor[0]; FileDescriptor[] handles = new FileDescriptor[relativePaths.length]; for (int i = 0, n = relativePaths.length; i < n; i++) handles[i] = child(relativePaths[i]); return handles; }
/** Returns a stream for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throw RuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * FileType#Internal file, or if it could not be written. */ public OutputStream write (boolean append) { if (type == FileType.Classpath) throw new RuntimeException("Cannot write to a classpath file: " + file); parent().mkdirs(); try { return new FileOutputStream(file(), append); } catch (FileNotFoundException ex) { if (file().isDirectory()) throw new RuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
/** Execute the Ant script file with the given parameters. * @param buildFile * @param params * @return whether the Ant succeeded */ public static boolean executeAnt (String buildFile, String params) { FileDescriptor build = new FileDescriptor(buildFile); String ant = System.getProperty("os.name").contains("Windows") ? "ant.bat" : "ant"; String command = ant + " -f \"" + build.file().getAbsolutePath() + "\" " + params; System.out.println("Executing '" + command + "'"); return startProcess(command, build.parent().file()); }
/** Returns a stream for writing to this file. Parent directories will be created if necessary. * @param append If false, this file will be overwritten if it exists, otherwise it will be appended. * @throw RuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or * FileType#Internal file, or if it could not be written. */ public OutputStream write (boolean append) { if (type == FileType.Classpath) throw new RuntimeException("Cannot write to a classpath file: " + file); parent().mkdirs(); try { return new FileOutputStream(file(), append); } catch (FileNotFoundException ex) { if (file().isDirectory()) throw new RuntimeException("Cannot open a stream to a directory: " + file + " (" + type + ")", ex); throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex); } }
/** Execute the Ant script file with the given parameters. * @param buildFile * @param params * @return whether the Ant succeeded */ public static boolean executeAnt (String buildFile, String params) { FileDescriptor build = new FileDescriptor(buildFile); String ant = System.getProperty("os.name").contains("Windows") ? "ant.bat" : "ant"; String command = ant + " -f \"" + build.file().getAbsolutePath() + "\" " + params; System.out.println("Executing '" + command + "'"); return startProcess(command, build.parent().file()); }
/** Execute ndk-build in the given directory * @param directory */ public static void executeNdk (String directory) { FileDescriptor build = new FileDescriptor(directory); String command = "ndk-build"; startProcess(command, build.file()); }
/** Execute ndk-build in the given directory * @param directory */ public static void executeNdk (String directory) { FileDescriptor build = new FileDescriptor(directory); String command = "ndk-build"; startProcess(command, build.file()); }