Returns a stream with the template parameter expressions replaced

@param is {@link InputStream} inputstream for
@param valuesMap a hashmap containing parameters
@return returns stream with template parameter expressions replaced
962100
public static InputStream replaceValues(InputStream is, Map<String, String> valuesMap) {
        return new ReplaceValueStream(valuesMap).createInputStream(is);
    }
943650
private LinkedHashMap<String, Num> mapValues(String infix, Object... values) {
        LinkedHashMap<String, Num> vNames = null;
        int remain = 0;
      
        Matcher mat = pVariableNames.matcher(infix);
        while (mat.find()) {
            if (vNames == null)
                vNames = new LinkedHashMap<String, Num>();

            String vName = mat.group();
            if (!vNames.containsKey(vName)) {
                remain++;
                Num num = findValue(vName, true, values);
                vNames.put(vName, num);

                if (num != null)
                    remain--;
            }
        }

        // pair names with values without name
        if (vNames != null) {
            int lastPos = 0;
            for (Entry<String, Num> entry : vNames.entrySet()) {
                if (entry.getValue() == null) {
                    for (int i = lastPos; i < values.length; i++) {
                        Object v = values[i];
                        if (v != null) {
                            if (v instanceof Num) {
                                Num n = (Num) v;
                                if (n.getName() == null)
                                    entry.setValue(n);
                                else if (n.getName().equals(entry.getValue()))
                                    entry.setValue(n);
                            }
                            else
                                entry.setValue(Num.toNum(v));

                            values[i] = null;
                            lastPos = i;
                            remain--;
                        }
                    }
                }
            }
        }

        if (remain > 0 && vNames != null) {
            StringBuilder sb = new StringBuilder();
            int c = 0;
            for (Entry<String, Num> entry : vNames.entrySet()) {
                if (entry.getValue() == null) {
                    if (c++ > 0)
                        sb.append(", ");
                    sb.append(entry.getKey());
                }
            }

            throw new CalculatorException("Undefined values for expression (" + infix + ") variables: " + sb.toString());
        }

        return vNames;
    }
1173933
public static SObject of(String key, InputStream is, Map<String, String> conf) {
        SObject sobj = of(key, is);
        sobj.setAttributes(conf);
        return sobj;
    }
1131849
public static ValueMap map(Object... map) {
        if (map.length / 2 * 2 != map.length)
            throw new IllegalArgumentException("Arguments should be <String> key - <?> value pairs");

        Builder builder = new Builder();
        for (int i = 0; i < map.length; i += 2)
            builder.put((String)map[i], map[i + 1]);

        return builder.build();
    }
958951
private <T> String writeMapValues(String mapName, MultiValueMap<T> map) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("        " + mapName + "\n");
        for (Iterator<T> names = map.names(); names.hasNext();) {
            T name = names.next();
            buffer.append("            ").append(name.toString()).append("\n");
            String[] values = map.getStringArray(name);
            for (String element : values) {
                buffer.append("                ").append(element).append("\n");
            }
        }
        return buffer.toString();
    }
905014
@Nullable
  public static Map<String, String> parsePointer(@NotNull InputStream stream) throws IOException {
    byte[] buffer = new byte[Constants.POINTER_MAX_SIZE];
    int size = 0;
    while (size < buffer.length) {
      int len = stream.read(buffer, size, buffer.length - size);
      if (len <= 0) {
        return parsePointer(buffer, 0, size);
      }
      size += len;
    }
    return null;
  }
386941
public static <E> List<E> parseList(InputStream is, Class<E> jsonObjectClass) throws IOException {
        return mapperFor(jsonObjectClass).parseList(is);
    }
165620
public void fillParameterValues(Map<String, Object> valuesMap) {
        AssertUtils.assertNotNull(valuesMap, "Value map cannot be null");

        if (this.sqlParameterNames != null) {

            String parameterName = null;
            this.sqlParameterValues = new ArrayList<Object>();

            // using for instead of iterator because this way I control position
            // I am getting.
            for (int i = 0; i < this.sqlParameterNames.size(); i++) {
                parameterName = this.sqlParameterNames.get(i);

                if (valuesMap.containsKey(parameterName) == true) {
                    this.sqlParameterValues.add(valuesMap.get(parameterName));
                } else {
                    throw new IllegalArgumentException(String.format(HandlersConstants.ERROR_PARAMETER_NOT_FOUND, parameterName));
                }
            }
        }
    }
430329
private static String getStringFromInputStream(InputStream is)
    {
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        String line;
        try
        {
            br = new BufferedReader(new InputStreamReader(is));
            while((line = br.readLine()) != null)
            {
                sb.append(line);
            }

        }
        catch(IOException e)
        {
            logger.severe("Unable to get string from stream: "+e.getClass().getName()+": "+e.getMessage());
        }
        finally
        {
            try
            {
                if(br != null)
                    br.close();
            }
            catch(IOException e)
            {
            }
        }

        return sb.toString();
    }
56831
public static <K, V> MultiValueMap<K, V> toMultiValueMap(Map<K, List<V>> map) {
		return new MultiValueMapAdapter<K, V>(map);

	}
341218
public String replace(Map<String, String> varMap)
   {
      StringBuilder newString = new StringBuilder();

      int p = 0;
      int p0 = 0;
      while (true)
      {
         p = templateText.indexOf("${", p);
         if (p == -1)
         {
            newString.append(templateText.substring(p0, templateText.length()));
            break;
         }
         else
         {
            newString.append(templateText.substring(p0, p));
         }
         p0 = p;
         p = templateText.indexOf("}", p);
         if (p != -1)
         {
            String varName = templateText.substring(p0 + 2, p).trim();
            if (varMap.containsKey(varName))
            {
               newString.append(varMap.get(varName));
               p0 = p + 1;
            }
         }
      }
      return newString.toString();
   }
935369
public static ComparableSimpleDateFormat compile(final String valueStr)
    {
        final ComparableSimpleDateFormat cp = new ComparableSimpleDateFormat();
        cp.delegate = new SimpleDateFormat(valueStr);
        cp.pattern = valueStr;
        return cp;
    }
54861
protected String merge(String template, Map<String, Object> values){
        try (ResponseStream stream = new ResponseStreamWriter()) {
        
            TemplateEngineOrchestrator manager = injector.getInstance(TemplateEngineOrchestrator.class);
            TemplateEngine engine = manager.getTemplateEngineForContentType(MediaType.TEXT_HTML);
            
            engine.invoke(
                    context, 
                    ResultBuilder.ok().addAllViewObjects(values).template(template).layout(null), 
                    stream);
            
            
    //        Configuration.getTemplateManager().merge(values, template, stringWriter);
            return stream.getWriter().toString();
        } catch (IOException notPossible) { }
        return "";
    }
445638
public static Map mapValues(Mapper mapper, Map map) {
        return mapValues(mapper, map, false);
    }
72894
public static <T> T unmarshal(InputStream is, ObjectMapper mapper) {
   return unmarshal(is, mapper, Collections.<String, String>emptyMap());
  }
812622
public static String applyFromInputStream(InputStream is) throws ConverterException {		
		String xml = converters.get(0).convertFromInputStream(is, false);						
		xml = applyFromSecond(xml);
		if (conversionDone()) {
			return converters.get(converters.size()-1).changeVersion(xml);
		} else {
			return xml;
		}
	}
186666
@Override
    public Map<String, String> values() {
        Map<String, String> values = new LinkedHashMap<>();
        for (Row each : delegates) {
            for (Entry<String, String> entry : each.values().entrySet()) {
                String name = entry.getKey();
                if (!values.containsKey(name)) {
                    values.put(name, entry.getValue());
                }
            }
        }
        return values;
    }