Class CouchDbUtil


  • final class CouchDbUtil
    extends java.lang.Object
    Provides various utility methods, for internal use.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String LINE_SEP  
      private static java.lang.String SPRING_BOOT_DIR  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CouchDbUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertNotEmpty​(java.lang.Object object, java.lang.String prefix)  
      static void assertNull​(java.lang.Object object, java.lang.String prefix)  
      static void close​(java.io.Closeable c)
      Closes a resource.
      static void close​(org.apache.http.HttpResponse response)
      Closes the response input stream.
      static java.lang.String generateUUID()  
      static int getAsInt​(com.google.gson.JsonObject j, java.lang.String e)  
      static long getAsLong​(com.google.gson.JsonObject j, java.lang.String e)  
      static java.lang.String getAsString​(com.google.gson.JsonObject j, java.lang.String e)  
      static java.io.InputStream getStream​(org.apache.http.HttpResponse response)  
      static <T> T JsonToObject​(com.google.gson.Gson gson, com.google.gson.JsonElement elem, java.lang.String key, java.lang.Class<T> classType)  
      static java.util.List<java.lang.String> listResources​(java.lang.String path)
      List directory contents for a resource folder.
      static java.lang.String readFile​(java.lang.String path)  
      static java.lang.String removeExtension​(java.lang.String fileName)  
      static java.lang.String streamToString​(java.io.InputStream in)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LINE_SEP

        private static final java.lang.String LINE_SEP
    • Constructor Detail

      • CouchDbUtil

        private CouchDbUtil()
    • Method Detail

      • assertNotEmpty

        public static void assertNotEmpty​(java.lang.Object object,
                                          java.lang.String prefix)
                                   throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • assertNull

        public static void assertNull​(java.lang.Object object,
                                      java.lang.String prefix)
                               throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • generateUUID

        public static java.lang.String generateUUID()
      • JsonToObject

        public static <T> T JsonToObject​(com.google.gson.Gson gson,
                                         com.google.gson.JsonElement elem,
                                         java.lang.String key,
                                         java.lang.Class<T> classType)
      • getAsString

        public static java.lang.String getAsString​(com.google.gson.JsonObject j,
                                                   java.lang.String e)
        Returns:
        A JSON element as a String, or null if not found.
      • getAsLong

        public static long getAsLong​(com.google.gson.JsonObject j,
                                     java.lang.String e)
        Returns:
        A JSON element as long, or 0 if not found.
      • getAsInt

        public static int getAsInt​(com.google.gson.JsonObject j,
                                   java.lang.String e)
        Returns:
        A JSON element as int, or 0 if not found.
      • listResources

        public static java.util.List<java.lang.String> listResources​(java.lang.String path)
        List directory contents for a resource folder. Not recursive. This is basically a brute-force implementation. Works for regular files and also JARs.
        Parameters:
        path - Should end with "/", but not start with one.
        Returns:
        Just the name of each member item, not the full paths.
      • readFile

        public static java.lang.String readFile​(java.lang.String path)
      • getStream

        public static java.io.InputStream getStream​(org.apache.http.HttpResponse response)
        Returns:
        InputStream of HttpResponse
      • removeExtension

        public static java.lang.String removeExtension​(java.lang.String fileName)
      • streamToString

        public static java.lang.String streamToString​(java.io.InputStream in)
      • close

        public static void close​(org.apache.http.HttpResponse response)
        Closes the response input stream.
        Parameters:
        response - The HttpResponse
      • close

        public static void close​(java.io.Closeable c)
        Closes a resource.
        Parameters:
        c - The Closeable resource.