@Test public void testResource() throws Exception { FlexibleConfigurationSourceProvider provider = new FlexibleConfigurationSourceProvider(); byte[] bytes = ByteStreams.toByteArray(provider.open("|package/test-file.txt")); Assert.assertArrayEquals("one\ntwo\nthree\n".getBytes(), bytes); }
@Override public InputStream open(String value) throws IOException { InputStream stream = null; do { if ( value.startsWith(stringPrefix) ) { log.info("Configuration argument is a string literal"); String str = (value.length() > stringPrefix.length()) ? value.substring(stringPrefix.length()) : ""; stream = new ByteArrayInputStream(str.getBytes("UTF-8")); break; } if ( value.contains(resourceSeparator) ) { List<String> parts = Splitter.on(resourceSeparator).trimResults().limit(2).splitToList(value); if ( parts.size() == 2 ) { String pathname = parts.get(0); File filePart = new File(pathname); String resourcePart = parts.get(1); if ( (pathname.length() > 0) && filePart.exists() ) { value = filePart.getCanonicalPath(); log.info("Using " + value + " for configuration"); } else { log.info("Using " + resourcePart + " for configuration"); URL resource = Resources.getResource(resourcePart); stream = resource.openStream(); } } } } while ( false ); return (stream != null) ? stream : super.open(value); }
FlexibleConfigurationSourceProvider extends FileConfigurationSourceProvider { @Override public InputStream open(String value) throws IOException { InputStream stream = null; do { if ( value.startsWith(stringPrefix) ) { log.info("Configuration argument is a string literal"); String str = (value.length() > stringPrefix.length()) ? value.substring(stringPrefix.length()) : ""; stream = new ByteArrayInputStream(str.getBytes("UTF-8")); break; } if ( value.contains(resourceSeparator) ) { List<String> parts = Splitter.on(resourceSeparator).trimResults().limit(2).splitToList(value); if ( parts.size() == 2 ) { String pathname = parts.get(0); File filePart = new File(pathname); String resourcePart = parts.get(1); if ( (pathname.length() > 0) && filePart.exists() ) { value = filePart.getCanonicalPath(); log.info("Using " + value + " for configuration"); } else { log.info("Using " + resourcePart + " for configuration"); URL resource = Resources.getResource(resourcePart); stream = resource.openStream(); } } } } while ( false ); return (stream != null) ? stream : super.open(value); } }
FlexibleConfigurationSourceProvider extends FileConfigurationSourceProvider { @Override public InputStream open(String value) throws IOException { InputStream stream = null; do { if ( value.startsWith(stringPrefix) ) { log.info("Configuration argument is a string literal"); String str = (value.length() > stringPrefix.length()) ? value.substring(stringPrefix.length()) : ""; stream = new ByteArrayInputStream(str.getBytes("UTF-8")); break; } if ( value.contains(resourceSeparator) ) { List<String> parts = Splitter.on(resourceSeparator).trimResults().limit(2).splitToList(value); if ( parts.size() == 2 ) { String pathname = parts.get(0); File filePart = new File(pathname); String resourcePart = parts.get(1); if ( (pathname.length() > 0) && filePart.exists() ) { value = filePart.getCanonicalPath(); log.info("Using " + value + " for configuration"); } else { log.info("Using " + resourcePart + " for configuration"); URL resource = Resources.getResource(resourcePart); stream = resource.openStream(); } } } } while ( false ); return (stream != null) ? stream : super.open(value); } FlexibleConfigurationSourceProvider();  FlexibleConfigurationSourceProvider(String resourceSeparator, String stringPrefix); }
FlexibleConfigurationSourceProvider extends FileConfigurationSourceProvider { @Override public InputStream open(String value) throws IOException { InputStream stream = null; do { if ( value.startsWith(stringPrefix) ) { log.info("Configuration argument is a string literal"); String str = (value.length() > stringPrefix.length()) ? value.substring(stringPrefix.length()) : ""; stream = new ByteArrayInputStream(str.getBytes("UTF-8")); break; } if ( value.contains(resourceSeparator) ) { List<String> parts = Splitter.on(resourceSeparator).trimResults().limit(2).splitToList(value); if ( parts.size() == 2 ) { String pathname = parts.get(0); File filePart = new File(pathname); String resourcePart = parts.get(1); if ( (pathname.length() > 0) && filePart.exists() ) { value = filePart.getCanonicalPath(); log.info("Using " + value + " for configuration"); } else { log.info("Using " + resourcePart + " for configuration"); URL resource = Resources.getResource(resourcePart); stream = resource.openStream(); } } } } while ( false ); return (stream != null) ? stream : super.open(value); } FlexibleConfigurationSourceProvider();  FlexibleConfigurationSourceProvider(String resourceSeparator, String stringPrefix); @Override InputStream open(String value); }
FlexibleConfigurationSourceProvider extends FileConfigurationSourceProvider { @Override public InputStream open(String value) throws IOException { InputStream stream = null; do { if ( value.startsWith(stringPrefix) ) { log.info("Configuration argument is a string literal"); String str = (value.length() > stringPrefix.length()) ? value.substring(stringPrefix.length()) : ""; stream = new ByteArrayInputStream(str.getBytes("UTF-8")); break; } if ( value.contains(resourceSeparator) ) { List<String> parts = Splitter.on(resourceSeparator).trimResults().limit(2).splitToList(value); if ( parts.size() == 2 ) { String pathname = parts.get(0); File filePart = new File(pathname); String resourcePart = parts.get(1); if ( (pathname.length() > 0) && filePart.exists() ) { value = filePart.getCanonicalPath(); log.info("Using " + value + " for configuration"); } else { log.info("Using " + resourcePart + " for configuration"); URL resource = Resources.getResource(resourcePart); stream = resource.openStream(); } } } } while ( false ); return (stream != null) ? stream : super.open(value); } FlexibleConfigurationSourceProvider();  FlexibleConfigurationSourceProvider(String resourceSeparator, String stringPrefix); @Override InputStream open(String value); static final String DEFAULT_RESOURCE_SEPARATOR; static final String DEFAULT_STRING_PREFIX; }