Package org.apache.solr.common.util
Class Utils
- java.lang.Object
- 
- org.apache.solr.common.util.Utils
 
- 
 public class Utils extends Object 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classUtils.BAOSstatic classUtils.DelegateReflectWriterstatic interfaceUtils.InputStreamConsumer<T>
 - 
Field SummaryFields Modifier and Type Field Description static PatternARRAY_ELEMENT_INDEXstatic StringCATCH_ALL_PROPERTIES_METHOD_NAMEstatic 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 RandomRANDOMstatic Function<org.noggit.JSONParser,org.noggit.ObjectBuilder>STANDARDOBJBUILDER
 - 
Constructor SummaryConstructors Constructor Description Utils()
 - 
Method SummaryAll 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 Map<String,Object>convertToMap(MapWriter m, Map<String,Object> map)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(byte[] utf8, int offset, int length, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> fun)static ObjectfromJSON(InputStream is)static ObjectfromJSON(InputStream is, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider)static ObjectfromJSON(Reader is)static ObjectfromJSONResource(ClassLoader loader, String resourceName)static ObjectfromJSONString(String json)static StringgetBaseUrlForNodeName(String nodeName, String urlScheme)Construct a V1 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.static StringgetBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2)Construct a V1 or a V2 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.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 org.noggit.JSONParsergetJSONParser(Reader reader)static ObjectgetObjectByPath(Object root, boolean onlyPrimitive, String hierarchy)static ObjectgetObjectByPath(Object root, boolean onlyPrimitive, List<String> hierarchy)static ObjectgetReflectWriter(Object o)Return a writable object that will be serialized using the reflection-friendly properties of the class, notably the fields that have theJsonPropertyannotation.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 another.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 Map<String,Object>reflectToMap(Object toReflect)Produce a Map representation of the provided object using reflection to identify annotated fields.static voidreflectWrite(MapWriter.EntryWriter ew, Object o)Convert the input object to a map, writing only those fields annotated with aJsonPropertyannotationstatic voidreflectWrite(MapWriter.EntryWriter ew, Object o, Predicate<Field> fieldFilterer, Class<? extends Annotation> catchAllAnnotation, Function<Field,String> fieldNamer)Convert an input object to a map, writing only those fields that match a providedPredicatestatic 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 ByteBuffertoByteArray(InputStream is)static ByteBuffertoByteArray(InputStream is, long maxSize)Reads an input stream into a byte arraystatic InputStreamtoJavabin(Object o)static byte[]toJSON(Object o)static byte[]toJSON(Object o, int indentSize)static StringtoJSONString(Object o)static StringtoJSONString(Object o, int indentSize)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- 
RANDOMpublic static final Random RANDOM 
 - 
STANDARDOBJBUILDERpublic static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> STANDARDOBJBUILDER 
 - 
MAPWRITEROBJBUILDERpublic static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> MAPWRITEROBJBUILDER 
 - 
MAPOBJBUILDERpublic static final Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> MAPOBJBUILDER 
 - 
ARRAY_ELEMENT_INDEXpublic static final Pattern ARRAY_ELEMENT_INDEX 
 - 
JAVABINCONSUMERpublic static final Utils.InputStreamConsumer<?> JAVABINCONSUMER 
 - 
JSONCONSUMERpublic static final Utils.InputStreamConsumer<?> JSONCONSUMER 
 - 
CATCH_ALL_PROPERTIES_METHOD_NAMEpublic static final String CATCH_ALL_PROPERTIES_METHOD_NAME - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getDeepCopypublic static Map getDeepCopy(Map<?,?> map, int maxDepth, boolean mutable, boolean sorted) 
 - 
forEachMapEntrypublic static void forEachMapEntry(Object o, String path, BiConsumer fun) 
 - 
forEachMapEntrypublic static void forEachMapEntry(Object o, List<String> path, BiConsumer fun) 
 - 
forEachMapEntrypublic static void forEachMapEntry(Object o, BiConsumer fun) 
 - 
toJavabinpublic static InputStream toJavabin(Object o) throws IOException - Throws:
- IOException
 
 - 
fromJavabinpublic static Object fromJavabin(byte[] bytes) throws IOException - Throws:
- IOException
 
 - 
getDeepCopypublic static Collection<?> getDeepCopy(Collection<?> c, int maxDepth, boolean mutable) 
 - 
getDeepCopypublic static Collection<?> getDeepCopy(Collection<?> c, int maxDepth, boolean mutable, boolean sorted) 
 - 
writeJsonpublic static void writeJson(Object o, OutputStream os, boolean indent) throws IOException - Throws:
- IOException
 
 - 
writeJsonpublic static Writer writeJson(Object o, Writer writer, boolean indent) throws IOException - Throws:
- IOException
 
 - 
toJSONpublic static byte[] toJSON(Object o) 
 - 
toJSONpublic static byte[] toJSON(Object o, int indentSize) - Parameters:
- indentSize- The number of space characters to use as an indent. 0=newlines but no spaces, -1=no indent at all.
 
 - 
toJSONStringpublic static String toJSONString(Object o, int indentSize) - Parameters:
- indentSize- The number of space characters to use as an indent. 0=newlines but no spaces, -1=no indent at all.
 
 - 
toUTF8public static byte[] toUTF8(org.noggit.CharArr out) 
 - 
fromJSONpublic static Object fromJSON(byte[] utf8) 
 - 
fromJSONpublic static Object fromJSON(byte[] utf8, int offset, int length) 
 - 
fromJSONpublic static Object fromJSON(byte[] utf8, int offset, int length, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> fun) 
 - 
fromJSONpublic static Object fromJSON(InputStream is) 
 - 
fromJSONpublic static Object fromJSON(InputStream is, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> objBuilderProvider) 
 - 
fromJSONResourcepublic static Object fromJSONResource(ClassLoader loader, String resourceName) 
 - 
getJSONParserpublic static org.noggit.JSONParser getJSONParser(Reader reader) 
 - 
getObjectByPathpublic static Object getObjectByPath(Object root, boolean onlyPrimitive, String hierarchy) 
 - 
setObjectByPathpublic static boolean setObjectByPath(Object root, List<String> hierarchy, Object value) 
 - 
getObjectByPathpublic static Object getObjectByPath(Object root, boolean onlyPrimitive, List<String> hierarchy) 
 - 
consumeFullypublic 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
 
 - 
readFullypublic static void readFully(InputStream is) throws IOException Make sure the InputStream is fully read.- Parameters:
- is- to read
- Throws:
- IOException- on problem with IO
 
 - 
getSpecpublic static SpecProvider getSpec(String name) 
 - 
parseMetricsReplicaNamepublic static String parseMetricsReplicaName(String collectionName, String coreName) 
 - 
mergeJsonpublic static boolean mergeJson(Map<String,Object> sink, Map<String,Object> input) Applies one json over another. The 'input' is applied over the sink The values in input is applied 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.
 
 - 
applyUrlSchemepublic 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
 
 - 
getBaseUrlForNodeNamepublic static String getBaseUrlForNodeName(String nodeName, String urlScheme) Construct a V1 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.- Parameters:
- nodeName- name of the Solr node
- urlScheme- scheme for the base url ('http' or 'https')
- Returns:
- url that looks like https://app-node-1:8983/solr
- Throws:
- IllegalArgumentException- if the provided node name is malformed
 
 - 
getBaseUrlForNodeNamepublic static String getBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2) Construct a V1 or a V2 base url for the Solr node, given its name (e.g., 'app-node-1:8983_solr') and a URL scheme.- Parameters:
- nodeName- name of the Solr node
- urlScheme- scheme for the base url ('http' or 'https')
- isV2- whether a V2 url should be constructed
- Returns:
- url that looks like https://app-node-1:8983/api(V2) orhttps://app-node-1:8983/solr(V1)
- Throws:
- IllegalArgumentException- if the provided node name is malformed
 
 - 
timepublic static long time(TimeSource timeSource, TimeUnit unit) 
 - 
timeElapsedpublic static long timeElapsed(TimeSource timeSource, long start, TimeUnit unit) 
 - 
handleExppublic static <T> T handleExp(org.slf4j.Logger logger, T def, Callable<T> c)
 - 
newBytesConsumerpublic static Utils.InputStreamConsumer<ByteBuffer> newBytesConsumer(int maxSize) 
 - 
executeGETpublic static <T> T executeGET(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer) throws SolrException- Throws:
- SolrException
 
 - 
executeHttpMethodpublic static <T> T executeHttpMethod(org.apache.http.client.HttpClient client, String url, Utils.InputStreamConsumer<T> consumer, org.apache.http.client.methods.HttpRequestBase httpMethod)
 - 
reflectWritepublic static void reflectWrite(MapWriter.EntryWriter ew, Object o) Convert the input object to a map, writing only those fields annotated with aJsonPropertyannotation- Parameters:
- ew- an- MapWriter.EntryWriterto do the actual map insertion/writing
- o- the object to be converted
 
 - 
getReflectWriterpublic static Object getReflectWriter(Object o) Return a writable object that will be serialized using the reflection-friendly properties of the class, notably the fields that have theJsonPropertyannotation.If the class has no reflection-friendly fields, then it will be serialized as a string, using the class's name and toString()method.- Parameters:
- o- the object to get a serializable version of
- Returns:
- a serializable version of the object
 
 - 
reflectWritepublic static void reflectWrite(MapWriter.EntryWriter ew, Object o, Predicate<Field> fieldFilterer, Class<? extends Annotation> catchAllAnnotation, Function<Field,String> fieldNamer) Convert an input object to a map, writing only those fields that match a providedPredicate- Parameters:
- ew- an- MapWriter.EntryWriterto do the actual map insertion/writing
- o- the object to be converted
- fieldFilterer- a predicate used to identify which fields of the object to write
- catchAllAnnotation- the annotation used to identify a method that can return a Map of "catch-all" properties. Method is expected to be named "unknownProperties"
- fieldNamer- a callback that allows changing field names
 
 - 
reflectToMappublic static Map<String,Object> reflectToMap(Object toReflect) Produce a Map representation of the provided object using reflection to identify annotated fields.The provided object is not required to be a MapWriter.
 - 
toByteArraypublic static ByteBuffer toByteArray(InputStream is) throws IOException - Throws:
- IOException
 
 - 
toByteArraypublic static ByteBuffer toByteArray(InputStream is, long maxSize) throws IOException Reads an input stream into a byte array- Parameters:
- is- the input stream
- Returns:
- the byte array
- Throws:
- IOException- If there is a low-level I/O error.
 
 
- 
 
-