List of usage examples for java.io SequenceInputStream SequenceInputStream
public SequenceInputStream(Enumeration<? extends InputStream> e)
SequenceInputStream
by remembering the argument, which must be an Enumeration
that produces objects whose run-time type is InputStream
. From source file:org.ow2.proactive_grid_cloud_portal.scheduler.SchedulerStateRest.java
@Override @GET/* w w w .j a v a 2 s . co m*/ @GZIP @Path("jobs/{jobid}/log/full") @Produces("application/json") public InputStream jobFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException { if (sessionId == null) { sessionId = session; } try { Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/log/full"); JobState jobState = scheduler.getJobState(jobId); List<TaskState> tasks = jobState.getTasks(); List<InputStream> streams = new ArrayList<>(tasks.size()); Collections.sort(tasks, TaskState.COMPARE_BY_FINISHED_TIME_ASC); for (TaskState taskState : tasks) { InputStream inputStream = null; try { if (taskState.isPreciousLogs()) { inputStream = retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskState.getId()); } else { String taskLogs = retrieveTaskLogsUsingDatabase(sessionId, jobId, taskState.getName()); if (!taskLogs.isEmpty()) { inputStream = IOUtils.toInputStream(taskLogs); } logger.warn("Retrieving truncated logs for task '" + taskState.getId() + "'"); } } catch (Exception e) { logger.info("Could not retrieve logs for task " + taskState.getId() + " (could be a non finished or killed task)", e); } if (inputStream != null) { streams.add(inputStream); } } if (streams.isEmpty()) { return null; // will produce HTTP 204 code } else { return new SequenceInputStream(Collections.enumeration(streams)); } } catch (PermissionException e) { throw new PermissionRestException(e); } catch (UnknownJobException e) { throw new UnknownJobRestException(e); } catch (NotConnectedException e) { throw new NotConnectedRestException(e); } }