Coverage Report - ca.uhn.hl7v2.hoh.util.StringUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
StringUtils
75%
22/29
62%
15/24
4.4
 
 1  
 package ca.uhn.hl7v2.hoh.util;
 2  
 
 3  
 import java.io.ByteArrayInputStream;
 4  
 import java.io.InputStreamReader;
 5  
 import java.nio.charset.Charset;
 6  
 
 7  0
 public class StringUtils {
 8  
 
 9  5
         public static final String LINE_SEP = System.getProperty("line.separator");
 10  
 
 11  
         /**
 12  
          * Null safe equals comparison
 13  
          */
 14  
         public static boolean equals(String theString1, String theString2) {
 15  250
                 if (theString1 == null && theString2 == null) {
 16  0
                         return true;
 17  
                 }
 18  250
                 if (theString1 == null || theString2 == null) {
 19  0
                         return false;
 20  
                 }
 21  250
                 return theString1.equals(theString2);
 22  
         }
 23  
 
 24  
         public static boolean isNotBlank(String theString) {
 25  1265
                 return !isBlank(theString);
 26  
         }
 27  
 
 28  
         public static boolean isBlank(String theString) {
 29  
                 int strLen;
 30  2540
                 if (theString == null || (strLen = theString.length()) == 0) {
 31  295
                         return true;
 32  
                 }
 33  2245
                 for (int i = 0; i < strLen; i++) {
 34  2245
                         if ((Character.isWhitespace(theString.charAt(i)) == false)) {
 35  2245
                                 return false;
 36  
                         }
 37  
                 }
 38  0
                 return true;
 39  
         }
 40  
 
 41  
         public static String defaultString(String theString) {
 42  410
                 if (theString == null) {
 43  0
                         return "";
 44  
                 }
 45  410
                 return theString;
 46  
         }
 47  
 
 48  
         public static String asciiEscape(byte[] theBytes, Charset theCharset) {
 49  20
                 StringBuilder b = new StringBuilder();
 50  
 
 51  
                 try {
 52  20
                         InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(theBytes), theCharset);
 53  1770
                         while (reader.ready()) {
 54  1750
                                 char read = (char) reader.read();
 55  1750
                                 if (read < 32) {
 56  50
                                         b.append('[').append((int) read).append(']');
 57  
                                 } else {
 58  1700
                                         b.append(read);
 59  
                                 }
 60  1750
                         }
 61  0
                 } catch (Exception e) {
 62  0
                         b.append("ERROR: ").append(e.toString());
 63  20
                 }
 64  20
                 return b.toString();
 65  
         }
 66  
 
 67  
 }