Package org.apache.solr.common.util
Class Utils
- java.lang.Object
-
- org.apache.solr.common.util.Utils
-
public class Utils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceUtils.InputStreamConsumer<T>
-
Field Summary
Fields Modifier and Type Field Description static PatternARRAY_ELEMENT_INDEXstatic Utils.InputStreamConsumer<?>JAVABINCONSUMERstatic Utils.InputStreamConsumer<?>JSONCONSUMERstatic Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>MAPOBJBUILDERstatic Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>MAPWRITEROBJBUILDERstatic Function<Object,String>OBJECT_TO_STRINGstatic Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>STANDARDOBJBUILDER
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringapplyUrlScheme(String url, String urlScheme)Given a URL string with or without a scheme, return a new URL with the correct scheme applied.static voidconsumeFully(org.apache.http.HttpEntity entity)If the passed entity has content, make sure it is fully read and closed.static <T> TexecuteGET(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer)static <T> TexecuteHttpMethod(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer, org.apache.http.client.methods.HttpRequestBase httpMethod)static voidforEachMapEntry(Object o, String path, BiConsumer fun)static voidforEachMapEntry(Object o, BiConsumer fun)static voidforEachMapEntry(Object o, List<String> path, BiConsumer fun)static ObjectfromJavabin(byte[] bytes)static ObjectfromJSON(byte[] utf8)static ObjectfromJSON(byte[] utf8, int offset, int length)static ObjectfromJSON(InputStream is)static ObjectfromJSON(InputStream is, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider)static ObjectfromJSON(Reader is)static ObjectfromJSONResource(String resourceName)static ObjectfromJSONString(String json)static StringgetBaseUrlForNodeName(String nodeName, String urlScheme)static StringgetBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2)static Collection<?>getDeepCopy(Collection<?> c, int maxDepth, boolean mutable)static Collection<?>getDeepCopy(Collection<?> c, int maxDepth, boolean mutable, boolean sorted)static MapgetDeepCopy(Map<?,?> map, int maxDepth)static MapgetDeepCopy(Map<?,?> map, int maxDepth, boolean mutable)static MapgetDeepCopy(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 Mapstatic org.noggit.JSONParsergetJSONParser(Reader reader)static StringgetMDCNode()static ObjectgetObjectByPath(Object root, boolean onlyPrimitive, String hierarchy)static ObjectgetObjectByPath(Object root, boolean onlyPrimitive, List<String> hierarchy)static SpecProvidergetSpec(String name)static <T> ThandleExp(org.slf4j.Logger logger, T def, Callable<T> c)static Map<String,Object>makeMap(Object... keyVals)static Map<String,String>makeMap(String... keyVals)static <V> Map<String,V>makeMap(String k1, V v1, String k2, V v2)static booleanmergeJson(Map<String,Object> sink, Map<String,Object> input)Applies one json over other.static Utils.InputStreamConsumer<ByteBuffer>newBytesConsumer(int maxSize)static StringparseMetricsReplicaName(String collectionName, String coreName)static voidreadFully(InputStream is)Make sure the InputStream is fully read.static voidreflectWrite(MapWriter.EntryWriter ew, Object o)static booleansetObjectByPath(Object root, String hierarchy, Object value)static booleansetObjectByPath(Object root, List<String> hierarchy, Object value)static longtime(TimeSource timeSource, TimeUnit unit)static longtimeElapsed(TimeSource timeSource, long start, TimeUnit unit)static InputStreamtoJavabin(Object o)static byte[]toJSON(Object o)static StringtoJSONString(Object o)static byte[]toUTF8(org.noggit.CharArr out)static voidwriteJson(Object o, OutputStream os, boolean indent)static WriterwriteJson(Object o, Writer writer, boolean indent)
-
-
-
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
-
MAPOBJBUILDER
public static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> MAPOBJBUILDER
-
ARRAY_ELEMENT_INDEX
public static final Pattern ARRAY_ELEMENT_INDEX
-
JAVABINCONSUMER
public static final Utils.InputStreamConsumer<?> JAVABINCONSUMER
-
JSONCONSUMER
public static final Utils.InputStreamConsumer<?> JSONCONSUMER
-
-
Method Detail
-
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
-
fromJavabin
public static Object fromJavabin(byte[] bytes) 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)
-
toUTF8
public static byte[] toUTF8(org.noggit.CharArr out)
-
fromJSON
public static Object fromJSON(byte[] utf8)
-
fromJSON
public static Object fromJSON(byte[] utf8, int offset, int length)
-
fromJSON
public static Object fromJSON(InputStream is)
-
fromJSON
public static Object fromJSON(InputStream is, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider)
-
getJSONParser
public static org.noggit.JSONParser getJSONParser(Reader reader)
-
getObjectByPath
public static Object getObjectByPath(Object root, boolean onlyPrimitive, String hierarchy)
-
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
-
readFully
public static void readFully(InputStream is) throws IOException
Make sure the InputStream is fully read.- Parameters:
is- to read- Throws:
IOException- on problem with IO
-
getJson
public static Map<String,Object> getJson(DistribStateManager distribStateManager, String path) throws InterruptedException, IOException, org.apache.zookeeper.KeeperException
- Throws:
InterruptedExceptionIOExceptionorg.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 clientpath- the path to the znode being readretryOnConnLoss- whether to retry the operation automatically on connection loss, seeZkCmdExecutor.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.KeeperExceptionInterruptedException
-
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 mutableinput- the json with new values- Returns:
- whether there was any change made to sink or not.
-
applyUrlScheme
public static String applyUrlScheme(String url, String urlScheme)
Given a URL string with or without a scheme, return a new URL with the correct scheme applied.- Parameters:
url- A URL to change the scheme (http|https)- Returns:
- A new URL with the correct scheme
-
getBaseUrlForNodeName
public static String getBaseUrlForNodeName(String nodeName, String urlScheme)
-
getBaseUrlForNodeName
public static String getBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2)
-
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)
-
newBytesConsumer
public static Utils.InputStreamConsumer<ByteBuffer> newBytesConsumer(int maxSize)
-
executeGET
public static <T> T executeGET(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer) throws SolrException- Throws:
SolrException
-
executeHttpMethod
public static <T> T executeHttpMethod(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer, org.apache.http.client.methods.HttpRequestBase httpMethod)
-
reflectWrite
public static void reflectWrite(MapWriter.EntryWriter ew, Object o) throws IOException
- Throws:
IOException
-
-