class AsynchronousProcessListWriter implements MessageBodyWriter<Iterable<AsynchronousProcess>> {

    @Override
    public void writeTo(Iterable<AsynchronousProcess> asynchronousProcesses,
                        Class<?> type, Type genericType,
                        Annotation[] annotations,
                        MediaType mediaType,
                        MultivaluedMap<String, Object> httpHeaders,
                        OutputStream entityStream) throws IOException, WebApplicationException {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(entityStream));
        try {
            writer.format(OUTPUT_FORMAT, "USER", "ID", "STAT", "PATH");
            for (AsynchronousProcess process : asynchronousProcesses) {
                writer.format(OUTPUT_FORMAT, process.getOwner() == null ? "unknown" : process.getOwner(), process.getId(), process.getStatus(), process.getPath());
            }
        } finally {
            writer.flush();
        }
    }

}