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 StringCEATTRNAMEstatic StringCHECKSUMATTRNAMEstatic intCHECKSUMSIZEstatic intCHUNK_ALLstatic intCHUNK_DATAstatic intCHUNK_ENDstatic intCHUNK_ERRORstatic intCHUNK_LITTLE_ENDIANstatic intCHUNK_NOCHECKSUMstatic StringCRLFstatic intCRLFSIZEstatic StringDIGESTERstatic StringDRIVELETTERSstatic StringLFstatic StringLITTLEENDIANATTRNAMEstatic 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 letterstatic booleanhasSequence(DapNode node)static booleanhasStrideOne(List<Slice> slices)static booleanhasWindowsDrive(String path)static List<Slice>indexToSlices(Index indices)Given an offset (single index) and a set of dimensions compute the set of dimension indices that correspond to the offset.static List<Slice>indexToSlices(Index indices, DapVariable template)Provide a helper function to convert an Index object to a slice list.static List<Slice>indexToSlices(Index indices, List<DapDimension> dimset)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 Stringmerge(String[] pieces, String sep)static Stringnullify(String path)Convert "" paths to nullstatic IndexoffsetToIndex(long offset, long[] dimsizes)Given an offset (single index) and a set of dimensions compute the set of dimension indices that correspond to the offset.static List<Slice>offsetToSlices(long offset, DapVariable template)Provide a helper function to convert an offset to a slice list.static byte[]readbinaryfile(InputStream stream)static Stringreadtextfile(InputStream stream)static Stringrelativize(String path)static longsliceProduct(List<Slice> slices)static IndexslicesToIndex(List<Slice> slices)If a set of slices refers to a single position, then return the corresponding Index.static IntegerstringToInteger(String s)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
-
CHUNK_DATA
public static final int CHUNK_DATA
- See Also:
- Constant Field Values
-
CHUNK_END
public static final int CHUNK_END
- See Also:
- Constant Field Values
-
CHUNK_ERROR
public static final int CHUNK_ERROR
- See Also:
- Constant Field Values
-
CHUNK_LITTLE_ENDIAN
public static final int CHUNK_LITTLE_ENDIAN
- See Also:
- Constant Field Values
-
CHUNK_NOCHECKSUM
public static final int CHUNK_NOCHECKSUM
- See Also:
- Constant Field Values
-
CHUNK_ALL
public static final int CHUNK_ALL
- See Also:
- Constant Field Values
-
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
-
CHECKSUMSIZE
public static final int CHECKSUMSIZE
- See Also:
- Constant Field Values
-
DIGESTER
public static final String DIGESTER
- See Also:
- Constant Field Values
-
CHECKSUMATTRNAME
public static final String CHECKSUMATTRNAME
- See Also:
- Constant Field Values
-
LITTLEENDIANATTRNAME
public static final String LITTLEENDIANATTRNAME
- See Also:
- Constant Field Values
-
CEATTRNAME
public static final String CEATTRNAME
- See Also:
- Constant Field Values
-
DRIVELETTERS
public static final String DRIVELETTERS
- See Also:
- Constant Field Values
-
-
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
-
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 ""
-
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- Parameters:
path-- Returns:
- true, if path has drive letter
-
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)
-
indexToSlices
public static List<Slice> indexToSlices(Index indices, DapVariable template) throws DapException
Provide a helper function to convert an Index object to a slice list.- Parameters:
indices- indicate value to readtemplate- variable template- Returns:
- corresponding List
- Throws:
DapException
-
indexToSlices
public static List<Slice> indexToSlices(Index indices, List<DapDimension> dimset) throws DapException
- Throws:
DapException
-
offsetToSlices
public static List<Slice> offsetToSlices(long offset, DapVariable template) throws DapException
Provide a helper function to convert an offset to a slice list.- Parameters:
offset- offsettemplate- variable template- Returns:
- slices
- Throws:
DapException
-
offsetToIndex
public static Index offsetToIndex(long offset, long[] dimsizes)
Given an offset (single index) and a set of dimensions compute the set of dimension indices that correspond to the offset.
-
indexToSlices
public static List<Slice> indexToSlices(Index indices) throws DapException
Given an offset (single index) and a set of dimensions compute the set of dimension indices that correspond to the offset.- Throws:
DapException
-
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
-
slicesToIndex
public static Index slicesToIndex(List<Slice> slices) throws DapException
If a set of slices refers to a single position, then return the corresponding Index. Otherwise, throw Exception.- Parameters:
slices-- Returns:
- Index corresponding to slices
- Throws:
DapException
-
dimsetToSlices
public static List<Slice> dimsetToSlices(List<DapDimension> dimset) throws DapException
- Throws:
DapException
-
-