Search in sources :

Example 6 with Resource

use of org.drools.compiler.compiler.io.Resource in project drools by kiegroup.

the class MemoryFileSystem method copyFolder.

private static int copyFolder(MemoryFileSystem srcMfs, Folder srcFolder, MemoryFileSystem trgMfs, Folder trgFolder, int count, String... filters) {
    if (!trgFolder.exists()) {
        trgMfs.getFolder(trgFolder.getPath()).create();
    }
    if (srcFolder != null) {
        for (Resource rs : srcFolder.getMembers()) {
            if (rs instanceof Folder) {
                count = copyFolder(srcMfs, (Folder) rs, trgMfs, trgFolder.getFolder(((Folder) rs).getName()), count, filters);
            } else {
                MemoryFile trgFile = (MemoryFile) trgFolder.getFile(((org.drools.compiler.compiler.io.File) rs).getName());
                boolean accept = false;
                if (filters == null || filters.length == 0) {
                    accept = true;
                } else {
                    for (String filter : filters) {
                        if (trgFile.getName().endsWith(filter)) {
                            accept = true;
                            break;
                        }
                    }
                }
                if (accept) {
                    try {
                        trgMfs.setFileContents(trgFile, srcMfs.getFileContents((MemoryFile) rs));
                        count++;
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
    return count;
}
Also used : Resource(org.drools.compiler.compiler.io.Resource) IOException(java.io.IOException) Folder(org.drools.compiler.compiler.io.Folder) ZipFile(java.util.zip.ZipFile) File(org.drools.compiler.compiler.io.File)

Aggregations

Folder (org.drools.compiler.compiler.io.Folder)6 Resource (org.drools.compiler.compiler.io.Resource)6 IOException (java.io.IOException)4 File (org.drools.compiler.compiler.io.File)3 ZipFile (java.util.zip.ZipFile)2 ZipEntry (java.util.zip.ZipEntry)1 MemoryFile (org.drools.compiler.compiler.io.memory.MemoryFile)1