| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package org.apache.hudi.common.util; |
| |
| /** |
| * Simple utility for operations on strings. |
| */ |
| public class StringUtils { |
| |
| /** |
| * <p> |
| * Joins the elements of the provided array into a single String containing the provided list of elements. |
| * </p> |
| * |
| * <p> |
| * No separator is added to the joined String. Null objects or empty strings within the array are represented by empty |
| * strings. |
| * </p> |
| * |
| * <pre> |
| * StringUtils.join(null) = null |
| * StringUtils.join([]) = "" |
| * StringUtils.join([null]) = "" |
| * StringUtils.join(["a", "b", "c"]) = "abc" |
| * StringUtils.join([null, "", "a"]) = "a" |
| * </pre> |
| */ |
| public static <T> String join(final String... elements) { |
| return join(elements, ""); |
| } |
| |
| public static <T> String joinUsingDelim(String delim, final String... elements) { |
| return join(elements, delim); |
| } |
| |
| public static String join(final String[] array, final String separator) { |
| if (array == null) { |
| return null; |
| } |
| return org.apache.hadoop.util.StringUtils.join(separator, array); |
| } |
| |
| public static String toHexString(byte[] bytes) { |
| StringBuilder sb = new StringBuilder(bytes.length * 2); |
| for (byte b : bytes) { |
| sb.append(String.format("%02x", b)); |
| } |
| return sb.toString(); |
| } |
| |
| public static boolean isNullOrEmpty(String str) { |
| return str == null || str.length() == 0; |
| } |
| } |