String[] getCommands(File file) throws IOException {
    List<String> cmds = new LinkedList<String>();
    try (BufferedReader reader =
             new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
      StringBuilder cmd = null;
      while (true) {
        String scriptLine = reader.readLine();

        if (scriptLine == null) {
          break;
        }

        String trimmedLine = scriptLine.trim();
        if (getOpts().getTrimScripts()) {
          scriptLine = trimmedLine;
        }

        if (cmd != null) {
          // we're continuing an existing command
          cmd.append("\n");
          cmd.append(scriptLine);
          if (trimmedLine.endsWith(getOpts().getDelimiter())) {
            // this command has terminated
            cmds.add(cmd.toString());
            cmd = null;
          }
        } else {
          // we're starting a new command
          if (needsContinuation(scriptLine)) {
            // multi-line
            cmd = new StringBuilder(scriptLine);
          } else {
            // single-line
            cmds.add(scriptLine);
          }
        }
      }

      if (cmd != null) {
        // ### REVIEW: oops, somebody left the last command
        // unterminated; should we fix it for them or complain?
        // For now be nice and fix it.
        cmd.append(getOpts().getDelimiter());
        cmds.add(cmd.toString());
      }
    }
    return cmds.toArray(new String[0]);
  }
Test whether a line is a comment.

@param line
         the line to be tested

@return true if a comment
beeline/src/java/org/apache/hive/beeline/BeeLine.java