Class DefaultProtoLoader

java.lang.Object
io.protostuff.parser.DefaultProtoLoader
All Implemented Interfaces:
Proto.Loader
Direct Known Subclasses:
CachingProtoLoader

public class DefaultProtoLoader extends Object implements Proto.Loader
Default proto loader for imported protos.
  • Field Details

    • ALL

      protected static final int ALL
      See Also:
    • PROTO_PATH_ONLY

      protected static final int PROTO_PATH_ONLY
      See Also:
    • PROTO_PATH_AND_CLASSPATH

      protected static final int PROTO_PATH_AND_CLASSPATH
      See Also:
    • DEFAULT_PROTO_SEARCH_STRATEGY

      public static final int DEFAULT_PROTO_SEARCH_STRATEGY
      The default proto search strategy to use.
    • PATH_SEPARATOR

      public static final String PATH_SEPARATOR
      Standard JVM property. See https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
    • PATH_SEPARATOR_PROPERTY

      public static final String PATH_SEPARATOR_PROPERTY
      See Also:
    • PATH_SEPARATOR_DEFAULT

      private static final String PATH_SEPARATOR_DEFAULT
      See Also:
    • DEFAULT_INSTANCE

      public static final DefaultProtoLoader DEFAULT_INSTANCE
    • __protoLoadDirs

      private static final ArrayList<File> __protoLoadDirs
    • protoSearchStrategy

      protected final int protoSearchStrategy
  • Constructor Details

    • DefaultProtoLoader

      public DefaultProtoLoader()
    • DefaultProtoLoader

      public DefaultProtoLoader(int protoSearchStrategy)
  • Method Details

    • getDefaultInstance

      public static DefaultProtoLoader getDefaultInstance()
    • load

      public Proto load(String path, Proto importer) throws Exception
      Specified by:
      load in interface Proto.Loader
      Throws:
      Exception
    • searchFromProtoPathOnly

      protected Proto searchFromProtoPathOnly(String path, Proto importer) throws Exception
      Search from proto_path only. For full protoc compatibility, use this.

       Enable via:
       -Dproto_path=$path -Dproto_search_strategy=1
       
      Throws:
      Exception
    • searchFromProtoPathAndClasspath

      protected Proto searchFromProtoPathAndClasspath(String path, Proto importer) throws Exception
      Search from proto_path and classpath (in that order).

       Enable via:
       -Dproto_path=$path -Dproto_search_strategy=2
       
      Throws:
      Exception
    • searchFromAll

      protected Proto searchFromAll(String path, Proto importer) throws Exception
      Search from every possible resource. Also loads from a remote url (if path starts with http://).

       Search order is:
       1. relative path
       2. proto_path
       3. classpath
       
      Throws:
      Exception
    • getBaseDirFromPackagePath

      static File getBaseDirFromPackagePath(String path, Proto importer)
    • loadFromOtherResource

      protected Proto loadFromOtherResource(String path, Proto importer) throws Exception
      Throws:
      Exception
    • loadFrom

      protected Proto loadFrom(File file, Proto importer) throws Exception
      Throws:
      Exception
    • loadFrom

      protected Proto loadFrom(URL resource, Proto importer) throws Exception
      Throws:
      Exception
    • loadFromClasspath

      public static Proto loadFromClasspath(String path, Proto importer) throws Exception
      Loads a proto from the classpath.
      Throws:
      Exception
    • getResource

      public static URL getResource(String resource, Class<?> context)
      Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used.
    • getResource

      public static URL getResource(String resource, Class<?> context, boolean checkParent)
      Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used. If the flag checkParent is true, the classloader's parent is included in the lookup.