Package org.apache.solr.common.util
Class Utils
java.lang.Object
org.apache.solr.common.util.Utils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Patternstatic final Stringstatic final Utils.InputStreamConsumer<?> static final Utils.InputStreamConsumer<?> static final Function<org.noggit.JSONParser, org.noggit.ObjectBuilder> static final Function<org.noggit.JSONParser, org.noggit.ObjectBuilder> static final Randomstatic final Function<org.noggit.JSONParser, org.noggit.ObjectBuilder> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringapplyUrlScheme(String url, String urlScheme) Given a URL string with or without a scheme, return a new URL with the correct scheme applied.convertToMap(MapWriter m, Map<String, Object> map) 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 Objectstatic 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 Objectstatic ObjectfromJSONResource(ClassLoader loader, String resourceName) static ObjectfromJSONString(String json) static StringgetBaseUrlForNodeName(String nodeName, String urlScheme) Deprecated.static StringgetBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2) Deprecated.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 ObjectReturn a writable object that will be serialized using the reflection-friendly properties of the class, notably the fields that have theJsonPropertyannotation.static SpecProviderstatic <T> Tstatic booleanApplies 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.reflectToMap(Object toReflect) Produce a Map representation of the provided object using reflection to identify annotated fields.static voidConvert 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 Stringsha512Digest(ByteBuffer byteBuffer) static longtime(TimeSource timeSource, TimeUnit unit) static longtimeElapsed(TimeSource timeSource, long start, TimeUnit unit) static ByteBufferReads an input stream into a byte array.static InputStreamstatic byte[]static byte[]static Stringstatic StringtoJSONString(Object o, int indentSize) static byte[]toUTF8(org.noggit.CharArr out) static voidwriteJson(Object o, OutputStream os, boolean indent) static Writer
-
Field Details
-
RANDOM
-
STANDARDOBJBUILDER
-
MAPWRITEROBJBUILDER
-
MAPOBJBUILDER
-
OBJECT_TO_STRING
-
ARRAY_ELEMENT_INDEX
-
JAVABINCONSUMER
-
JSONCONSUMER
-
CATCH_ALL_PROPERTIES_METHOD_NAME
- See Also:
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
sha512Digest
-
getDeepCopy
-
getDeepCopy
-
getDeepCopy
-
forEachMapEntry
-
forEachMapEntry
-
forEachMapEntry
-
toJavabin
- Throws:
IOException
-
fromJavabin
- Throws:
IOException
-
fromJavabin
- Throws:
IOException
-
getDeepCopy
-
getDeepCopy
public static Collection<?> getDeepCopy(Collection<?> c, int maxDepth, boolean mutable, boolean sorted) -
writeJson
- Throws:
IOException
-
writeJson
- Throws:
IOException
-
toJSON
-
toJSON
- Parameters:
indentSize- The number of space characters to use as an indent. 0=newlines but no spaces, -1=no indent at all.
-
toJSONString
- Parameters:
indentSize- The number of space characters to use as an indent. 0=newlines but no spaces, -1=no indent at all.
-
toJSONString
-
toUTF8
public static byte[] toUTF8(org.noggit.CharArr out) -
fromJSON
-
fromJSON
-
fromJSON
-
makeMap
-
makeMap
-
makeMap
-
fromJSON
-
fromJSON
-
fromJSON
public static Object fromJSON(InputStream is, Function<org.noggit.JSONParser, org.noggit.ObjectBuilder> objBuilderProvider) -
fromJSONResource
-
getJSONParser
-
fromJSONString
-
getObjectByPath
-
setObjectByPath
-
setObjectByPath
-
getObjectByPath
-
readFully
Make sure the InputStream is fully read.- Parameters:
is- to read- Throws:
IOException- on problem with IO
-
getSpec
-
parseMetricsReplicaName
-
mergeJson
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 mutableinput- the json with new values- Returns:
- whether there was any change made to sink or not.
-
applyUrlScheme
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
Deprecated.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 nodeurlScheme- 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
-
getBaseUrlForNodeName
@Deprecated public static String getBaseUrlForNodeName(String nodeName, String urlScheme, boolean isV2) Deprecated.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 nodeurlScheme- 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
-
time
-
timeElapsed
-
handleExp
-
newBytesConsumer
-
reflectWrite
Convert the input object to a map, writing only those fields annotated with aJsonPropertyannotation- Parameters:
ew- anMapWriter.EntryWriterto do the actual map insertion/writingo- the object to be converted
-
getReflectWriter
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
-
reflectWrite
public 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- anMapWriter.EntryWriterto do the actual map insertion/writingo- the object to be convertedfieldFilterer- a predicate used to identify which fields of the object to writecatchAllAnnotation- 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
-
reflectToMap
Produce a Map representation of the provided object using reflection to identify annotated fields.The provided object is not required to be a
MapWriter. -
convertToMap
-
toByteArray
Reads an input stream into a byte array. Does not close the input.- Throws:
IOException
-
URLUtil.getBaseUrlForNodeName(String, String)