/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Creates and loads the extended properties from the specified file. * * @param file the filename to load * @param defaultFile a second filename to load default values from * @throws IOException if a file error occurs */ public ExtendedProperties(String file, String defaultFile) throws IOException { this.file = file; basePath = new File(file).getAbsolutePath(); basePath = basePath.substring(0, basePath.lastIndexOf(fileSeparator) + 1); FileInputStream in = null; try { in = new FileInputStream(file); this.load(in); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) {} } if (defaultFile != null) { defaults = new ExtendedProperties(defaultFile); } }
/** * Creates and loads the extended properties from the specified file. * * @param file the filename to load * @param defaultFile a second filename to load default values from * @throws IOException if a file error occurs */ public ExtendedProperties(String file, String defaultFile) throws IOException { this.file = file; basePath = new File(file).getAbsolutePath(); basePath = basePath.substring(0, basePath.lastIndexOf(fileSeparator) + 1); FileInputStream in = null; try { in = new FileInputStream(file); this.load(in); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) {} } if (defaultFile != null) { defaults = new ExtendedProperties(defaultFile); } }
load(new FileInputStream(file));
load(new FileInputStream(file));
public void testTrailingBackSlash() { ExtendedProperties ep1 = new ExtendedProperties(); try { /* initialize using: one=ONE two=TWO \\ three=THREE */ String s1 = "one=ONE\ntwo=TWO \\\\\nthree=THREE"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals("Trailing back-slashes not interpreted properly", 3, ep1.size()); assertEquals("Back-slash not escaped properly", "TWO \\", ep1.getString("two")); } catch (IOException ioe) { fail("There was an exception loading the EP"); } }
public void testMultipleSameKey1() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a one=b,c */ String s1 = "one=a\none=b,c\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals(3, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); }
public void testMultipleSameKey3() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a,b one=c */ String s1 = "one=a,b\none=c\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals(3, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); }
public void testMultipleSameKey2() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a,b one=c,d */ String s1 = "one=a,b\none=c,d\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(4, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals("d", ep1.getVector("one").get(3)); assertEquals(4, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); assertEquals("d", ep1.getList("one").get(3)); }
byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals("Back-slashes not interpreted properly", "Hello\\World", ep1.getString("one")); bytes = baos.toByteArray(); bais = new ByteArrayInputStream(bytes); ep2.load(bais); assertEquals("Back-slash not same after being saved and loaded", ep1.getString("one"), ep2.getString("one"));
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Load the properties from the given input stream. * * @param input the InputStream to load from * @throws IOException if an IO error occurs */ public void load(InputStream input) throws IOException { load(input, null); }
/** * Initializes the Velocity Runtime with properties file. * The properties file may be in the file system proper, * or the properties file may be in the classpath. */ private void setDefaultProperties() { try { InputStream inputStream = getClass() .getResourceAsStream('/' + DEFAULT_RUNTIME_PROPERTIES); configuration.load( inputStream ); info ("Default Properties File: " + new File(DEFAULT_RUNTIME_PROPERTIES).getPath()); } catch (IOException ioe) { System.err.println("Cannot get Velocity Runtime default properties!"); } }
/** * @param resourcePath Path of overlapping properties files * @param classLoader Class loader where the resources are loaded * @return ExtendedProperties result * @throws IOException */ public static ExtendedProperties loadFromOverlappingResources( String resourcePath, ClassLoader classLoader ) throws IOException { Validate.notNull( resourcePath, "Resource path can't be NULL" ); Validate.notNull( classLoader, "ClassLoader can't be NULL" ); ExtendedProperties props = new ExtendedProperties(); Enumeration<URL> resources = classLoader.getResources( resourcePath ); while ( resources.hasMoreElements() ) { InputStream resource = resources.nextElement().openStream(); try { props.load( resource ); } finally { resource.close(); } } return props; }
/** * Creates and loads the extended properties from the specified file. * * @param file the filename to load * @param defaultFile a second filename to load default values from * @throws IOException if a file error occurs */ public ExtendedProperties(String file, String defaultFile) throws IOException { this.file = file; basePath = new File(file).getAbsolutePath(); basePath = basePath.substring(0, basePath.lastIndexOf(fileSeparator) + 1); FileInputStream in = null; try { in = new FileInputStream(file); this.load(in); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) {} } if (defaultFile != null) { defaults = new ExtendedProperties(defaultFile); } }
/** * Loads an extended property file and performs unescaping of "," and "=" entries.<p> * * @param stream the input stream to read the properties from * * @return the initialized extended properties * * @throws IOException in case of IO errors */ public static ExtendedProperties loadProperties(InputStream stream) throws IOException { ExtendedProperties properties = new ExtendedProperties(); properties.load(stream); unescapeProperties(properties); return properties; }