import jalview.ws.params.WsParamSetI;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashSet;
{
List<RemoteFile> files = client.getJobResults(job.getJobId());
Optional<RemoteFile> logFile = files.stream()
- .filter(f -> f.getLabel().equals("log")).findFirst();
+ .filter(f -> f.getLabel().equals("log")).findFirst();
boolean newContent = false;
if (logFile.isPresent())
{
- InputStream stream = logFile.get().getContent();
- long nextChunk = stream.skip(job.getNextChunk());
- int len = appendJobStatus(job, stream);
- job.setnextChunk(nextChunk + len);
- newContent |= len > 0;
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ logFile.get().writeTo(output);
+ if (output.size() > job.getNextChunk())
+ {
+ newContent = true;
+ job.setStatus(output.toString("UTF-8"));
+ job.setnextChunk(output.size());
+ }
}
if (failedStates.contains(job.getJobState()))
{
Optional<RemoteFile> errLogFile = files.stream()
- .filter(f -> f.getLabel().equals("error-log")).findFirst();
+ .filter(f -> f.getLabel().equals("error-log")).findFirst();
if (errLogFile.isPresent())
{
- newContent |= appendJobStatus(job, errLogFile.get().getContent()) > 0;
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ errLogFile.get().writeTo(output);
+ if (output.size() > 0)
+ {
+ newContent = true;
+ job.setStatus(job.getStatus() + "\n" + output.toString("UTF-8"));
+ }
}
}
return newContent;
}
- private int appendJobStatus(WsJob job, InputStream stream) throws IOException
- {
- StringBuilder builder = new StringBuilder(job.getStatus());
- InputStreamReader reader = new InputStreamReader(stream);
- char[] buffer = new char[4096];
- int chunkLen = 0;
- int len = 0;
- while ((len = reader.read(buffer)) != -1)
- {
- chunkLen += len;
- builder.append(buffer, 0, len);
- }
- job.setStatus(builder.toString());
- return chunkLen;
- }
-
@Override
public final boolean handleSubmitError(Throwable _lex, WsJob j, WebserviceInfo wsInfo)
{