@Test public void shouldLoadProperties() { Properties props = PropertiesStoreUtils.loadProperties("inputFolder=/home/karel4/one;name=- PROCESS NAME - ;outputFolder=/home/karel4/two"); Assert.assertTrue(props.size() == 3); Assert.assertEquals(props.getProperty("inputFolder"), "/home/karel4/one"); Assert.assertEquals(props.getProperty("outputFolder"), "/home/karel4/two"); Assert.assertEquals(props.getProperty("name"), "- PROCESS NAME - "); }
public static Properties loadProperties(String str) { List<Character> mustBeEscaped = Arrays.asList(new Character('\\'),new Character(';')); List<String> tokens = new ArrayList<String>(); StringWriter processWriter = new StringWriter(); Stack<Character> stckChars = new Stack<Character>(); char[] charArray = str.toCharArray(); for (int i = charArray.length-1; i >=0; i--) { stckChars.push(new Character(charArray[i])); } while(!stckChars.isEmpty()) { Character cChar = stckChars.pop(); if ((cChar.equals(new Character('\\')) && (!stckChars.isEmpty()) && (mustBeEscaped.contains(stckChars.peek())))) { processWriter.write(stckChars.pop()); } else if (cChar.equals(new Character(';'))){ tokens.add(processWriter.toString()); processWriter = new StringWriter(); } else { processWriter.write(cChar); } } tokens.add(processWriter.toString()); Properties props = new Properties(); for (String token : tokens) { if (token.indexOf("=") > 0) { String[] vals = token.split("="); if (vals.length == 2) { String key = vals[0]; String val = vals[1]; props.put(key, val); } else { LOGGER.warning("no eq character in token '"+token+"'"); } } } return props; }
PropertiesStoreUtils { public static Properties loadProperties(String str) { List<Character> mustBeEscaped = Arrays.asList(new Character('\\'),new Character(';')); List<String> tokens = new ArrayList<String>(); StringWriter processWriter = new StringWriter(); Stack<Character> stckChars = new Stack<Character>(); char[] charArray = str.toCharArray(); for (int i = charArray.length-1; i >=0; i--) { stckChars.push(new Character(charArray[i])); } while(!stckChars.isEmpty()) { Character cChar = stckChars.pop(); if ((cChar.equals(new Character('\\')) && (!stckChars.isEmpty()) && (mustBeEscaped.contains(stckChars.peek())))) { processWriter.write(stckChars.pop()); } else if (cChar.equals(new Character(';'))){ tokens.add(processWriter.toString()); processWriter = new StringWriter(); } else { processWriter.write(cChar); } } tokens.add(processWriter.toString()); Properties props = new Properties(); for (String token : tokens) { if (token.indexOf("=") > 0) { String[] vals = token.split("="); if (vals.length == 2) { String key = vals[0]; String val = vals[1]; props.put(key, val); } else { LOGGER.warning("no eq character in token '"+token+"'"); } } } return props; } }
PropertiesStoreUtils { public static Properties loadProperties(String str) { List<Character> mustBeEscaped = Arrays.asList(new Character('\\'),new Character(';')); List<String> tokens = new ArrayList<String>(); StringWriter processWriter = new StringWriter(); Stack<Character> stckChars = new Stack<Character>(); char[] charArray = str.toCharArray(); for (int i = charArray.length-1; i >=0; i--) { stckChars.push(new Character(charArray[i])); } while(!stckChars.isEmpty()) { Character cChar = stckChars.pop(); if ((cChar.equals(new Character('\\')) && (!stckChars.isEmpty()) && (mustBeEscaped.contains(stckChars.peek())))) { processWriter.write(stckChars.pop()); } else if (cChar.equals(new Character(';'))){ tokens.add(processWriter.toString()); processWriter = new StringWriter(); } else { processWriter.write(cChar); } } tokens.add(processWriter.toString()); Properties props = new Properties(); for (String token : tokens) { if (token.indexOf("=") > 0) { String[] vals = token.split("="); if (vals.length == 2) { String key = vals[0]; String val = vals[1]; props.put(key, val); } else { LOGGER.warning("no eq character in token '"+token+"'"); } } } return props; }  }
PropertiesStoreUtils { public static Properties loadProperties(String str) { List<Character> mustBeEscaped = Arrays.asList(new Character('\\'),new Character(';')); List<String> tokens = new ArrayList<String>(); StringWriter processWriter = new StringWriter(); Stack<Character> stckChars = new Stack<Character>(); char[] charArray = str.toCharArray(); for (int i = charArray.length-1; i >=0; i--) { stckChars.push(new Character(charArray[i])); } while(!stckChars.isEmpty()) { Character cChar = stckChars.pop(); if ((cChar.equals(new Character('\\')) && (!stckChars.isEmpty()) && (mustBeEscaped.contains(stckChars.peek())))) { processWriter.write(stckChars.pop()); } else if (cChar.equals(new Character(';'))){ tokens.add(processWriter.toString()); processWriter = new StringWriter(); } else { processWriter.write(cChar); } } tokens.add(processWriter.toString()); Properties props = new Properties(); for (String token : tokens) { if (token.indexOf("=") > 0) { String[] vals = token.split("="); if (vals.length == 2) { String key = vals[0]; String val = vals[1]; props.put(key, val); } else { LOGGER.warning("no eq character in token '"+token+"'"); } } } return props; }  static String storeProperties(Properties properties); static Properties loadProperties(String str); }
PropertiesStoreUtils { public static Properties loadProperties(String str) { List<Character> mustBeEscaped = Arrays.asList(new Character('\\'),new Character(';')); List<String> tokens = new ArrayList<String>(); StringWriter processWriter = new StringWriter(); Stack<Character> stckChars = new Stack<Character>(); char[] charArray = str.toCharArray(); for (int i = charArray.length-1; i >=0; i--) { stckChars.push(new Character(charArray[i])); } while(!stckChars.isEmpty()) { Character cChar = stckChars.pop(); if ((cChar.equals(new Character('\\')) && (!stckChars.isEmpty()) && (mustBeEscaped.contains(stckChars.peek())))) { processWriter.write(stckChars.pop()); } else if (cChar.equals(new Character(';'))){ tokens.add(processWriter.toString()); processWriter = new StringWriter(); } else { processWriter.write(cChar); } } tokens.add(processWriter.toString()); Properties props = new Properties(); for (String token : tokens) { if (token.indexOf("=") > 0) { String[] vals = token.split("="); if (vals.length == 2) { String key = vals[0]; String val = vals[1]; props.put(key, val); } else { LOGGER.warning("no eq character in token '"+token+"'"); } } } return props; }  static String storeProperties(Properties properties); static Properties loadProperties(String str);  }