MockServletOutputStream.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.protocol.modipa.utils;

  21. import java.io.ByteArrayOutputStream;
  22. import java.io.IOException;

  23. import javax.servlet.ServletOutputStream;
  24. import javax.servlet.WriteListener;

  25. /**
  26.  * MockServletOutputStream semplice stream usato per poter leggere
  27.  * il contenuto da una risposta servlet http
  28.  *
  29.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class MockServletOutputStream extends ServletOutputStream {

  34.    
  35.     private ByteArrayOutputStream os = new ByteArrayOutputStream();
  36.    
  37.     @Override
  38.     public boolean isReady() {
  39.         return true;
  40.     }

  41.     @Override
  42.     public void setWriteListener(WriteListener arg0) {
  43.        
  44.         try {
  45.             arg0.onWritePossible();
  46.         } catch (IOException e) {
  47.             // ignore
  48.         }
  49.     }

  50.     @Override
  51.     public void write(int b) throws IOException {
  52.         this.os.write(b);
  53.     }
  54.    
  55.     public ByteArrayOutputStream getByteArrayOutputStream() {
  56.         return this.os;
  57.     }

  58. }