/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package real.estate.io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import real.estate.dao.ListHouse;

/**
 *
 * @author Chathu
 */
public class HouseFile {

private static BufferedReader inFile;
private static PrintWriter outFile;
private static boolean isInFileOpen = false;
private static boolean isOutFileOpen = false;
private static String stringInput ="";
    
public static void reset() throws IOException{
    if(isInFileOpen){
        inFile.close();
    }
    if(isOutFileOpen){
        outFile.close();
    }
    inFile = new BufferedReader(new FileReader("house_details.dat"));
    isInFileOpen = true;
    stringInput = inFile.readLine();
}
public static void resetForWrite() throws IOException{
    if(isInFileOpen){
        inFile.close();
    }
    if(isOutFileOpen){
        outFile.close();
    }
    outFile = new PrintWriter(new FileWriter("house_details.dat"));
    isOutFileOpen = true;
}
public static boolean isMoreHousesExist(){
    return stringInput != null;
   
    }
public static void putDataToFile(ListHouse houseItem){
    outFile.println(houseItem.firstName());
    outFile.println(houseItem.lastName());
    outFile.println(houseItem.lotNumber());
    outFile.println(houseItem.price());
    outFile.println(houseItem.squareFeet());
    outFile.println(houseItem.numberOfBedRooms());
    
}
public static ListHouse getNextHouseItem() throws IOException{
    String lastName;
    String firstName;
    int lotNo;
    int price;
    int squareFeet;
    int noOfBedRooms;
    
    lastName=stringInput;
    firstName=inFile.readLine();
    lotNo=Integer.parseInt(inFile.readLine());
    price=Integer.parseInt(inFile.readLine());
    squareFeet=Integer.parseInt(inFile.readLine());
    noOfBedRooms=Integer.parseInt(inFile.readLine());
    
    stringInput=inFile.readLine();
    
    ListHouse hs1=new ListHouse(lastName,firstName,lotNo,price,squareFeet,noOfBedRooms);
    System.out.println("correct");
    return hs1;
}
public static void closeFile() throws IOException{
    if(isInFileOpen)
        inFile.close();
    if(isOutFileOpen)
        outFile.close();
}

public static void main(String []args) throws IOException{
    HouseFile hs=new HouseFile();
    hs.reset();
    hs.resetForWrite();
    hs.isMoreHousesExist();
   // hs.getNextHouseItem();
    
    }

}

@@ -215,2174 +215,199 @@
 ort 
-java.io.BufferedReader;%0Aimport java.io.FileReader;%0Aimport java.io.FileWriter;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0Aimport real.estate.dao.ListHouse;%0A%0A/**%0A *%0A * @author Chathu%0A */%0Apublic class HouseFile %7B%0A%0Aprivate static BufferedReader inFile;%0Aprivate static PrintWriter outFile;%0Aprivate static boolean isInFileOpen = false;%0Aprivate static boolean isOutFileOpen = false;%0Aprivate static String stringInput =%22%22;%0A    %0Apublic static void reset() throws IOException%7B%0A    if(isInFileOpen)%7B%0A        inFile.close();%0A    %7D%0A    if(isOutFileOpen)%7B%0A        outFile.close();%0A    %7D%0A    inFile = new BufferedReader(new FileReader(%22house_details.dat%22));%0A    isInFileOpen = true;%0A    stringInput = inFile.readLine();%0A%7D%0Apublic static void resetForWrite() throws IOException%7B%0A    if(isInFileOpen)%7B%0A        inFile.close();%0A    %7D%0A    if(isOutFileOpen)%7B%0A        outFile.close();%0A    %7D%0A    outFile = new PrintWriter(new FileWriter(%22house_details.dat%22));%0A    isOutFileOpen = true;%0A%7D%0Apublic static boolean isMoreHousesExist()%7B%0A    return stringInput != null;%0A   %0A    %7D%0Apublic static void putDataToFile(ListHouse houseItem)%7B%0A    outFile.println(houseItem.firstName());%0A    outFile.println(houseItem.lastName());%0A    outFile.println(houseItem.lotNumber());%0A    outFile.println(houseItem.price());%0A    outFile.println(houseItem.squareFeet());%0A    outFile.println(houseItem.numberOfBedRooms());%0A    %0A%7D%0Apublic static ListHouse getNextHouseItem() throws IOException%7B%0A    String lastName;%0A    String firstName;%0A    int lotNo;%0A    int price;%0A    int squareFeet;%0A    int noOfBedRooms;%0A    %0A    lastName=stringInput;%0A    firstName=inFile.readLine();%0A    lotNo=Integer.parseInt(inFile.readLine());%0A    price=Integer.parseInt(inFile.readLine());%0A    squareFeet=Integer.parseInt(inFile.readLine());%0A    noOfBedRooms=Integer.parseInt(inFile.readLine());%0A    %0A    stringInput=inFile.readLine();%0A    %0A    ListHouse hs1=new ListHouse(lastName,firstName,lotNo,price,squareFeet,noOfBedRooms);%0A    System.out.println(%22correct%22);%0A    return hs1;%0A%7D%0Apublic static void closeFile() throws IOException%7B%0A    if(isInFileOpen)%0A        inFile.close();%0A    if(isOutFileOpen)%0A        outFile.close
+real.estate.dao.impl.SortedList;%0A%0A%0A/**%0A *%0A * @author Chathu%0A */%0Apublic class HouseFile %7B%0A%0A    %0Apublic static SortedList readJSONFileToList()%7B%0A    throw new UnsupportedOperationException
 ();%0A%7D%0A
-%0A
 publ
@@ -425,188 +425,32 @@
 oid 
-main(String %5B%5Dargs) throws IOException%7B%0A    HouseFile hs=new HouseFile();%0A    hs.reset();%0A    hs.resetForWrite();%0A    hs.isMoreHousesExist();%0A   // hs.getNextHouseItem();
+writeJSONToFile()%7B
 %0A    %0A
-    
 %7D%0A%0A%7D

Add read and write methods