001/* 002 * Copyright 2015-2016 UnboundID Corp. 003 * 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License (GPLv2 only) 006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 007 * as published by the Free Software Foundation. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, see <http://www.gnu.org/licenses>. 016 */ 017 018package com.unboundid.scim2.server; 019 020import com.unboundid.scim2.common.ScimResource; 021 022import javax.ws.rs.core.StreamingOutput; 023import java.io.IOException; 024import java.io.OutputStream; 025 026/** 027 * Interface for streaming list/query results using the ListResponse container. 028 */ 029public abstract class ListResponseStreamingOutput<T extends ScimResource> 030 implements StreamingOutput 031{ 032 /** 033 * Start streaming the contents of the list response. The list response will 034 * be considered complete upon return; 035 * 036 * @param os The list response output stream used to stream back elements of 037 * the list response. 038 * @throws IOException if an error occurs while writing. 039 */ 040 public abstract void write(ListResponseWriter<T> os) throws IOException; 041 042 043 /** 044 * {@inheritDoc} 045 */ 046 public final void write(final OutputStream os) throws IOException 047 { 048 ListResponseWriter<T> handler = 049 new ListResponseWriter<T>(os); 050 handler.startResponse(); 051 write(handler); 052 handler.endResponse(); 053 } 054}