private void buildTextLine(
      StringBuffer lineBuffer, String[] rowData, int[] rowSizes, int columnSpacing) {

    for (int i = 0; i < rowData.length; i++) {

      String data = rowData[i];
      int len = rowSizes[i];

      if (i == 2) {

        // The length should be aligned right
        lineBuffer.append(CustomUtil.repeat(" ", len - data.length()));
        lineBuffer.append(data);

      } else {

        // Other values should be aligned left
        lineBuffer.append(data);
        lineBuffer.append(CustomUtil.repeat(" ", len - data.length()));
      }

      // Print column spacing
      lineBuffer.append(CustomUtil.repeat(" ", columnSpacing));
    }

    lineBuffer.append("\n");
  }
  /**
   * This method is designated to build the data for the directory listing.
   *
   * <p>Subclasses must implement this method and write the generated data into the given output
   * stream.
   *
   * @param sid The current session's ID.
   * @param out The output stream to write the list data to.
   * @throws IOException If any IO errors occur.
   */
  public void generateDirectoryListing(UUID sid, OutputStream out) throws IOException {

    String title = "Index of " + this.getRequestURI().getPath() + getFormattedLineBreak(2);

    if (this.isHTMLFormat()) {

      String cssPath = "/system/styles/directory.list.css";

      StringBuffer htmlHeader = new StringBuffer();
      htmlHeader
          .append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
          .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n")
          .append("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")
          .append("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n")
          .append("<head>\n")
          .append("<title>Contents of ")
          .append(this.getRequestURI().getPath())
          .append("</title>\n")
          .append("<link rel=\"icon\" href=\"/favicon.ico\" type=\"image/x-icon\" />\n")
          .append("<link rel=\"stylesheet\" type=\"text/css\" href=\"")
          .append(cssPath)
          .append("\" />")
          .append("</head>\n")
          .append("\n")
          .append("<body>\n")
          .append("\n")
          .
          // append( "<h3><img src=\"icon_mini.png\" alt=\"Icon\" id=\"icon_mini\" /> " ).append(
          // title ).append( "</h3>\n"  ).
          append("<h2>")
          .append(title)
          .append("</h2>\n")
          .append("\n");

      out.write(htmlHeader.toString().getBytes());

    } else {

      out.write(title.getBytes());
    }

    // First make the '..' navigation file (if parent exists)
    if (this.isHTMLFormat() && !this.getRequestURI().getPath().equals("/")) {

      String parentPath = new File(this.getRequestURI().getPath()).getParent();
      String parentLink = "<a href=\"" + parentPath + "\">parent dir</a><br/><br/>\n";
      out.write(parentLink.getBytes());
    }

    if (this.isHTMLFormat()) {

      String tableStart = "<table>\n";
      out.write(tableStart.getBytes());
    }

    // Write temp file data into buffer
    int totalTextWidth = this.generateFileListing(out);

    Date currentDate = new Date(System.currentTimeMillis());
    String footLine =
        getFormattedLineBreak(2)
            + "Document generated "
            + this.getDateFormat().format(currentDate)
            + getFormattedLineBreak();

    if (this.isHTMLFormat()) footLine += "<hr />\n";
    else footLine += CustomUtil.repeat("=", totalTextWidth) + getFormattedLineBreak();

    footLine += this.getHTTPHandler().getSoftwareName() + getFormattedLineBreak();

    if (this.isHTMLFormat()) {

      String htmlFooter = "</table>\n" + footLine + "</body>\n" + "</html>\n";
      out.write(htmlFooter.getBytes());

    } else {

      out.write(footLine.getBytes());
    }
  }