/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package vn.mobile.id.utils; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.log4j.Logger; import vn.mobile.id.objects.FmsUuidListJsonObject; /** * * @author TuoiCM */ public class Utils { // private static final Logger logger = Logger.getLogger(Utils.class); // // public static String printStackTrace(Exception e) { String result = null; try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); result = sw.toString(); pw.close(); sw.close(); } catch (IOException ex) { ex.printStackTrace(); } return result; } // // public static String walk(String path, String fileName) { try (Stream walk = Files.walk(Paths.get(path))) { List result = walk.filter(Files::isRegularFile) .map(x -> x.toString()).collect(Collectors.toList()); for (String f : result) { if (f.contains(fileName)) { return f; } } } catch (IOException e) { e.printStackTrace(); } return null; } // // public static String getPropertiesFile(String fileName) { /* File folder = new File(System.getProperty("jboss.server.base.dir")); File[] listOfFiles = folder.listFiles(); int i; for (i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { String filePath = listOfFiles[i].getAbsolutePath(); LOG.error(filePath); if (filePath.contains(fileName)) { return filePath; } } } return null; */ return walk(System.getProperty("jboss.server.base.dir"), fileName); } // // public static boolean isNullOrEmpty(String value) { if (value == null) { return true; } if (value.compareTo("") == 0) { return true; } return false; } public static boolean isNullOrEmpty(String[] value) { if (value == null) { return true; } if (value.length == 0) { return true; } return false; } public static boolean isNullOrEmpty(byte[] value) { if (value == null) { return true; } if (value.length == 0) { return true; } return false; } public static boolean isNullOrEmpty(List value) { if (value == null) { return true; } if (value.isEmpty()) { return true; } return false; } // // public static String readFile(String path, Charset encoding) throws IOException { String content = Files.lines(Paths.get(path), encoding) .collect(Collectors.joining(System.lineSeparator())); return content; } // // public static FmsUuidListJsonObject getUuidListJson(String pathJsonFile) { try { ObjectMapper objectMapper = new ObjectMapper(); FmsUuidListJsonObject uuidListJsonObject = objectMapper.readValue(new File(pathJsonFile), FmsUuidListJsonObject.class); return uuidListJsonObject; } catch (Exception ex) { logger.error(printStackTrace(ex)); return null; } } // }