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 BigIntegerBIG_UMASK64static StringCRLFstatic intCRLFSIZEstatic PatternDAP4EXT_REstatic StringLFstatic ByteOrderNATIVE_ORDERstatic ByteOrderNETWORK_ORDERstatic CharsetUTF8
-
Constructor Summary
Constructors Constructor Description DapUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringabsolutize(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 StringcanonFileURL(String url)static Stringcanonicalpath(String path)Convert path to: 1.static Stringcanonjoin(String prefix, String suffix)static booleancheckFixedSize(DapVariable var)static voidcheckruntime(Exception e)Re-throw run-time exceptionsstatic Stringdenullify(String path)Convert null paths to ""static longdimProduct(List<DapDimension> dimset)static List<Slice>dimsetToSlices(List<DapDimension> dimset)static byte[]extract(ByteBuffer buf)Properly extract the byte contents of a ByteBufferstatic StringfqnPrefix(String fqn)static StringfqnSuffix(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 booleanhasDriveLetter(String path)Return true if this path appears to start with a windows drive letter This tests the patterns "/x:/" and "x:/"static booleanhasSequence(DapNode node)static booleanhasStrideOne(List<Slice> slices)static booleanhasWindowsDrive(String path)static int[]intvector(long[] lv)static booleanisAbsolutePath(String path)static booleanisContiguous(List<Slice> slices)Test if a set of slices represent a contiguous region This is equivalent to saying all strides are onestatic booleanisScalarSlices(List<Slice> slices)static booleanisSinglePoint(List<Slice> slices)Test if a set of slices represent a single positionstatic booleanisWhole(List<Slice> slices, List<DapDimension> dimset)Test a Listagainst set of DapDimensions to see if the list is whole wrt the dimensions static Stringjoin(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 StringlocateFile(String filename, String abspath, boolean wantdir)Walk the specified subtree dir tree to try to locate file|dir named filename.static StringlocateRelative(String relpath, String abspath, boolean wantdir)Walk the specified dir tree to locate file specified by relative path.static long[]longvector(int[] iv)static Stringmerge(String[] pieces, String sep)static Stringnullify(String path)Convert "" paths to nullstatic byte[]readbinaryfile(InputStream stream)static intreadbinaryfilepartial(InputStream stream, byte[] buffer, int count)Read a limited number of bytes from a streamstatic Stringreadtextfile(InputStream stream)static Stringrelativize(String path)static StringrepairPath(String path)Convert a path of the form "/x:/" to "x:/" to expose drive letter; otherwise leave unchangedstatic longsliceProduct(List<Slice> slices)static Objectstringable(Object obj)Convert null objects to ""static IntegerstringToInteger(String s)static StringstripDap4Extensions(String path)static Stringxrelpath(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)
-
-