public final class CommonUtils extends Object
Constructor and Description |
---|
CommonUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
addLeadingZero(int number,
int width)
Add leading zero to make the number has a fixed width.
|
static void |
changeLocalFilePermission(String filePath,
String perms)
Change local file's permission.
|
static void |
changeLocalFileToFullPermission(String filePath)
Change local file's permission to be 777.
|
static String |
cleanPath(String path)
Checks and normalizes the given path
|
static ByteBuffer |
cloneByteBuffer(ByteBuffer buf) |
static List<ByteBuffer> |
cloneByteBufferList(List<ByteBuffer> source) |
static String |
concat(Object... args)
Add the path component to the base path
|
static String |
convertByteArrayToStringWithoutEscape(byte[] data) |
static String |
convertMsToClockTime(long Millis) |
static String |
convertMsToDate(long Millis) |
static String |
convertMsToShortClockTime(long Millis) |
static String |
convertMsToSimpleDate(long Millis) |
static ByteBuffer |
generateNewByteBufferFromThriftRPCResults(ByteBuffer data) |
static long |
getBlockIdFromFileName(String name) |
static long |
getCurrentMs() |
static long |
getCurrentNs() |
static long |
getMB(long bytes) |
static String |
getName(String path)
Get the name of the file at a path.
|
static String |
getParent(String path)
Get the parent of the file at a path.
|
static String[] |
getPathComponents(String path)
Get the path components of the given path.
|
static String |
getPathWithoutSchema(String path)
Get the path without schema.
|
static String |
getSizeFromBytes(long bytes) |
static void |
illegalArgumentException(Exception e) |
static void |
illegalArgumentException(String msg) |
static boolean |
isRoot(String path)
Check if the given path is the root.
|
static <T> String |
listToString(List<T> list) |
static String |
parametersToString(Object... objs) |
static InetSocketAddress |
parseInetSocketAddress(String address)
Parse InetSocketAddress from a String
|
static long |
parseSpaceSize(String spaceSize)
Parse a String size to Bytes.
|
static void |
printByteBuffer(org.apache.log4j.Logger LOG,
ByteBuffer buf) |
static void |
printTimeTakenMs(long startTimeMs,
org.apache.log4j.Logger logger,
String message) |
static void |
printTimeTakenNs(long startTimeNs,
org.apache.log4j.Logger logger,
String message) |
static void |
runtimeException(Exception e) |
static void |
runtimeException(String msg) |
static void |
setLocalFileStickyBit(String file)
If the sticky bit of the 'file' is set, the 'file' is only writable to its owner and the owner
of the folder containing the 'file'.
|
static void |
sleepMs(org.apache.log4j.Logger logger,
long timeMs) |
static void |
tempoaryLog(String msg) |
static String[] |
toStringArray(ArrayList<String> src) |
static void |
touch(String path)
Create an empty file
|
static void |
validatePath(String path)
Check if the given path is properly formed
|
public static String addLeadingZero(int number, int width) throws IOException
number
- the number to add leading zerowidth
- the fixed widthIOException
- the number has to be non-negative; the width has to be positive.public static void changeLocalFilePermission(String filePath, String perms) throws IOException
filePath
- that will change permissionperms
- the permission, e.g. "775"IOException
public static void changeLocalFileToFullPermission(String filePath) throws IOException
filePath
- that will change permissionIOException
public static String cleanPath(String path) throws InvalidPathException
path
- The path to clean upInvalidPathException
public static ByteBuffer cloneByteBuffer(ByteBuffer buf)
public static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source)
public static String concat(Object... args)
args
- The components to concatenatepublic static String convertByteArrayToStringWithoutEscape(byte[] data)
public static String convertMsToClockTime(long Millis)
public static String convertMsToDate(long Millis)
public static String convertMsToShortClockTime(long Millis)
public static String convertMsToSimpleDate(long Millis)
public static ByteBuffer generateNewByteBufferFromThriftRPCResults(ByteBuffer data)
public static long getBlockIdFromFileName(String name)
public static long getCurrentMs()
public static long getCurrentNs()
public static long getMB(long bytes)
public static String getName(String path) throws InvalidPathException
path
- The pathInvalidPathException
public static String getParent(String path) throws InvalidPathException
path
- The pathInvalidPathException
public static String[] getPathComponents(String path) throws InvalidPathException
path
- The path to splitInvalidPathException
public static String getPathWithoutSchema(String path)
tachyon://localhost:19998/ -> /
tachyon://localhost:19998/abc/d.txt -> /abc/d.txt
tachyon-ft://localhost:19998/abc/d.txt -> /abc/d.txt
path
- the original pathpublic static String getSizeFromBytes(long bytes)
public static void illegalArgumentException(Exception e)
public static void illegalArgumentException(String msg)
public static boolean isRoot(String path) throws InvalidPathException
path
- The path to checkInvalidPathException
public static InetSocketAddress parseInetSocketAddress(String address) throws IOException
address
- IOException
public static long parseSpaceSize(String spaceSize)
spaceSize
- the size of a space, e.g. 10GB, 5TB, 1024public static void printByteBuffer(org.apache.log4j.Logger LOG, ByteBuffer buf)
public static void printTimeTakenMs(long startTimeMs, org.apache.log4j.Logger logger, String message)
public static void printTimeTakenNs(long startTimeNs, org.apache.log4j.Logger logger, String message)
public static void runtimeException(Exception e)
public static void runtimeException(String msg)
public static void setLocalFileStickyBit(String file)
file
- absolute file pathpublic static void sleepMs(org.apache.log4j.Logger logger, long timeMs)
public static void tempoaryLog(String msg)
public static void touch(String path) throws IOException
IOException
public static void validatePath(String path) throws InvalidPathException
path
- The path to checkInvalidPathException
- If the path is not properly formedCopyright © 2014. All rights reserved.