Example usage for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getContents

List of usage examples for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getContents

Introduction

In this page you can find the example usage for org.springframework.boot.devtools.restart.classloader ClassLoaderFile getContents.

Prototype

public byte[] getContents() 

Source Link

Document

Return the contents of the file as a byte array or null if #getKind() is Kind#DELETED .

Usage

From source file:org.springframework.boot.devtools.restart.classloader.RestartClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    String path = name.replace('.', '/').concat(".class");
    final ClassLoaderFile file = this.updatedFiles.getFile(path);
    if (file == null) {
        return super.findClass(name);
    }/*from   w  ww  .jav  a2s  .  c  om*/
    if (file.getKind() == Kind.DELETED) {
        throw new ClassNotFoundException(name);
    }
    return AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
        @Override
        public Class<?> run() {
            byte[] bytes = file.getContents();
            return defineClass(name, bytes, 0, bytes.length);
        }
    });
}

From source file:org.springframework.boot.devtools.restart.server.RestartServer.java

private boolean updateFileSystem(URL url, String name, ClassLoaderFile classLoaderFile) {
    if (!isFolderUrl(url.toString())) {
        return false;
    }//from   w  w w .j a va 2  s.  c  om
    try {
        File folder = ResourceUtils.getFile(url);
        File file = new File(folder, name);
        if (file.exists() && file.canWrite()) {
            if (classLoaderFile.getKind() == Kind.DELETED) {
                return file.delete();
            }
            FileCopyUtils.copy(classLoaderFile.getContents(), file);
            return true;
        }
    } catch (IOException ex) {
        // Ignore
    }
    return false;
}