Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: Add an offset to sorting job #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public BigDecimal getTs() {
private final String fTsKey;
private final String fPath;
private final ITmfTrace fTrace;
private final long fOffset;


/**
* Constructor
Expand All @@ -112,17 +114,39 @@ public BigDecimal getTs() {
* @param path
* Trace path
* @param tsKey
* Timestamp key, represent the json object key. The value associated
* to this key is the timestamp that will be use to sort
* Timestamp key, represent the json object key. The value
* associated to this key is the timestamp that will be use to
* sort
* @param bracketsToSkip
* Number of bracket to skip
*/
public SortingJob(ITmfTrace trace, String path, String tsKey, int bracketsToSkip) {
this(trace, path, tsKey, bracketsToSkip, 0);
}

/**
* Constructor
*
* @param trace
* Trace to sort
* @param path
* Trace path
* @param tsKey
* Timestamp key, represent the json object key. The value
* associated to this key is the timestamp that will be use to
* sort
* @param bracketsToSkip
* Number of bracket to skip
* @param offset
* offset in bytes to skip in the file.
*/
public SortingJob(ITmfTrace trace, String path, String tsKey, int bracketsToSkip, long offset) {
super(Messages.SortingJob_description);
fTrace = trace;
fPath = path;
fTsKey = tsKey;
fBracketsToSkip = bracketsToSkip;
fOffset = offset;
}

/**
Expand All @@ -148,6 +172,11 @@ protected IStatus run(IProgressMonitor monitor) {
tempDir.mkdirs();
List<File> tracelings = new ArrayList<>();
try (BufferedInputStream parser = new BufferedInputStream(new FileInputStream(fPath))) {
long offset = parser.skip(fOffset);
if (offset != fOffset) {
// already at EOF
return new Status(IStatus.ERROR, getClass(), "Offset " + fOffset + " is greater than the file size.");
}
int data = 0;
for (int nbBracket = 0; nbBracket < fBracketsToSkip; nbBracket++) {
data = parser.read();
Expand Down
Loading