Class ModuleReaderProxy

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class ModuleReaderProxy
    extends java.lang.Object
    implements java.io.Closeable
    A ModuleReader proxy, written using reflection to preserve backwards compatibility with JDK 7 and 8.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.Class<?> collectorClass
      Class collectorClass = Class.forName("java.util.stream.Collector");
      private static java.lang.Object collectorsToList
      Collector> collectorsToList = Collectors.toList();
      private java.lang.AutoCloseable moduleReader
      The module reader.
      private ReflectionUtils reflectionUtils  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Calls ModuleReader#close().
      java.net.URI find​(java.lang.String path)
      Use the proxied ModuleReader to find the named resource as a URI.
      java.util.List<java.lang.String> list()
      Get the list of resources accessible to a ModuleReader.
      java.io.InputStream open​(java.lang.String path)
      Use the proxied ModuleReader to open the named resource as an InputStream.
      java.nio.ByteBuffer read​(java.lang.String path)
      Use the proxied ModuleReader to open the named resource as a ByteBuffer.
      void release​(java.nio.ByteBuffer byteBuffer)
      Release a ByteBuffer allocated by calling read(String).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • moduleReader

        private final java.lang.AutoCloseable moduleReader
        The module reader.
      • collectorClass

        private static java.lang.Class<?> collectorClass
        Class collectorClass = Class.forName("java.util.stream.Collector");
      • collectorsToList

        private static java.lang.Object collectorsToList
        Collector> collectorsToList = Collectors.toList();
    • Constructor Detail

      • ModuleReaderProxy

        ModuleReaderProxy​(ModuleRef moduleRef)
                   throws java.io.IOException
        Constructor.
        Parameters:
        moduleRef - the module ref
        Throws:
        java.io.IOException - If an I/O exception occurs.
    • Method Detail

      • close

        public void close()
        Calls ModuleReader#close().
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • list

        public java.util.List<java.lang.String> list()
                                              throws java.lang.SecurityException
        Get the list of resources accessible to a ModuleReader. From the documentation for ModuleReader#list(): "Whether the stream of elements includes names corresponding to directories in the module is module reader specific. In lazy implementations then an IOException may be thrown when using the stream to list the module contents. If this occurs then the IOException will be wrapped in an java.io.UncheckedIOException and thrown from the method that caused the access to be attempted. SecurityException may also be thrown when using the stream to list the module contents and access is denied by the security manager."
        Returns:
        A list of the paths of resources in the module.
        Throws:
        java.lang.SecurityException - If the module cannot be accessed.
      • open

        public java.io.InputStream open​(java.lang.String path)
                                 throws java.lang.SecurityException
        Use the proxied ModuleReader to open the named resource as an InputStream.
        Parameters:
        path - The path to the resource to open.
        Returns:
        An InputStream for the content of the resource.
        Throws:
        java.lang.SecurityException - If the module cannot be accessed.
        java.lang.IllegalArgumentException - If the module cannot be accessed.
      • read

        public java.nio.ByteBuffer read​(java.lang.String path)
                                 throws java.lang.SecurityException,
                                        java.lang.OutOfMemoryError
        Use the proxied ModuleReader to open the named resource as a ByteBuffer. Call release(ByteBuffer) when you have finished with the ByteBuffer.
        Parameters:
        path - The path to the resource to open.
        Returns:
        A ByteBuffer for the content of the resource.
        Throws:
        java.lang.SecurityException - If the module cannot be accessed.
        java.lang.OutOfMemoryError - if the resource is larger than 2GB, the maximum capacity of a byte buffer.
      • release

        public void release​(java.nio.ByteBuffer byteBuffer)
        Release a ByteBuffer allocated by calling read(String).
        Parameters:
        byteBuffer - The ByteBuffer to release.
      • find

        public java.net.URI find​(java.lang.String path)
        Use the proxied ModuleReader to find the named resource as a URI.
        Parameters:
        path - The path to the resource to open.
        Returns:
        A URI for the resource.
        Throws:
        java.lang.SecurityException - If the module cannot be accessed.