Oi
Estou a fazer um parse de um ficheiro de log do Microsoft Exchange 5.5. Só alguns campos são necessários, tendo já conseguido resolver esse problema. Contudo, quando tento fazer o parse do ficheiro em que este seja maior que 800 kb, o programa não consegue fazer o parse
Agradecia que alguém me pudesse dar umas dicas.
----
import java.util.Date;
import java.io.;
import java.text.;
import java.util.Properties;
public class FileUtils
{
private Thread timerThread;
private Timer timerClass;
public FileUtils()
{
timerClass = new Timer(this);
timerThread = new Thread(timerClass);
timerThread.start();
}
public String getTodaysFileName()
{
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMdd");
String fileName = df.format(date);
fileName = ".".concat(fileName).concat(".log");
return fileName;
}
public String getFileInStringFormat()
{
String fileContent = new String(),str;
DataInputStream fds = null;
FileInputStream fis = null;
try
{
fis = new FileInputStream(getTodaysFileName());
fds = new DataInputStream(fis);
while((str = fds.readLine()) != null)
fileContent += str;
}
catch(IOException e){System.out.println("Erro ao ler o ficheiro de log");}
catch(Exception e2){System.out.println("Error : "+e2.getMessage());}
finally
{
try{fds.close();} //closes file
catch(Exception e){e.printStackTrace();}
}
return fileContent;
}
public void createTodaysFile(String todaysFile)
{
FileOutputStream os = null;
DataOutputStream dos = null;
try
{
os = new FileOutputStream(getTodaysFileName().concat(".txt"));
dos = new DataOutputStream(os);
dos.writeBytes(todaysFile);
}
catch(IOException e){System.out.println("Erro ao escrever no ficheiro de Log");}
finally
{
try{os.close();} //closes file
catch(Exception e){e.printStackTrace();}
}
}
public String parseServerFile(String fileContent)
{
char arrayChar[] = new char[fileContent.length()];
char arrayCharRegister[] = new char[fileContent.length()];
char arrayCharAux[] = new char[fileContent.length()];
int h = 0;
arrayChar = fileContent.toCharArray();
for(int i=0;i<arrayChar.length;i++)
//beginning of a register
if((arrayChar[i]==´c´ && arrayChar[i+1]==´=´) || (arrayChar[i]==´C´ && arrayChar[i+1]==´=´))
{
int j=i+1,a=1;
arrayCharRegister[0] = arrayChar[i];
//gets a single register
for(;arrayChar.length > j && !((arrayChar[j]==´c´ && arrayChar[j+1]==´=´) ||
(arrayChar[j]==´C´ && arrayChar[j+1]==´=´)); j++,a++)
arrayCharRegister[a] = arrayChar[j];
//checks if it´s an F2 register
for(int c = a-1; arrayCharRegister[c] != ´t´ && c >=0 ; c–)
//it is
if(arrayCharRegister[c]==´@´)
{
//keeps the F2 register
for(int b = 0; b < a; b++,i++,h++)
arrayCharAux[h] = arrayCharRegister[b];
}
arrayCharAux[h] = ´n´; h++;
arrayCharAux[h] = ´r´; h++;
}
return String.valueOf(arrayCharAux);
}
public static void main(String[] args)
{
FileUtils fileUtils = new FileUtils();
}
}
-----
public class Timer implements Runnable
{
FileUtils fileUtils;
int numberOfTimesToRun = 1;
int numberOfSecDay = 86400;
public Timer(FileUtils fileUtils){this.fileUtils = fileUtils;}
public void run()
{
while(true)
{
fileUtils.createTodaysFile(fileUtils.parseServerFile(fileUtils.getFileInStringFormat()));
try{Thread.sleep((int)(numberOfSecDay/numberOfTimesToRun));}
catch(InterruptedException ie){}
}
}
-----
Obrigado
Nuno Ricardo
[ Esta mensagem foi editada por: nrfd em 23-02-2003 12:31 ]
Já tentasse aumentar a memória da JVM ?
E a do windows ?
Experimenta usar BufferedReader e StringBuffer ao invés de usar só String.
O código String x += x; consume mais memódia do que o código StringBuffer sb;
sb.append(x);
[]s