public static void checkCreateDirectoryOK ( Resource resource , boolean createParentWhenNotExists ) throws IOException { if ( resource . exists ( ) ) { if ( resource . isFile ( ) ) throw new IOException ( "can't create directory [" + resource . getPath ( ) + "], resource already exists as a file" ) ; if ( resource . isDirectory ( ) ) throw new IOException ( "can't create directory [" + resource . getPath ( ) + "], directory already exists" ) ; } Resource parent = resource . getParentResource ( ) ; // when there is a parent but the parent does not exist if ( parent != null ) { if ( ! parent . exists ( ) ) { if ( createParentWhenNotExists ) parent . createDirectory ( true ) ; else throw new IOException ( "can't create file [" + resource . getPath ( ) + "], missing parent directory" ) ; } else if ( parent . isFile ( ) ) { throw new IOException ( "can't create directory [" + resource . getPath ( ) + "], parent is a file" ) ; } } }
check if directory creation is ok with the rules for the Resource interface to not change this rules .