Package org.jvnet.basicjaxb.config
Class LocatorInputFactory
java.lang.Object
org.jvnet.basicjaxb.config.LocatorInputFactory
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamcreateInputStream(String locator) Create input stream for the given locator.static InputStreamcreateInputStream(String locator, Class<?> clazz) Create input stream for the given locator.static ReadercreateReader(String locator) Create reader with UTF-8 character encoding for the given locator.static ReadercreateReader(String locator, Class<?> clazz) Create reader with UTF-8 character encoding for the given locator.static booleanlocatorExists(String locator) Does the given locator exist.static booleanlocatorExists(String locator, Class<?> clazz) Does the given locator exist.
-
Field Details
-
PROTOCOL_CLASSPATH
Represents a URL protocol for a classpath lookup.- See Also:
-
PROTOCOL_FILE
Represents a URL protocol for a file lookup.- See Also:
-
-
Constructor Details
-
LocatorInputFactory
public LocatorInputFactory()
-
-
Method Details
-
locatorExists
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
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
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
InputStreamfor the given locator. - Throws:
IOException- If an error occurred when inputting from the stream.
-
createInputStream
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
InputStreamfor the given locator and class. - Throws:
IOException- If an error occurred when inputting from the stream.
-
createReader
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
Readerfor the given locator. - Throws:
IOException- If an error occurred when inputting from the reader.
-
createReader
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
Readerfor the given locator and class. - Throws:
IOException- If an error occurred when inputting from the reader.
-