Class DapUtil


  • public abstract class DapUtil
    extends Object
    Misc. Utility methods
    • Constructor Detail

      • DapUtil

        public DapUtil()
    • Method Detail

      • fqnSuffix

        public static String fqnSuffix​(String fqn)
      • fqnPrefix

        public static String fqnPrefix​(String fqn)
      • backslashSplit

        public static List<String> backslashSplit​(String s,
                                                  char sep)
        Split a string with respect to a separator character and taking backslashes into consideration.
        Parameters:
        s - The string to split
        sep - The character on which to split
        Returns:
        a List of strings (all with escaping still intact) representing s split at unescaped instances of sep.
      • stringToInteger

        public static Integer stringToInteger​(String s)
      • hasSequence

        public static boolean hasSequence​(DapNode node)
      • locateFile

        public static String locateFile​(String filename,
                                        String abspath,
                                        boolean wantdir)
        Walk the specified subtree dir tree to try to locate file|dir named filename. Use breadth first search.
        Parameters:
        filename - Name of the file|dir to locate
        abspath - Absolute path from which to start search
        wantdir - True if we are looking for a directory, false if we are looking for a file
        Returns:
        absolute path of the file or null
      • locateRelative

        public static String locateRelative​(String relpath,
                                            String abspath,
                                            boolean wantdir)
        Walk the specified dir tree to locate file specified by relative path. Use breadth first search.
        Parameters:
        relpath - Name of the file|dir to locate
        abspath - Absolute path from which to start search
        wantdir - True if we are looking for a directory, false if we are looking for a file
        Returns:
        absolute path of the file|dir wrt to abspath
      • canonicalpath

        public static String canonicalpath​(String path)
        Convert path to: 1. use '/' consistently 2. remove any trailing '/' 3. trim blanks 4. Be aware of possible windows drive letter
        Parameters:
        path - convert this path
        Returns:
        canonicalized version
      • relativize

        public static String relativize​(String path)
      • absolutize

        public static String absolutize​(String path)
      • checkFixedSize

        public static boolean checkFixedSize​(DapVariable var)
      • extract

        public static byte[] extract​(ByteBuffer buf)
        Properly extract the byte contents of a ByteBuffer
        Parameters:
        buf - The buffer whose content is to be extracted as defined by the buffer limit.
        Returns:
        The byte array contents of the buffer
      • readbinaryfilepartial

        public static int readbinaryfilepartial​(InputStream stream,
                                                byte[] buffer,
                                                int count)
                                         throws IOException
        Read a limited number of bytes from a stream
        Parameters:
        stream -
        buffer - into which to read
        count - amount to read; <= |buffer|
        Returns:
        amount actually read
        Throws:
        IOException
      • getStructurePath

        public static List<DapVariable> getStructurePath​(DapVariable var)
        Given a dap variable, get the path from the top-level variable to and including the given variable such that all but the last element is a structure.
      • denullify

        public static String denullify​(String path)
        Convert null paths to ""
        Parameters:
        path -
        Returns:
        path or ""
      • stringable

        public static Object stringable​(Object obj)
        Convert null objects to ""
        Parameters:
        obj -
        Returns:
        obj or ""
      • nullify

        public static String nullify​(String path)
        Convert "" paths to null
        Parameters:
        path -
        Returns:
        path or null
      • isWhole

        public static boolean isWhole​(List<Slice> slices,
                                      List<DapDimension> dimset)
        Test a List against set of DapDimensions to see if the list is whole wrt the dimensions
        Parameters:
        slices - the set of slices
        dimset - the list of DapDimension
        Returns:
        true if slices is whole wrt dimset; false otherwise
      • sliceProduct

        public static long sliceProduct​(List<Slice> slices)
      • hasStrideOne

        public static boolean hasStrideOne​(List<Slice> slices)
      • join

        public static String join​(String[] array,
                                  String sep,
                                  int from,
                                  int upto)
        Given an Array of Strings and a separator and a count, concat the first count elements of an array with separator between them. A null string is treated like "".
        Parameters:
        array - the array to concat
        sep - the separator
        from - start point for join (inclusive)
        upto - end point for join (exclusive)
        Returns:
        the join
      • xrelpath

        public static String xrelpath​(String path)
        Relativizing a path => remove any leading '/' and cleaning it
        Parameters:
        path -
        Returns:
        Relativized path
      • hasDriveLetter

        public static boolean hasDriveLetter​(String path)
        Return true if this path appears to start with a windows drive letter This tests the patterns "/x:/" and "x:/"
        Parameters:
        path -
        Returns:
        true, if path has drive letter
      • repairPath

        public static String repairPath​(String path)
        Convert a path of the form "/x:/" to "x:/" to expose drive letter; otherwise leave unchanged
        Parameters:
        path -
        Returns:
        repaired path
      • getProtocols

        public static List<String> getProtocols​(String url,
                                                int[] breakpoint)
        Return the set of leading protocols for a url; may be more than one.
        Parameters:
        url - the url whose protocols to return
        breakpoint - return the index past last protocol
        Returns:
        list of leading protocols without the trailing :
      • checkruntime

        public static void checkruntime​(Exception e)
        Re-throw run-time exceptions
      • hasWindowsDrive

        public static boolean hasWindowsDrive​(String path)
      • isAbsolutePath

        public static boolean isAbsolutePath​(String path)
      • canonFileURL

        public static String canonFileURL​(String url)
      • stripDap4Extensions

        public static String stripDap4Extensions​(String path)
      • isContiguous

        public static boolean isContiguous​(List<Slice> slices)
        Test if a set of slices represent a contiguous region This is equivalent to saying all strides are one
        Parameters:
        slices -
        Returns:
        true, if contiguous
      • isSinglePoint

        public static boolean isSinglePoint​(List<Slice> slices)
        Test if a set of slices represent a single position
        Parameters:
        slices -
        Returns:
        true, if single position
      • isScalarSlices

        public static boolean isScalarSlices​(List<Slice> slices)
      • longvector

        public static long[] longvector​(int[] iv)
      • intvector

        public static int[] intvector​(long[] lv)