public int read(char cbuf[]) throws IOException { return read(cbuf, 0, cbuf.length); }
TokenReplacingReader childReader = new TokenReplacingReader(tokenName, tokens, activeTokens, resolvedTokens); tokenValue = readAll(childReader); } else { tokenValue = resolveToken(tokenName); return this.tokenValue.charAt(this.tokenValueIndex++); } else { return read();
private String resolveToken(String tokenName) throws IOException { if (resolvedTokens.containsKey(tokenName)) { return resolvedTokens.get(tokenName); } if (activeTokens.contains(tokenName)) { throw new IllegalArgumentException("Token '" + tokenName + "' (indirectly) contains reference to itself in its value."); } activeTokens.push(tokenName); String tokenValue = tokens.get(tokenName); if (tokenValue != null) { if (tokenValue.contains("${")) { TokenReplacingReader childReader = new TokenReplacingReader(tokenValue, tokens, activeTokens, resolvedTokens); tokenValue = readAll(childReader); } } else { tokenValue = "${" + tokenName + "}"; } resolvedTokens.put(tokenName, tokenValue); activeTokens.pop(); return tokenValue; } }
@Override public String get(Object key) { if (resolved.containsKey(key)) { return resolved.get(key); } String rawValue = getRaw(key); if (rawValue == null) { return null; } String ret = readAll(new TokenReplacingReader(new StringReader(rawValue.toString()), this)); resolved.put(key, ret); return ret; }
private void applyConfigChanges(File confDir, String fileName, Map<String, String> tokens) throws DeploymentException { File filteredFile = new File(confDir, fileName); try { if (log.isInfoEnabled()) { log.info("Applying configuration changes to " + filteredFile); } File rhqFile = new File(confDir, "rhq." + fileName); TokenReplacingReader reader = new TokenReplacingReader(new FileReader(rhqFile), tokens); StreamUtil.copy(reader, new FileWriter(filteredFile)); rhqFile.delete(); } catch (IOException e) { log.error("An unexpected error occurred while apply configuration changes to " + filteredFile, e); throw new DeploymentException("An unexpected error occurred while apply configuration changes to " + filteredFile, e); } }
private String getConnectionString(BundleResourceDeployment resourceDeployment) { ResourceContainer rc = inventoryManager.getResourceContainer(resourceDeployment.getResource()); BundleDestination dest = resourceDeployment.getBundleDeployment().getDestination(); ResourceType type = rc.getResource().getResourceType(); String specName = dest.getDestinationSpecificationName(); String relativeDeployDir = dest.getDeployDir(); Configuration config = new Configuration(); config.put(new PropertySimple("deployDir", relativeDeployDir)); ConnectionStringAvailableProperties props = new ConnectionStringAvailableProperties(rc, measurementManager, config); for (ResourceTypeBundleConfiguration.BundleDestinationSpecification spec : type .getResourceTypeBundleConfiguration().getBundleDestinationSpecifications()) { if (specName.equals(spec.getName())) { ResourceTypeBundleConfiguration.BundleDestinationDefinition def = (ResourceTypeBundleConfiguration.BundleDestinationDefinition) spec; String rawConnectionString = def.getConnectionString(); if (rawConnectionString == null) { return null; } TokenReplacingReader trr = new TokenReplacingReader(new StringReader(rawConnectionString), props); try { return StreamUtil.slurp(trr); } finally { StreamUtil.safeClose(trr); } } } return null; }
public int read(char cbuf[], int off, int len) throws IOException { int i = 0; for (; i < len; i++) { int nextChar = read(); if (nextChar == -1) { if (i == 0) { i = -1; } break; } cbuf[off + i] = (char) nextChar; } return i; }