Update ves-agent dependency
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / commons / utils / StringUtil.java
1 /*
2  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.vfc.nfvo.emsdriver.commons.utils;
17
18 import java.io.File;
19 import java.io.PrintWriter;
20 import java.io.StringWriter;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class StringUtil {
25
26     private static final Logger log = LoggerFactory.getLogger(StringUtil.class);
27     public static String getStackTrace(Throwable t) {
28
29         try( 
30             StringWriter sw = new StringWriter();
31             PrintWriter pw = new PrintWriter(sw)){
32             t.printStackTrace(pw);
33             pw.flush();
34             sw.flush();
35             return sw.getBuffer().toString();
36         } catch (Exception e) {
37                 log.error("getStackTrace : ",e);
38         } 
39         return null;
40     }
41
42     public static String addSlash(String dirName) {
43         if (dirName.endsWith(File.separator))
44             return dirName;
45         return dirName + File.separator;
46     }
47
48     public static boolean isBank(String str) {
49             return (str == null || str.trim().length() == 0); 
50     }
51 }