dev.rikka.tools.materialthemebuilder.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-plugin Show documentation
Show all versions of gradle-plugin Show documentation
A gradle plugin that generates Material Design 3 themes for Android projects.
The newest version!
package dev.rikka.tools.materialthemebuilder;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class Util {
public static String capitalize(String val) {
char[] arr = val.toCharArray();
arr[0] = Character.toUpperCase(arr[0]);
return new String(arr);
}
public static void createFile(File file) throws IOException {
if (!file.exists()) {
if (!file.getParentFile().exists()) {
if (!file.getParentFile().mkdirs()) {
throw new IOException("Failed to create " + file.getParentFile());
}
}
if (!file.createNewFile()) {
throw new IOException("Failed to create " + file);
}
}
}
public static void clearDir(File dir) {
try {
Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
} catch (Throwable ignored) {
}
}
}