001/** 002 * Copyright (C) 2006-2024 Talend Inc. - www.talend.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.talend.sdk.component.runtime.manager.util; 017 018import static lombok.AccessLevel.PRIVATE; 019 020import java.nio.charset.StandardCharsets; 021import java.util.Base64; 022 023import lombok.NoArgsConstructor; 024 025@NoArgsConstructor(access = PRIVATE) 026public class IdGenerator { 027 028 /** 029 * /!\ keep this algorithm private for now and don't assume it is reversible, we 030 * can revise it to something more compressed later 031 * 032 * @param args the list of strings to concatenate and encode as an identifier. 033 * @return a {@link Base64} url encoded string from the strings parameter joined 034 * by # 035 */ 036 public static String get(final String... args) { 037 038 if (args == null || args.length == 0) { 039 return null; 040 } 041 042 return Base64 043 .getUrlEncoder() 044 .withoutPadding() 045 .encodeToString(String.join("#", args).getBytes(StandardCharsets.UTF_8)); 046 } 047 048}