Class LocatorInputFactory

java.lang.Object
org.jvnet.basicjaxb.config.LocatorInputFactory

public class LocatorInputFactory extends Object
A factory to create an InputStream or Reader from a string locator. The locator represents either a classpath, a URL or a file.

Sample locators:

  • file:///PATH/src/main/resources/org/jvnet/basicjaxb/locator/messages.properties
  • file:src/main/resources/org/jvnet/basicjaxb/locator/messages.properties
  • classpath:/org/jvnet/basicjaxb/locator/messages.properties
  • classpath:messages.properties
  • /PATH/src/main/resources/org/jvnet/basicjaxb/locator/messages.properties
  • src/main/resources/org/jvnet/basicjaxb/locator/messages.properties
  • Field Details

    • PROTOCOL_CLASSPATH

      public static final String PROTOCOL_CLASSPATH
      Represents a URL protocol for a classpath lookup.
      See Also:
    • PROTOCOL_FILE

      public static final String PROTOCOL_FILE
      Represents a URL protocol for a file lookup.
      See Also:
  • Constructor Details

    • LocatorInputFactory

      public LocatorInputFactory()
  • Method Details

    • locatorExists

      public static boolean locatorExists(String locator) throws IOException
      Does the given locator exist. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the input stream will be located as a resource stream. This method uses a ClassLoader to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      Returns:
      True when an input stream can be created for the given locator; otherwise, false.
      Throws:
      IOException - If an error occurred when inputting from the stream.
    • locatorExists

      public static boolean locatorExists(String locator, Class<?> clazz) throws IOException
      Does the given locator exist. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the input stream will be located as a resource stream. If the class parameter is null, a ClassLoader is used to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      clazz - A classpath location for relative locators.
      Returns:
      True when an input stream can be created for the given locator and class; otherwise, false.
      Throws:
      IOException - If an error occurred when inputting from the stream.
    • createInputStream

      public static InputStream createInputStream(String locator) throws IOException
      Create input stream for the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the input stream will be located as a resource stream. This method uses a ClassLoader to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      Returns:
      An InputStream for the given locator.
      Throws:
      IOException - If an error occurred when inputting from the stream.
    • createInputStream

      public static InputStream createInputStream(String locator, Class<?> clazz) throws IOException
      Create input stream for the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the input stream will be located as a resource stream. If the class parameter is null, a ClassLoader is used to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      clazz - A classpath location for relative locators.
      Returns:
      An InputStream for the given locator and class.
      Throws:
      IOException - If an error occurred when inputting from the stream.
    • createReader

      public static Reader createReader(String locator) throws IOException
      Create reader with UTF-8 character encoding for the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the reader will be located as a resource stream. This method uses a ClassLoader to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      Returns:
      A Reader for the given locator.
      Throws:
      IOException - If an error occurred when inputting from the reader.
    • createReader

      public static Reader createReader(String locator, Class<?> clazz) throws IOException
      Create reader with UTF-8 character encoding for the given locator. The locator can represent a URL or a File. If the URL protocol is "classpath:" then the reader will be located as a resource stream. If the class parameter is null, a ClassLoader is used to resolve classpath resources; thus, a "classpath:" locator must provide the full path relative to the classpath root and any leading '/' will be ignored.
      Parameters:
      locator - The location of a file or resource.
      clazz - A classpath location for relative locators.
      Returns:
      A Reader for the given locator and class.
      Throws:
      IOException - If an error occurred when inputting from the reader.