Skip to content

Commit

Permalink
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -4,15 +4,18 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;

public class MesosFileChunkObject {
private final String data;
private final long offset;
private final Optional<Long> nextOffset;

@JsonCreator
public MesosFileChunkObject(@JsonProperty("data") String data, @JsonProperty("offset") long offset) {
public MesosFileChunkObject(@JsonProperty("data") String data, @JsonProperty("offset") long offset, @JsonProperty("nextOffset") Optional<Long> nextOffset) {
this.data = data;
this.offset = offset;
this.nextOffset = nextOffset;
}

public String getData() {
@@ -23,11 +26,16 @@ public long getOffset() {
return offset;
}

public Optional<Long> getNextOffset() {
return nextOffset;
}

@Override
public String toString() {
return "MesosFileChunkObject[" +
"data='" + data + '\'' +
", offset=" + offset +
", nextOffset=" + nextOffset +
']';
}

@@ -41,11 +49,12 @@ public boolean equals(Object o) {
}
MesosFileChunkObject that = (MesosFileChunkObject) o;
return Objects.equals(offset, that.offset) &&
Objects.equals(data, that.data);
Objects.equals(data, that.data) &&
Objects.equals(nextOffset, that.nextOffset);
}

@Override
public int hashCode() {
return Objects.hash(data, offset);
return Objects.hash(data, offset, nextOffset);
}
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
@@ -139,7 +140,7 @@ public MesosFileChunkObject read(@ApiParam("The task ID of the sandbox to read f

checkNotFound(maybeChunk.isPresent(), "File %s does not exist for task ID %s", fullPath, taskId);

if (grep.isPresent()) {
if (grep.isPresent() && !Strings.isNullOrEmpty(grep.get())) {
final Pattern grepPattern = Pattern.compile(grep.get());
final StringBuilder strBuilder = new StringBuilder(maybeChunk.get().getData().length());

@@ -150,7 +151,7 @@ public MesosFileChunkObject read(@ApiParam("The task ID of the sandbox to read f
}
}

return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset());
return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset(), Optional.of(maybeChunk.get().getOffset() + maybeChunk.get().getData().length()));
}

return maybeChunk.get();

0 comments on commit 1d8f2e0

Please sign in to comment.