package de.dhbwstuttgart.environment;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public interface IByteArrayClassLoader {

    Class<?> loadClass(String path) throws ClassNotFoundException;

    default Class<?> loadClass(byte[] code) {
        return this.loadClass(null, code);
    }

    default Class<?> loadClass(String name, byte[] code) {
        return this._defineClass(name, code, 0, code.length);
    }

    default Class<?> loadClass(Path path) throws IOException {
        var code = Files.readAllBytes(path);
        return this._defineClass(null, code, 0, code.length);
    }

    public Class<?> findClass(String name) throws ClassNotFoundException;

    Class<?> _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError;
}
