Path getImageDirectory(ImageReference imageReference) {
    // Replace ':' and '@' with '!' to avoid directory-naming restrictions
    String replacedReference =
        imageReference.toStringWithQualifier().replace(':', '!').replace('@', '!');

    // Split image reference on '/' to build directory structure
    Iterable<String> directories = Splitter.on('/').split(replacedReference);
    Path destination = getImagesDirectory();
    for (String dir : directories) {
      destination = destination.resolve(dir);
    }
    return destination;
  }
Gets the directory corresponding to the given image reference.

@param imageReference the image reference
@return a path in the form of {@code
    (jib-cache)/images/registry[!port]/repository!(tag|digest-type!digest)}
jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageFiles.java