BufferedReader == reader.mark() ERROR
This is a basice i/o program. It reads data, stores it in an array and then writes a file based on a filtering system.
The code:
import java.io.*;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.lang.String;
import java.lang.IndexOutOfBoundsException;
publicclass bigbook{
public bigbook()
{
Day = 0;
Open = 0;
High = 0;
Low = 0;
Close = 0;
Vol = 0;
Trade = 0;
Shares = 0;
TradingDay = 0;
PL = 0;
ExitDay = 0;
}
publicvoid enterDay(double date)
{
Day = date;
}
publicvoid enterOpen(double open)
{
Open = open;
}
publicvoid enterHigh(double high)
{
High = high;
}
publicvoid enterLow(double low)
{
Low = low;
}
publicvoid enterClose(double close)
{
Close = close;
}
publicvoid enterTradingDay(int day)
{
TradingDay = day;
}
publicvoid enterPL(double pandl)
{
PL = pandl;
}
publicvoid enterVol(double vol)
{
Vol = vol;
}
publicvoid enterExit(double dayfive)
{
ExitDay = dayfive;
}
publicvoid enterExitPrice(double exitspot)
{
ExitPrice = exitspot;
}
publicdouble getExitPrice()
{
return ExitPrice;
}
publicdouble getExit()
{
return ExitDay;
}
publicdouble getHigh()
{
return High;
}
publicdouble getPL()
{
return PL;
}
publicdouble getClose()
{
return Close;
}
publicdouble getShares()
{
return Shares;
}
publicdouble getDate()
{
return Day;
}
publicdouble getPosition()
{
return Trade;
}
publicint getTradingDay()
{
return TradingDay;
}
publicdouble getVolume()
{
return Vol;
}
publicvoid numShares()
{
Shares = 100000/Close;
}
publicvoid goLong()
{
Trade = 1;
}
publicvoid sellShort()
{
Trade = -1;
}
privatedouble Day;
privatedouble Open;
privatedouble High;
privatedouble Low;
privatedouble Close;
privatedouble Vol;
privatedouble Trade;
privatedouble Shares;
privateint TradingDay;
privatedouble PL;
privatedouble ExitDay;
privatedouble ExitPrice;
privatestaticvoid ReadFile(BufferedReader reader)throws IOException{
String nextLine = reader.readLine();// read first line from br
int runCount = 0;
int closeCount = 0;
ArrayList theDayList =new ArrayList();
ArrayList theResultsList =new ArrayList();
StringTokenizer td;
do
{
while ( runCount<2500 && nextLine !=null){
int roc = 10;
// roc == run overlap count
runCount++;
bigbook Zbigbook =new bigbook();
td =new StringTokenizer(nextLine,",");
while (td.hasMoreTokens()){
Zbigbook.enterDay(Double.parseDouble((String)td.nextToken()));
Zbigbook.enterOpen(Double.parseDouble((String)td.nextToken()));
Zbigbook.enterHigh(Double.parseDouble((String)td.nextToken()));
Zbigbook.enterLow(Double.parseDouble((String)td.nextToken()));
td.nextToken();
Zbigbook.enterVol(Double.parseDouble((String)td.nextToken()));
Zbigbook.enterClose(Double.parseDouble((String)td.nextToken()));
Zbigbook.enterTradingDay(closeCount);
}
theDayList.add(Zbigbook);
nextLine = reader.readLine();
if(runCount == 2000)
{
reader.mark(roc);
}
if(runCount == 2500 || nextLine ==null)
{
reader.reset();
closeCount += runCount;
ArrayList theInterimList = (ArrayList)Test(theDayList);
for (int i=0; i<theInterimList.size(); i++){
try{
bigbook Xbigbook = (bigbook)theInterimList.get(i);
theResultsList.add(Xbigbook);
}
catch (IndexOutOfBoundsException e){
break;
}
}
if(nextLine ==null){
PrintWriter pw;
System.out.print("Send output where? ");
String dest = (new BufferedReader (new InputStreamReader(System.in))).readLine();
if (dest.equals("System.out"))
pw =new PrintWriter(System.out);
else
pw =new PrintWriter(new FileWriter(dest));
pw.println("Runs " + closeCount +" closes.");
for (int i=0; i><theResultsList.size(); i++){
try{
bigbook Ybigbook = (bigbook)theResultsList.get(i);
pw.println(Ybigbook.getDate()+"," + Ybigbook.getVolume()+","
+Ybigbook.getClose());
}
catch (IndexOutOfBoundsException e){
break;
}
}
pw.close();
}
runCount = 0;
theDayList =new ArrayList();
}
}
}
while(nextLine !=null);
}
privatestatic ArrayList Test(ArrayList list)throws IOException{
ArrayList theRelayedList = list;
ArrayList theVolList =new ArrayList();
for (int i = 0; i><theRelayedList.size(); i++)
{
try{
bigbook Abigbook = (bigbook)theRelayedList.get(i);
double volume = Abigbook.getVolume();
if(volume > 1000)
{
theVolList.add(Abigbook);
}
}
catch (IndexOutOfBoundsException e){
break;
}
}
return theVolList;
}
publicstaticvoid main(String[] args){
String filename;
// Prompt user for file name
System.out.print("Enter file name: " );
// Read user's input from System.in
InputStreamReader isr =new InputStreamReader(System.in);
BufferedReader br =new BufferedReader(isr);
FileReader fr;
// Iteratively prompt user until file found
try{
while (true){
filename = br.readLine();
try{
fr =new FileReader(filename);
break;
}
catch (FileNotFoundException e){
System.out.print("Re-enter file name: ");
}
}
ReadFile(new BufferedReader (fr));
}
catch (IOException e){
System.out.println(e);
return;
}
}
}
The problem is that the mark() method is becoming invalidated.
This is the first time I've tried to implement the mark method. I know that the reset() method is supposed to start the reader back at the place where I called mark().
Does it have something to do with the if statement where the mark() call is?

