private String getEditor() {
   // if we have editor in the system properties, it should
   // override the env so we check that first
   String editor = System.getProperty("EDITOR");
   if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) {
     editor = System.getenv().get("EDITOR");
   }
   if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) {
     editor = System.getenv("VISUAL");
   }
   if (org.apache.commons.lang3.StringUtils.isEmpty(editor)) {
     editor = "/bin/vi";
   }
   return editor;
 }
Пример #2
0
 public static String randomName() {
   List<String> results = new ArrayList<>();
   StringBuffer buffer = new StringBuffer();
   while (buffer.length() <= 15) {
     String result = WORDS.get(RandomUtils.nextInt(0, WORDS.size()));
     if (!results.contains(result)) {
       results.add(result);
       buffer.append(result);
     }
   }
   return org.apache.commons.lang3.StringUtils.join(results, " ");
 }
Пример #3
0
 static {
   InputStream inputStream = null;
   try {
     inputStream = FileUtils.openInputStream(new File(Database.DICTIONARY));
     for (String word : IOUtils.readLines(inputStream, "UTF-8")) {
       WORDS.add(org.apache.commons.lang3.StringUtils.capitalize(word));
     }
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     IOUtils.closeQuietly(inputStream);
   }
 }
Пример #4
0
 /**
  * Method use OpenCsv Library for
  *
  * @param clazz the Class of the Bean.
  * @param fileInputCsv the File CSV to parse.
  * @param separator the char separator.
  * @param <T> the generic variable.
  * @return the List of Bean parsed from the CSV file.
  */
 public static <T> List<T> parseCSVFileAsList(Class<T> clazz, File fileInputCsv, char separator) {
   try {
     List<T> beans;
     try ( // create CSVReader object
     CSVReader reader = new CSVReader(new FileReader(fileInputCsv), separator)) {
       beans = new ArrayList<>();
       // read line by line
       String[] record;
       // skip header row
       String[] headers = reader.readNext();
       // read content
       while ((record = reader.readNext()) != null) {
         T t = ReflectionUtilities.invokeConstructor(clazz);
         for (int i = 0; i < record.length; i++) {
           String nameMethod = "set" + org.apache.commons.lang3.StringUtils.capitalize(headers[i]);
           // invoke setter method
           if (ReflectionUtilities.checkMethod(clazz, nameMethod)) {
             ReflectionUtilities.invokeSetter(t, nameMethod, record[i]);
           } else {
             logger.warn(
                 "Not exists the Method with name:"
                     + nameMethod
                     + " on the Bean:"
                     + t.getClass().getName());
           }
         }
         beans.add(t);
       }
     }
     return beans;
   } catch (IOException e) {
     logger.error(
         "Can't parse the CSV file:" + fileInputCsv.getAbsolutePath() + " -> " + e.getMessage(),
         e);
     return new ArrayList<>();
   }
 }