Replaces all the occurrences of variables within the given source buffer
with their matching values from the resolver.
The buffer is updated with the result.

@param source  the buffer to replace in, updated, null returns zero
@return true if altered
501109
public boolean replaceIn(final StringBuffer source) {
        if (source == null) {
            return false;
        }
        return replaceIn(source, 0, source.length());
    }
276814
private static String replace(String source, char oldChar, String newString) {
        StringBuilder StringBuilder = new StringBuilder(source.length());
        for (int i = 0; i < source.length(); i++) {
            char c = source.charAt(i);
            if (c == oldChar) {
                StringBuilder.append(newString);
            } else {
                StringBuilder.append(c);
            }
        }
        return StringBuilder.toString();
    }
911567
public Object javaToSql(Object source)
    {
        if (source instanceof Boolean)
        {
            if (source.equals(Boolean.TRUE))
            {
                return I_TRUE;
            }
            else
            {
                return I_FALSE;
            }
        }
        else
        {
            return source;
        }
    }
1247623
ResolveSource replaceWithinCurrentParent(AbstractConfigValue old, AbstractConfigValue replacement) {
        if (ConfigImpl.traceSubstitutionsEnabled())
            ConfigImpl.trace("replaceWithinCurrentParent old " + old + "@" + System.identityHashCode(old)
                    + " replacement " + replacement + "@" + System.identityHashCode(old) + " in " + this);
        if (old == replacement) {
            return this;
        } else if (pathFromRoot != null) {
            Container parent = pathFromRoot.head();
            AbstractConfigValue newParent = parent.replaceChild(old, replacement);
            return replaceCurrentParent(parent, (newParent instanceof Container) ? (Container) newParent : null);
        } else {
            if (old == root && replacement instanceof Container) {
                return new ResolveSource(rootMustBeObj((Container) replacement));
            } else {
                throw new ConfigException.BugOrBroken("replace in parent not possible " + old + " with " + replacement
                        + " in " + this);
                // return this;
            }
        }
    }
1319888
@Override
    public void execute(final ReplaceInList command) {
        referenceKeeper.cleanReferenceCache();
        if (couldBeExecuted(command)) {
            executor.execute(command);
        } else {
            keepReferenceIfObservable(command.getValue());
        }
    }
223126
public static void replace(final StringBuffer sb, final String find, final String replacement) {
		int pos = 0;
		while(pos<sb.length()) {
			pos = sb.indexOf(find, pos);
			if(pos==-1) break;
			sb.replace(pos, pos+find.length(), replacement);
			pos += replacement.length();
		}
	}
564955
public String apply(final JsonParser jp, CacheScope cacheScope, Supplier<String> source) throws IOException {
        return apply(CharBuffer.wrap(jp, source), cacheScope);
    }
73547
@Nullable
    public static String replaceMacro(@CheckForNull String s, @Nonnull VariableResolver<String> resolver) {
    	if (s == null) {
    		return null;
    	}

        int idx=0;
        while(true) {
            Matcher m = VARIABLE.matcher(s);
            if(!m.find(idx))   return s;

            String key = m.group().substring(1);

            // escape the dollar sign or get the key to resolve
            String value;
            if(key.charAt(0)=='$') {
               value = "$";
            } else {
               if(key.charAt(0)=='{')  key = key.substring(1,key.length()-1);
               value = resolver.resolve(key);
            }

            if(value==null)
                idx = m.end(); // skip this
            else {
                s = s.substring(0,m.start())+value+s.substring(m.end());
                idx = m.start() + value.length();
            }
        }
    }
823028
@Override
    public BufferByteInput<T> source(final T source) {
        return (BufferByteInput<T>) super.source(source);
    }
1312945
public static boolean copy(InputStream source, ByteBuffer destination) {
        try {
            byte [] buffer = new byte[4096];
            int n = 0;
            while (-1 != (n = source.read(buffer))) {
                destination.put(buffer, 0, n);
            }
            return true;
        } catch (IOException e) {
            return false;
        }
    }
776070
public Object javaToSql(Object source)
    {
        if (source == null)
            return null;
        try
        {
            return SerializationUtils.serialize((Serializable) source);
        }
        catch(Throwable t)
        {
            throw new ConversionException(t);
        }
    }
741179
private void copyToTargetBufferFrom(ByteBuffer source) {
		if (this.targetBuffer == null) {
			return;
		}

		int needed = source.remaining();
		int available = this.limit - this.position;
		int toCopy = Math.min(needed, available);

		this.targetBuffer.getMemorySegment().put(this.position, source, toCopy);

		this.position += toCopy;
	}
156253
protected String replace(String source) {
    StringBuffer tmp = new StringBuffer();
    StringTokenizer stringTokenizer = new StringTokenizer(source, specialString, true);
    String previous = "";
    while (stringTokenizer.hasMoreTokens()) {
      String current = stringTokenizer.nextToken();
      if (special.containsKey(current) && !previous.endsWith("&")) {
        current = (String) special.get(current);
      }
      tmp.append(current);
      previous = current;
    }
    return tmp.toString();
  }
563719
public Object javaToSql(Object source)
    {
        synchronized (byteOut)
        {
            try
            {
                if (gzipOut == null)
                {
                    gzipOut = new GZIPOutputStream(uuOut);
                    objOut = new ObjectOutputStream(gzipOut);
                }

                /*
                ** Clear out the byte array
                */
                byteOut.reset();

                objOut.writeObject(source);
                objOut.flush();
                gzipOut.finish();
                gzipOut.flush();

                return (byteOut.toString());
            }
            catch (Throwable t)
            {
                throw new ConversionException(t);
            }
        }
    }
531542
public boolean replaceByName(String table, Cell c) {
        if (c == null) {
            throw new DeepGenericException(new IllegalArgumentException("cell parameter cannot be null"));
        }

        boolean cellFound = false;
        int position = 0;

        List<Cell> localCells = getCellsByTable(table);

        Iterator<Cell> cellsIt = localCells.iterator();
        while (!cellFound && cellsIt.hasNext()) {
            Cell currentCell = cellsIt.next();

            if (currentCell.getCellName().equals(c.getCellName())) {
                cellFound = true;
            } else {
                position++;
            }
        }

        if (cellFound) {
            localCells.remove(position);

            return localCells.add(c);
        }

        return false;
    }
71733
public static String replaceLast(String source, char toReplace, char with) {
    StringBuilder sb = new StringBuilder(source);
    int index = sb.lastIndexOf(String.valueOf(toReplace));
    if (index != -1) {
      sb.setCharAt(index, with);
    }
    return sb.toString();
  }
941024
@Override
    public Object resolveObject(@Sensitive Object object) throws IOException {
        if (object instanceof JavaURLContextReplacement) {
            try {
                JavaURLContextReplacement replacement = (JavaURLContextReplacement) object;
                JavaURLContext ctx = factory.createJavaURLContext(replacement.getEnv(), new JavaURLName(replacement.getBase()));
                return ctx;
            } catch (NamingException ex) {
                throw new IOException(ex.getMessage(), ex);
            }

        }
        return null;
    }