org.apache.solr.common.util

## Class Utils

- java.lang.Object
- - org.apache.solr.common.util.Utils

    public class Utils
    extends Object

### Field Summary

Fields
`static Pattern` `ARRAY_ELEMENT_INDEX`
`static Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>` `MAPWRITEROBJBUILDER`
`static Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>` `STANDARDOBJBUILDER`

### Constructor Summary

Constructors
Constructor and Description
`Utils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `consumeFully(org.apache.http.HttpEntity entity)` If the passed entity has content, make sure it is fully read and closed.
`static void` `forEachMapEntry(Object o, BiConsumer fun)`
`static void` `forEachMapEntry(Object o, List<String> path, BiConsumer fun)`
`static void` `forEachMapEntry(Object o, String path, BiConsumer fun)`
`static Object` `fromJSON(byte[] utf8)`
`static Object` `fromJSON(InputStream is)`
`static Object` `fromJSON(InputStream is, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider)`
`static Object` `fromJSONResource(String resourceName)`
`static Object` `fromJSONString(String json)`
`static String` `getBaseUrlForNodeName(String nodeName, String urlScheme)`
`static Collection` `getDeepCopy(Collection c, int maxDepth, boolean mutable)`
`static Collection` `getDeepCopy(Collection c, int maxDepth, boolean mutable, boolean sorted)`
`static Map` `getDeepCopy(Map map, int maxDepth)`
`static Map` `getDeepCopy(Map map, int maxDepth, boolean mutable)`
`static Map` `getDeepCopy(Map map, int maxDepth, boolean mutable, boolean sorted)`
`static Map<String,Object>` `getJson(DistribStateManager distribStateManager, String path)`
`static Map<String,Object>` `getJson(SolrZkClient zkClient, String path, boolean retryOnConnLoss)` Assumes data in ZooKeeper is a JSON string, deserializes it and returns as a Map
`static org.noggit.JSONParser` `getJSONParser(Reader reader)`
`static String` `getMDCNode()`
`static Object` `getObjectByPath(Object root, boolean onlyPrimitive, List<String> hierarchy)`
`static Object` `getObjectByPath(Object root, boolean onlyPrimitive, String hierarchy)`
`static SpecProvider` `getSpec(String name)`
`static <T> T` `handleExp(org.slf4j.Logger logger, T def, Callable<T> c)`
`static Map<String,Object>` `makeMap(boolean skipNulls, Object... keyVals)`
`static Map<String,Object>` `makeMap(Object... keyVals)`
`static boolean` `mergeJson(Map<String,Object> sink, Map<String,Object> input)` Applies one json over other.
`static String` `parseMetricsReplicaName(String collectionName, String coreName)`
`static boolean` `setObjectByPath(Object root, List<String> hierarchy, Object value)`
`static boolean` `setObjectByPath(Object root, String hierarchy, Object value)`
`static long` `time(TimeSource timeSource, TimeUnit unit)`
`static long` `timeElapsed(TimeSource timeSource, long start, TimeUnit unit)`
`static InputStream` `toJavabin(Object o)`
`static byte[]` `toJSON(Object o)`
`static String` `toJSONString(Object o)`
`static byte[]` `toUTF8(org.noggit.CharArr out)`
`static void` `writeJson(Object o, OutputStream os, boolean indent)`
`static Writer` `writeJson(Object o, Writer writer, boolean indent)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### STANDARDOBJBUILDER

    public static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> STANDARDOBJBUILDER

#### MAPWRITEROBJBUILDER

    public static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> MAPWRITEROBJBUILDER

#### ARRAY_ELEMENT_INDEX

    public static final Pattern ARRAY_ELEMENT_INDEX

### Constructor Detail

#### Utils

    public Utils()

### Method Detail

#### getDeepCopy

    public static Map getDeepCopy(Map map,
                                  int maxDepth)

#### getDeepCopy

    public static Map getDeepCopy(Map map,
                                  int maxDepth,
                                  boolean mutable)

#### getDeepCopy

    public static Map getDeepCopy(Map map,
                                  int maxDepth,
                                  boolean mutable,
                                  boolean sorted)

#### forEachMapEntry

    public static void forEachMapEntry(Object o,
                                       String path,
                                       BiConsumer fun)

#### forEachMapEntry

    public static void forEachMapEntry(Object o,
                                       List<String> path,
                                       BiConsumer fun)

#### forEachMapEntry

    public static void forEachMapEntry(Object o,
                                       BiConsumer fun)

#### toJavabin

    public static InputStream toJavabin(Object o)
                                 throws IOException

Throws:
  `IOException`

#### getDeepCopy

    public static Collection getDeepCopy(Collection c,
                                         int maxDepth,
                                         boolean mutable)

#### getDeepCopy

    public static Collection getDeepCopy(Collection c,
                                         int maxDepth,
                                         boolean mutable,
                                         boolean sorted)

#### writeJson

    public static void writeJson(Object o,
                                 OutputStream os,
                                 boolean indent)
                          throws IOException

Throws:
  `IOException`

#### writeJson

    public static Writer writeJson(Object o,
                                   Writer writer,
                                   boolean indent)
                            throws IOException

Throws:
  `IOException`

#### toJSON

    public static byte[] toJSON(Object o)

#### toJSONString

    public static String toJSONString(Object o)

#### toUTF8

    public static byte[] toUTF8(org.noggit.CharArr out)

#### fromJSON

    public static Object fromJSON(byte[] utf8)

#### makeMap

    public static Map<String,Object> makeMap(Object... keyVals)

#### makeMap

    public static Map<String,Object> makeMap(boolean skipNulls,
                                             Object... keyVals)

#### fromJSON

    public static Object fromJSON(InputStream is)

#### fromJSON

    public static Object fromJSON(InputStream is,
                                  Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider)

#### fromJSONResource

    public static Object fromJSONResource(String resourceName)

#### getJSONParser

    public static org.noggit.JSONParser getJSONParser(Reader reader)

#### fromJSONString

    public static Object fromJSONString(String json)

#### getObjectByPath

    public static Object getObjectByPath(Object root,
                                         boolean onlyPrimitive,
                                         String hierarchy)

#### setObjectByPath

    public static boolean setObjectByPath(Object root,
                                          String hierarchy,
                                          Object value)

#### setObjectByPath

    public static boolean setObjectByPath(Object root,
                                          List<String> hierarchy,
                                          Object value)

#### getObjectByPath

    public static Object getObjectByPath(Object root,
                                         boolean onlyPrimitive,
                                         List<String> hierarchy)

#### consumeFully

    public static void consumeFully(org.apache.http.HttpEntity entity)

If the passed entity has content, make sure it is fully read and closed.

Parameters:
  `entity` - to consume or null

#### getJson

    public static Map<String,Object> getJson(DistribStateManager distribStateManager,
                                             String path)
                                      throws InterruptedException,
                                             IOException,
                                             org.apache.zookeeper.KeeperException

Throws:
  `InterruptedException`
  `IOException`
  `org.apache.zookeeper.KeeperException`

#### getJson

    public static Map<String,Object> getJson(SolrZkClient zkClient,
                                             String path,
                                             boolean retryOnConnLoss)
                                      throws org.apache.zookeeper.KeeperException,
                                             InterruptedException

Assumes data in ZooKeeper is a JSON string, deserializes it and returns as a Map

Parameters:
  `zkClient` - the zookeeper client
  `path` - the path to the znode being read
  `retryOnConnLoss` - whether to retry the operation automatically on connection loss, see `ZkCmdExecutor.retryOperation(ZkOperation)`
Returns:
  a Map if the node exists and contains valid JSON or an empty map if znode does not exist or has a null data
Throws:
  `org.apache.zookeeper.KeeperException`
  `InterruptedException`

#### getSpec

    public static SpecProvider getSpec(String name)

#### parseMetricsReplicaName

    public static String parseMetricsReplicaName(String collectionName,
                                                 String coreName)

#### mergeJson

    public static boolean mergeJson(Map<String,Object> sink,
                                    Map<String,Object> input)

Applies one json over other. The 'input' is applied over the sink The values in input isapplied over the values in 'sink' . If a value is 'null' that value is removed from sink

Parameters:
  `sink` - the original json object to start with. Ensure that this Map is mutable
  `input` - the json with new values
Returns:
  whether there was any change made to sink or not.

#### getBaseUrlForNodeName

    public static String getBaseUrlForNodeName(String nodeName,
                                               String urlScheme)

#### time

    public static long time(TimeSource timeSource,
                            TimeUnit unit)

#### timeElapsed

    public static long timeElapsed(TimeSource timeSource,
                                   long start,
                                   TimeUnit unit)

#### getMDCNode

    public static String getMDCNode()

#### handleExp

    public static <T> T handleExp(org.slf4j.Logger logger,
                                  T def,
                                  Callable<T> c)