private int generateFileListing( OutputStream out ) 
	throws IOException {

	// WARNING: due to the AbstractDirectoryResource-specs it is NOT GUARANTEED that the file
	//          is really a directory!


	StringBuffer lineBuffer = new StringBuffer();
	if( !this.getDirectoryFile().isDirectory() ) {

	    // Print the file itself as a listing? :)
	    // Print an error message? What about the status code in this case???

	    //buildLine( lineBuffer, this.getDirectoryFile() );
	    //out.write( lineBuffer.toString().getBytes() );
	    //lineBuffer.delete( 0, lineBuffer.length() );

	    String message = "File is a directory and cannot be listed.\n";
	    out.write( message.getBytes() );

	    return -1;
	}


	File[] files = this.getDirectoryFile().listFiles();
	files = sortFiles( files );

	if( this.isHTMLFormat() ) {
	
	    for( int i = 0; i < files.length; i++ ) {
		
		// Do NOT include files the file-filter does not allow to be listed!
		if( !this.getFileFilter().acceptListing(files[i]) )
		continue;  // Hide due to security reasons
		
		
		buildHTMLLine( lineBuffer, files[i] );
		out.write( lineBuffer.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8.name()) );
		lineBuffer.delete( 0, lineBuffer.length() );
		
	    }

	    return -1;

	} else {

	    List<String[]> tableData = new ArrayList<String[]>( files.length );
	    int[] rowSizes = null;
	    String[] rowData = null;
	    for( int i = 0; i < files.length; i++ ) {
		
		rowData = collectRowData( files[i] );
		tableData.add( rowData );

		if( rowSizes == null )
		    rowSizes = new int[ rowData.length ];

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

		    rowSizes[c] = Math.max( rowSizes[c], rowData[c].length() );
		}

	    } // END for
	    
	    // Generate text output
	    int totalWidth = 80;     // 80 for the case there are not files
	    for( int i = 0; i < tableData.size(); i++ ) {		

		rowData = tableData.get( i );
		buildTextLine( lineBuffer,
			       rowData,
			       rowSizes,
			       4    // columnSpacing
			       );
		out.write( lineBuffer.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8.name()) );
		totalWidth = lineBuffer.length() - 1;  // do not include line break
		lineBuffer.delete( 0, lineBuffer.length() );

	    }

	    return totalWidth;
	}
    }