Search in sources :

Example 1 with DyvilModifiers

use of dyvil.annotation.internal.DyvilModifiers in project Dyvil by Dyvil.

the class FileUtils method create.

@DyvilModifiers(Modifiers.INFIX)
public static void create(@NonNull File file) throws IOException {
    if (file.exists()) {
        return;
    }
    final File parent = file.getParentFile();
    if (parent != null && !parent.exists() && !parent.mkdirs()) {
        throw new IOException("Could not create parent directory: " + parent);
    }
    // noinspection ResultOfMethodCallIgnored
    file.createNewFile();
}
Also used : IOException(java.io.IOException) File(java.io.File) DyvilModifiers(dyvil.annotation.internal.DyvilModifiers)

Example 2 with DyvilModifiers

use of dyvil.annotation.internal.DyvilModifiers in project Dyvil by Dyvil.

the class FileUtils method readLines.

@DyvilModifiers(Modifiers.INFIX)
@NonNull
public static List<@NonNull String> readLines(@NonNull File file) throws IOException {
    try (BufferedReader reader = Files.newBufferedReader(file.toPath())) {
        final List<String> result = new ArrayList<>();
        for (; ; ) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            result.add(line);
        }
        return result;
    }
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(dyvil.collection.mutable.ArrayList) NonNull(dyvil.annotation.internal.NonNull) DyvilModifiers(dyvil.annotation.internal.DyvilModifiers)

Example 3 with DyvilModifiers

use of dyvil.annotation.internal.DyvilModifiers in project Dyvil by Dyvil.

the class ObjectReflection method copyFields.

@DyvilModifiers(Modifiers.INFIX)
public static <T> void copyFields(@NonNull T from, T to) {
    try {
        Class<?> c = from.getClass();
        do {
            for (Field f : c.getDeclaredFields()) {
                if ((f.getModifiers() & Modifiers.STATIC) == 0) {
                    f.setAccessible(true);
                    f.set(to, f.get(from));
                }
            }
            c = c.getSuperclass();
        } while (c != null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) DyvilModifiers(dyvil.annotation.internal.DyvilModifiers)

Aggregations

DyvilModifiers (dyvil.annotation.internal.DyvilModifiers)3 NonNull (dyvil.annotation.internal.NonNull)1 ArrayList (dyvil.collection.mutable.ArrayList)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1