com.credibledoc.combiner.SourceFilesReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of log-combiner Show documentation
Show all versions of log-combiner Show documentation
Simple command-line tool for merging log files with different format
of lines timestamps to a single file or readable source
with lines sorted by timestamps.
See the https://github.com/credibledoc/credible-doc/tree/master/log-combiner-parent/log-combiner page.
package com.credibledoc.combiner;
import com.credibledoc.combiner.context.CombinerContext;
import com.credibledoc.combiner.exception.CombinerRuntimeException;
import com.credibledoc.combiner.file.FileWithSources;
import com.credibledoc.combiner.log.buffered.LogBufferedReader;
import com.credibledoc.combiner.log.reader.ReaderService;
import com.credibledoc.combiner.node.file.NodeFileService;
import com.credibledoc.combiner.state.FilesMergerState;
import com.credibledoc.combiner.tactic.Tactic;
import com.credibledoc.combiner.tactic.TacticService;
import java.io.File;
import java.util.List;
/**
* Stateful instance with {@link CombinerContext} and methods for reading lines from parsed files.
*/
public class SourceFilesReader {
private List files;
private FilesMergerState filesMergerState;
private LogBufferedReader logBufferedReader;
private CombinerContext combinerContext;
public void addSourceFiles(List sourceFiles) {
this.files = sourceFiles;
}
public List read() {
if (filesMergerState == null) {
if (files.isEmpty()) {
throw new CombinerRuntimeException("The source files collection is empty.");
}
TacticService.getInstance().prepareReaders(files, combinerContext);
filesMergerState = new FilesMergerState();
filesMergerState.setNodeFiles(combinerContext.getNodeFileRepository().getNodeFiles());
}
String line = ReaderService.getInstance().readLineFromReaders(filesMergerState);
logBufferedReader = filesMergerState.getCurrentNodeFile().getLogBufferedReader();
if (line == null) {
return null;
}
if (logBufferedReader.isNotClosed()) {
return ReaderService.getInstance().readMultiline(line, logBufferedReader, combinerContext);
}
return null;
}
public File currentFile(CombinerContext combinerContext) {
return NodeFileService.getInstance().findNodeFile(logBufferedReader, combinerContext)
.getFileWithSources().getFile();
}
public Tactic currentTactic(CombinerContext combinerContext) {
return TacticService.getInstance().findTactic(logBufferedReader, combinerContext);
}
public void setCombinerContext(CombinerContext combinerContext) {
this.combinerContext = combinerContext;
}
}