001/* 002 * Copyright 2015-2024 Ping Identity Corporation 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 com.unboundid.scim2.common.annotations.NotNull; 023import jakarta.ws.rs.core.StreamingOutput; 024import java.io.IOException; 025import java.io.OutputStream; 026 027/** 028 * Interface for streaming list/query results using the ListResponse container. 029 */ 030public abstract class ListResponseStreamingOutput<T extends ScimResource> 031 implements StreamingOutput 032{ 033 /** 034 * Start streaming the contents of the list response. The list response will 035 * be considered complete upon return; 036 * 037 * @param os The list response output stream used to stream back elements of 038 * the list response. 039 * @throws IOException if an error occurs while writing. 040 */ 041 public abstract void write(@NotNull ListResponseWriter<T> os) 042 throws IOException; 043 044 045 /** 046 * {@inheritDoc} 047 */ 048 public final void write(@NotNull final OutputStream os) 049 throws IOException 050 { 051 ListResponseWriter<T> handler = new ListResponseWriter<>(os); 052 handler.startResponse(); 053 write(handler); 054 handler.endResponse(); 055 } 056}