code: public static String stripBlankLines(String text) {
          if (text == null) {
              return null;
          }
  
          try {
              StringBuffer output = new StringBuffer();
              BufferedReader in = new BufferedReader(new StringReader(text));
              boolean doneOneLine = false;
              while (true) {
                  String line = in.readLine();
                  if (line == null) {
                      break;
                  }
  
                  if (line.trim().length() > 0) {
                      output.append(line);
                      output.append('\n');
                      doneOneLine = true;
                  }
              }
  
              if (!doneOneLine) {
                  output.append('\n');
              }
  
              return output.toString();
          } catch (IOException e) {
              throw new IllegalArgumentException(e);
          }
      }
docs: Remove all blank lines from a string. A blank line is defined to be a
  line where the only characters are whitespace. We always ensure that the
  line contains a newline at the end.
  
  @param text
  The string to strip blank lines from
  @return The blank line stripped reply