Package dap4.core.util
Class DapUtil
- java.lang.Object
-
- dap4.core.util.DapUtil
-
public abstract class DapUtil extends Object
Misc. Utility methods
-
-
Field Summary
Fields Modifier and Type Field Description static BigInteger
BIG_UMASK64
static String
CRLF
static int
CRLFSIZE
static Pattern
DAP4EXT_RE
static String
LF
static ByteOrder
NATIVE_ORDER
static ByteOrder
NETWORK_ORDER
static Charset
UTF8
-
Constructor Summary
Constructors Constructor Description DapUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
absolutize(String path)
static List<String>
backslashSplit(String s, char sep)
Split a string with respect to a separator character and taking backslashes into consideration.static String
canonFileURL(String url)
static String
canonicalpath(String path)
Convert path to: 1.static String
canonjoin(String prefix, String suffix)
static boolean
checkFixedSize(DapVariable var)
static void
checkruntime(Exception e)
Re-throw run-time exceptionsstatic String
denullify(String path)
Convert null paths to ""static long
dimProduct(List<DapDimension> dimset)
static List<Slice>
dimsetToSlices(List<DapDimension> dimset)
static byte[]
extract(ByteBuffer buf)
Properly extract the byte contents of a ByteBufferstatic String
fqnPrefix(String fqn)
static String
fqnSuffix(String fqn)
static long[]
getDimSizes(List<DapDimension> dims)
static List<String>
getProtocols(String url, int[] breakpoint)
Return the set of leading protocols for a url; may be more than one.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.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:/"static boolean
hasSequence(DapNode node)
static boolean
hasStrideOne(List<Slice> slices)
static boolean
hasWindowsDrive(String path)
static int[]
intvector(long[] lv)
static boolean
isAbsolutePath(String path)
static boolean
isContiguous(List<Slice> slices)
Test if a set of slices represent a contiguous region This is equivalent to saying all strides are onestatic boolean
isScalarSlices(List<Slice> slices)
static boolean
isSinglePoint(List<Slice> slices)
Test if a set of slices represent a single positionstatic boolean
isWhole(List<Slice> slices, List<DapDimension> dimset)
Test a Listagainst set of DapDimensions to see if the list is whole wrt the dimensions 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.static String
locateFile(String filename, String abspath, boolean wantdir)
Walk the specified subtree dir tree to try to locate file|dir named filename.static String
locateRelative(String relpath, String abspath, boolean wantdir)
Walk the specified dir tree to locate file specified by relative path.static long[]
longvector(int[] iv)
static String
merge(String[] pieces, String sep)
static String
nullify(String path)
Convert "" paths to nullstatic byte[]
readbinaryfile(InputStream stream)
static int
readbinaryfilepartial(InputStream stream, byte[] buffer, int count)
Read a limited number of bytes from a streamstatic String
readtextfile(InputStream stream)
static String
relativize(String path)
static String
repairPath(String path)
Convert a path of the form "/x:/" to "x:/" to expose drive letter; otherwise leave unchangedstatic long
sliceProduct(List<Slice> slices)
static Object
stringable(Object obj)
Convert null objects to ""static Integer
stringToInteger(String s)
static String
stripDap4Extensions(String path)
static String
xrelpath(String path)
Relativizing a path => remove any leading '/' and cleaning it
-
-
-
Field Detail
-
BIG_UMASK64
public static final BigInteger BIG_UMASK64
-
UTF8
public static final Charset UTF8
-
NETWORK_ORDER
public static final ByteOrder NETWORK_ORDER
-
NATIVE_ORDER
public static final ByteOrder NATIVE_ORDER
-
LF
public static final String LF
- See Also:
- Constant Field Values
-
CRLF
public static final String CRLF
- See Also:
- Constant Field Values
-
CRLFSIZE
public static final int CRLFSIZE
- See Also:
- Constant Field Values
-
DAP4EXT_RE
public static Pattern DAP4EXT_RE
-
-
Method Detail
-
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 splitsep
- The character on which to split- Returns:
- a List of strings (all with escaping still intact) representing s split at unescaped instances of sep.
-
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 locateabspath
- Absolute path from which to start searchwantdir
- 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 locateabspath
- Absolute path from which to start searchwantdir
- 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
-
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
-
readbinaryfile
public static byte[] readbinaryfile(InputStream stream) throws IOException
- Throws:
IOException
-
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 readcount
- amount to read; <= |buffer|- Returns:
- amount actually read
- Throws:
IOException
-
readtextfile
public static String readtextfile(InputStream stream) throws IOException
- 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
-
getDimSizes
public static long[] getDimSizes(List<DapDimension> dims)
-
dimProduct
public static long dimProduct(List<DapDimension> dimset)
-
isWhole
public static boolean isWhole(List<Slice> slices, List<DapDimension> dimset)
Test a Listagainst set of DapDimensions to see if the list is whole wrt the dimensions - Parameters:
slices
- the set of slicesdimset
- the list of DapDimension- Returns:
- true if slices is whole wrt dimset; false otherwise
-
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 concatsep
- the separatorfrom
- 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 returnbreakpoint
- 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)
-
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
-
dimsetToSlices
public static List<Slice> dimsetToSlices(List<DapDimension> dimset) throws DapException
- Throws:
DapException
-
longvector
public static long[] longvector(int[] iv)
-
intvector
public static int[] intvector(long[] lv)
-
-