I'm trying to enhance a program that reads in a flat file that conatains multiple record types and only writes/prints out the first record of each type of record in the file. I created beans for each record type because I needed to shift the order of the fields in each record before printing them out.
I am able to write out each record, but if a record has multiple rows all the rows are being printed/written to a file. Is there a way to delete the number of rows in my buffer before I execute system.out.println for a specific bean? Any other suggestions would be appreciated.
Thank you in advance for any suggestions!

Here is the code:

public class ComplexFile {
public static void main(String[] args) {
ConfigurationReader parser = new ConfigurationReader();
try {
FileFormat ff = parser.loadConfigurationFile(args[0]);
InputStream in = new FileInputStream(args[1]);
BufferedReader bufIn = new BufferedReader(new InputStreamReader(in));

MatchedRecord results;
while ((results = ff.getNextRecord(bufIn)) != null) {
if (results.getRecordName().equals("onerecord")) {

if (results.getRecordName().equals("tworecord")) {

if (results.getRecordName().equals("threerecord")) {
System.out.println(results.getBean("threerecord")) ;

if (results.getRecordName().equals("fourrecord")) {

if (results.getRecordName().equals("fiverecord")) {
if (results.getRecordName().equals("sixrecord")) {

catch (ComplexUnsetFieldValueException complexUnsetFieldValueError) {
complexUnsetFieldValueError.printStackTrace(); }
catch (ComplexUnsetFieldValueException ComplexUnsetFieldValueError) {
ComplexUnsetFieldValueError.printStackTrace(); }
catch (ComplexConfigurationValueException ComplexConfigurationValueError) {
ComplexConfigurationValueError.printStackTrace(); }
catch (FileNotFoundException e) {
e.printStackTrace(); }
catch (ComplexInvalidRecordException e) {
e.printStackTrace(); }
catch (ComplexInputLineLengthException e) {
e.printStackTrace(); }
catch (ComplexConversionException e) {
e.printStackTrace(); .