Class Utils

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

public class Utils extends Object
  • Field Details

    • RANDOM

      public static final Random RANDOM
    • 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
    • OBJECT_TO_STRING

      public static final Function<Object,String> OBJECT_TO_STRING
      Util function to convert Object to String Specially handles Date to string conversion
    • ARRAY_ELEMENT_INDEX

      public static final Pattern ARRAY_ELEMENT_INDEX
    • JAVABINCONSUMER

      public static final Utils.InputStreamConsumer<?> JAVABINCONSUMER
    • JSONCONSUMER

      public static final Utils.InputStreamConsumer<?> JSONCONSUMER
    • CATCH_ALL_PROPERTIES_METHOD_NAME

      public static final String CATCH_ALL_PROPERTIES_METHOD_NAME
      See Also:
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • sha512Digest

      public static String sha512Digest(ByteBuffer byteBuffer)
    • 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
    • fromJavabin

      public static Object fromJavabin(byte[] bytes) throws IOException
      Throws:
      IOException
    • fromJavabin

      public static Object fromJavabin(InputStream is) 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)
    • toJSON

      public 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.
    • toJSONString

      public 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.
    • toJSONString

      public static String toJSONString(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(byte[] utf8, int offset, int length, Function<org.noggit.JSONParser,org.noggit.ObjectBuilder> fun)
    • makeMap

      public static <V> Map<String,V> makeMap(String k1, V v1, String k2, V v2)
    • makeMap

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

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

      public static Object fromJSON(InputStream is)
    • fromJSON

      public static Object fromJSON(Reader is)
    • fromJSON

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

      public static Object fromJSONResource(ClassLoader loader, 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)
    • 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
    • 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 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.
    • 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

      @Deprecated public 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
    • getBaseUrlForNodeName

      @Deprecated public 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) or https://app-node-1:8983/solr (V1)
      Throws:
      IllegalArgumentException - if the provided node name is malformed
    • time

      public static long time(TimeSource timeSource, TimeUnit unit)
    • timeElapsed

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

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

      public static Utils.InputStreamConsumer<ByteBuffer> newBytesConsumer(int maxSize)
    • reflectWrite

      public static void reflectWrite(MapWriter.EntryWriter ew, Object o)
      Convert the input object to a map, writing only those fields annotated with a JsonProperty annotation
      Parameters:
      ew - an MapWriter.EntryWriter to do the actual map insertion/writing
      o - the object to be converted
    • getReflectWriter

      public 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 the JsonProperty annotation.

      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 provided Predicate
      Parameters:
      ew - an MapWriter.EntryWriter to 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
    • reflectToMap

      public 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.

    • convertToMap

      public static Map<String,Object> convertToMap(MapWriter m, Map<String,Object> map)
    • toByteArray

      public static ByteBuffer toByteArray(InputStream is) throws IOException
      Reads an input stream into a byte array. Does not close the input.
      Throws:
      IOException