Bom é o seguinte tenho uma classe java que varre um diretório e abre todos os arquivos .log que encontrar e mostra a data de execução desse .log o horário inicial da execução e o horario final da execução e apresenta na tela no unix pra mim.
Agora tenho que fazer o seguinte pegar essa informação que é impressa na tela e criar um objeto e perssisti-la em um banco de dados, não estou conseguindo fazer isso, será que alguém pode me ajudar.
Segue a classe java
Classe Leitor
public class Leitor {
private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd kk.mm.ss");
private Logger logger = Logger.getLogger("Leitor");
public void init() {
Set<File> diretorios = carreagaDiretorios(Messages
.getString("leitor.diretorio")
+ Logger.getLogger("Carregando Diretorios"));
Set<String> extensoes = carregaExtensoesArquivos(Messages
.getString("leitor.extensao")
+ Logger.getLogger("Carregando Arquivos"));
for (File diretorio : diretorios) {
processaDiretorio(diretorio);
}
}
// imprimo o nome do diretório atual
private Set<File> carreagaDiretorios(String caminho) {
HashSet<File> retorno = new HashSet<File>();
String caminhos[] = caminho.split(";");
for (int i = 0; i < caminhos.length; i++) {
File file = new File(caminhos[i]);
if (file.exists()) {
retorno.add(file);
} else {
System.err.println("Diretorio " + file.getName()
+ " não existe.");
}
}
return retorno;
}
private void processaDiretorio(File diretorio) {
// criar um Array para os arquivos que estão dentro do diretório
File[] arquivosInternos = diretorio.listFiles();
// Se encontrar algum arquivo dentro do diretótio ele percorre
// tudo o que foi encontrado com o loop(for).
if (arquivosInternos != null) {
for (int i = 0; i < arquivosInternos.length; i++) {
if (arquivosInternos[i].exists()
&& arquivosInternos[i].isDirectory()) {
processaDiretorio(new File(arquivosInternos[i].getPath()));
} else if (arquivosInternos[i].exists()
&& arquivosInternos[i].isFile()) {
verificarArquivoLog(arquivosInternos[i]);
}
}
}
}
private Set<String> carregaExtensoesArquivos(String arquivo) {
HashSet<String> retorno = new HashSet<String>();
String arquivos[] = arquivo.split(";");
for (int i = 0; i < arquivos.length; i++) {
retorno.add(arquivos[i]);
}
return retorno;
}
private boolean verificarExtensaoArquivo(File f) {
String nomeArquivo = f.getPath();
String extensaoArquivo = nomeArquivo.substring(nomeArquivo
.lastIndexOf('.'), nomeArquivo.length());
return ".log".equalsIgnoreCase(extensaoArquivo);
}
private void verificarArquivoLog(File extensoes) {
if (verificarExtensaoArquivo(extensoes)) {
try {
LogEntry log = abrir(extensoes);
System.out.println(log);
} catch (FileNotFoundException e) {
Logger.getLogger("Arquivo não Existe");
} catch (IOException e) {
Logger.getLogger("e");
}
}
}
private LogEntry abrir(File file) throws IOException, FileNotFoundException {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String s;
boolean inicioRegistro = true;
LogEntry entrada = new LogEntry();
while ((s = br.readLine()) != null) {
if (s.indexOf("INICIO DO SCRIPT:") == 0) {
try {
// Setando ConfigFile
entrada.setConfigFile(s.substring((s.lastIndexOf('/') + 1),
(s.lastIndexOf("GPA") + 3)));
} catch (StringIndexOutOfBoundsException e) {
Logger.getLogger("Erro ao obter ConfigFile");
}
}
if ((s.indexOf("DATA EXECUÇÃO:") == 0) && (inicioRegistro)) {
String dataInicio = s.substring(15, 23);
String horaInicio = s.substring(73, 81);
try {
// Setando DataInicio
entrada.setDataInicio(format.parse(dataInicio + " "
+ horaInicio));
} catch (ParseException e) {
Logger.getLogger("Erro ao executar parse DataInicio");
}
}
if (s.indexOf("TERMINOU COM") == 0) {
// Setando codigoRerno
try {
entrada.setCodigoRetorno(s.substring((s.indexOf('=') + 1),
s.indexOf('.')));
inicioRegistro = false;
} catch (StringIndexOutOfBoundsException e) {
Logger.getLogger("Erro ao obter Codigo de retorno");
}
}
if ((s.indexOf("DATA EXECUÇÃO:") == 0) && (!inicioRegistro)) {
String dataFinal;
String horaFinal;
try {
dataFinal = s.substring(15, 23);
horaFinal = s.substring(73, 81);
entrada.setDataFim(format
.parse(dataFinal + " " + horaFinal));
} catch (Exception e) {
Logger.getLogger("Erro ao obter Data Fim.");
}
// System.out.println(entrada.toString());
inicioRegistro = true;
}
}
fr.close();
return entrada;
}
}
essa classe executada gera a seguinte informação na tela:
[ Gpa_ExecLoMaByMas.4103.MFPGPA, Tue Apr 27 17:26:14 BRT 2010, Tue Apr 27 17:26:16 BRT 2010, 0]
[ Gpa_ExecLoMaByMas.4105.MFPGPA, Tue Apr 27 17:26:20 BRT 2010, Tue Apr 27 17:26:22 BRT 2010, 0]
[ Gpa_ExecLoMaByMas.4108.MFPGPA, Tue Apr 27 18:25:10 BRT 2010, Tue Apr 27 19:02:28 BRT 2010, 0]
[ Gpa_ExecLoMaByMas.4109.MFPGPA, Tue Apr 27 17:26:25 BRT 2010, Tue Apr 27 18:25:05 BRT 2010, 0]
[ Gpa_ExecLoMaByMas.4114.MFPGPA, Tue Apr 27 19:02:34 BRT 2010, Tue Apr 27 19:30:52 BRT 2010, 0]
[ Gpa_ExecLoMaByMas.4115.MFPGPA, Tue Apr 27 19:30:53 BRT 2010, Tue Apr 27 19:42:56 BRT 2010, 0]
Desde já agradeço a quem puder me ajudar…!!!