@Test public void addLeadingZeroTest() throws IOException { for (int k = 0; k < 10; k ++) { Assert.assertEquals("" + k, CommonUtils.addLeadingZero(k, 1)); Assert.assertEquals("0" + k, CommonUtils.addLeadingZero(k, 2)); Assert.assertEquals("00" + k, CommonUtils.addLeadingZero(k, 3)); Assert.assertEquals("000" + k, CommonUtils.addLeadingZero(k, 4)); Assert.assertEquals("0000" + k, CommonUtils.addLeadingZero(k, 5)); } for (int k = 10; k < 100; k ++) { Assert.assertEquals("" + k, CommonUtils.addLeadingZero(k, 1)); Assert.assertEquals("" + k, CommonUtils.addLeadingZero(k, 2)); Assert.assertEquals("0" + k, CommonUtils.addLeadingZero(k, 3)); Assert.assertEquals("00" + k, CommonUtils.addLeadingZero(k, 4)); Assert.assertEquals("000" + k, CommonUtils.addLeadingZero(k, 5)); } }
public static String addLeadingZero(int number, int width) throws IOException { if (number < 0) { throw new IOException("The number has to be non-negative: " + number); } if (width <= 0) { throw new IOException("The width has to be positive: " + width); } String result = number + ""; while (result.length() < width) { result = "0" + result; } return result; }
CommonUtils { public static String addLeadingZero(int number, int width) throws IOException { if (number < 0) { throw new IOException("The number has to be non-negative: " + number); } if (width <= 0) { throw new IOException("The width has to be positive: " + width); } String result = number + ""; while (result.length() < width) { result = "0" + result; } return result; } }
CommonUtils { public static String addLeadingZero(int number, int width) throws IOException { if (number < 0) { throw new IOException("The number has to be non-negative: " + number); } if (width <= 0) { throw new IOException("The width has to be positive: " + width); } String result = number + ""; while (result.length() < width) { result = "0" + result; } return result; }  }
CommonUtils { public static String addLeadingZero(int number, int width) throws IOException { if (number < 0) { throw new IOException("The number has to be non-negative: " + number); } if (width <= 0) { throw new IOException("The width has to be positive: " + width); } String result = number + ""; while (result.length() < width) { result = "0" + result; } return result; }  static String addLeadingZero(int number, int width); static void changeLocalFilePermission(String filePath, String perms); static void changeLocalFileToFullPermission(String filePath); static String cleanPath(String path); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static String concat(Object... args); 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); static String getParent(String path); static String[] getPathComponents(String path); static String getPathWithoutSchema(String path); static String getSizeFromBytes(long bytes); static void illegalArgumentException(Exception e); static void illegalArgumentException(String msg); static boolean isRoot(String path); static String listToString(List<T> list); static String parametersToString(Object... objs); static InetSocketAddress parseInetSocketAddress(String address); static long parseSpaceSize(String spaceSize); static void printByteBuffer(Logger LOG, ByteBuffer buf); static void printTimeTakenMs(long startTimeMs, Logger logger, String message); static void printTimeTakenNs(long startTimeNs, Logger logger, String message); static void runtimeException(Exception e); static void runtimeException(String msg); static void setLocalFileStickyBit(String file); static void sleepMs(Logger logger, long timeMs); static void tempoaryLog(String msg); static String[] toStringArray(ArrayList<String> src); static void touch(String path); static void validatePath(String path); }
CommonUtils { public static String addLeadingZero(int number, int width) throws IOException { if (number < 0) { throw new IOException("The number has to be non-negative: " + number); } if (width <= 0) { throw new IOException("The width has to be positive: " + width); } String result = number + ""; while (result.length() < width) { result = "0" + result; } return result; }  static String addLeadingZero(int number, int width); static void changeLocalFilePermission(String filePath, String perms); static void changeLocalFileToFullPermission(String filePath); static String cleanPath(String path); static ByteBuffer cloneByteBuffer(ByteBuffer buf); static List<ByteBuffer> cloneByteBufferList(List<ByteBuffer> source); static String concat(Object... args); 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); static String getParent(String path); static String[] getPathComponents(String path); static String getPathWithoutSchema(String path); static String getSizeFromBytes(long bytes); static void illegalArgumentException(Exception e); static void illegalArgumentException(String msg); static boolean isRoot(String path); static String listToString(List<T> list); static String parametersToString(Object... objs); static InetSocketAddress parseInetSocketAddress(String address); static long parseSpaceSize(String spaceSize); static void printByteBuffer(Logger LOG, ByteBuffer buf); static void printTimeTakenMs(long startTimeMs, Logger logger, String message); static void printTimeTakenNs(long startTimeNs, Logger logger, String message); static void runtimeException(Exception e); static void runtimeException(String msg); static void setLocalFileStickyBit(String file); static void sleepMs(Logger logger, long timeMs); static void tempoaryLog(String msg); static String[] toStringArray(ArrayList<String> src); static void touch(String path); static void validatePath(String path);  }