public static byte[] toBytes(TypedProperties source) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { source.save(baos); } catch (IOException ex) { throw new IllegalArgumentException("Cannot store properties", ex); } return baos.toByteArray(); }
public static byte[] toBytes(TypedProperties source) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { source.save(baos); } catch (IOException ex) { throw new IllegalArgumentException("Cannot store properties", ex); } return baos.toByteArray(); }
private static void save(TypedProperties props, RandomAccessFile raf) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); props.save(baos); raf.setLength(0); raf.write(baos.toByteArray()); }
protected void updateStorage(ConfigId cid, TypedProperties props, boolean append) throws Exception { if (storage != null && configCfgStore) { File cfgFile = getConfigFile(cid); if (!cfgFile.exists()) { props.save(cfgFile); } else { updateExistingConfig(props, append, cfgFile); } } }
@Override public void propertyAction(TypedProperties props) { if (raw) { try { StringWriter sw = new StringWriter(); props.save(sw); System.out.print(sw.toString()); } catch (IOException e) { throw new RuntimeException(e); } } else { try { StringWriter sw = new StringWriter(); props.save(sw); TypedProperties p = new TypedProperties(); p.load(new StringReader(sw.toString())); props = p; } catch (IOException e) { // Ignore } Map<String, Object> sortedProps = new TreeMap<>(props); for (Map.Entry<String, Object> entry : sortedProps.entrySet()) { System.out.println(" " + entry.getKey() + " = " + displayValue(entry.getValue())); } } }
@Override public String createFactoryConfiguration(String factoryPid, String alias, Map<String, Object> properties) throws IOException { Configuration config = configAdmin.createFactoryConfiguration(factoryPid, "?"); TypedProperties props = new TypedProperties(); File file = null; if (alias != null && !"".equals(alias.trim())) { file = new File(new File(System.getProperty("karaf.etc")), factoryPid + "-" + alias + ".cfg"); } else { file = File.createTempFile(factoryPid + "-", ".cfg", new File(System.getProperty("karaf.etc"))); } props.putAll(properties); props.save(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); config.update(new Hashtable<>(props)); return config.getPid(); }
@Override public void propertyAction(TypedProperties props) { if (raw) { try { StringWriter sw = new StringWriter(); props.save(sw); System.out.print(sw.toString()); } catch (IOException e) { throw new RuntimeException(e); } } else { try { StringWriter sw = new StringWriter(); props.save(sw); TypedProperties p = new TypedProperties(); p.load(new StringReader(sw.toString())); props = p; } catch (IOException e) { // Ignore } Map<String, Object> sortedProps = new TreeMap<>(props); for (Map.Entry<String, Object> entry : sortedProps.entrySet()) { System.out.println(" " + entry.getKey() + " = " + displayValue(entry.getValue())); } } }
@Override public String createFactoryConfiguration(String factoryPid, String alias, Map<String, Object> properties) throws IOException { Configuration config = configAdmin.createFactoryConfiguration(factoryPid, "?"); TypedProperties props = new TypedProperties(); File file = null; if (alias != null && !"".equals(alias.trim())) { file = new File(new File(System.getProperty("karaf.etc")), factoryPid + "-" + alias + ".cfg"); } else { file = File.createTempFile(factoryPid + "-", ".cfg", new File(System.getProperty("karaf.etc"))); } props.putAll(properties); props.save(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); config.update(new Hashtable<>(props)); return config.getPid(); }
@Override public void update(String pid, Map<String, Object> properties) throws IOException { try { LOGGER.trace("Updating configuration {}", pid); Configuration cfg = configAdmin.getConfiguration(pid, "?"); Dictionary<String, Object> dict = cfg.getProperties(); TypedProperties props = new TypedProperties(); File file = getCfgFileFromProperties(dict); if (file != null) { props.load(file); props.putAll(properties); props.keySet().retainAll(properties.keySet()); props.save(file); props.clear(); props.load(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); } else { file = new File(System.getProperty("karaf.etc"), pid + ".cfg"); props.putAll(properties); props.keySet().retainAll(properties.keySet()); props.save(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); } cfg.update(new Hashtable<>(props)); } catch (URISyntaxException e) { throw new IOException("Error updating config", e); } }
@Override public void update(String pid, Map<String, Object> properties) throws IOException { try { LOGGER.trace("Updating configuration {}", pid); Configuration cfg = configAdmin.getConfiguration(pid, "?"); Dictionary<String, Object> dict = cfg.getProperties(); TypedProperties props = new TypedProperties(); File file = getCfgFileFromProperties(dict); if (file != null) { props.load(file); props.putAll(properties); props.keySet().retainAll(properties.keySet()); props.save(file); props.clear(); props.load(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); } else { file = new File(System.getProperty("karaf.etc"), pid + ".cfg"); props.putAll(properties); props.keySet().retainAll(properties.keySet()); props.save(file); props.put(FILEINSTALL_FILE_NAME, file.toURI().toString()); } cfg.update(new Hashtable<>(props)); } catch (URISyntaxException e) { throw new IOException("Error updating config", e); } }
props.putAll(c); props.keySet().retainAll(c.keySet()); props.save(etcFile); props.clear(); props.load(etcFile);
properties.save(cfgFile);