MailBinaryAttach.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.utils.mail;

  21. import java.io.ByteArrayInputStream;
  22. import java.io.InputStream;

  23. import org.openspcoop2.utils.UtilsException;

  24. /**
  25.  * MailAttach
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class MailBinaryAttach extends MailAttach {

  32.     private byte[] content;
  33.     private InputStream inputStream;
  34.    
  35.     public MailBinaryAttach(String name, byte[] content, String contentType){
  36.         super(name, contentType);
  37.         this.content = content;
  38.     }
  39.     public MailBinaryAttach(String name, InputStream inputStream, String contentType){
  40.         super(name, contentType);
  41.         this.inputStream = inputStream;
  42.     }
  43.     public MailBinaryAttach(String name, byte[] content){
  44.         this(name, content, null);
  45.     }
  46.     public MailBinaryAttach(String name, InputStream inputStream){
  47.         this(name, inputStream, null);
  48.     }
  49.    
  50.     public byte[] getContent() throws UtilsException {
  51.         if(this.content==null){
  52.             return org.openspcoop2.utils.Utilities.getAsByteArray(this.inputStream);
  53.         }
  54.         return this.content;
  55.     }
  56.     public void setContent(byte[] content) {
  57.         this.content = content;
  58.     }
  59.     public InputStream getInputStream() {
  60.         if(this.inputStream!=null){
  61.             return this.inputStream;
  62.         }
  63.         else{
  64.             return new ByteArrayInputStream(this.content);
  65.         }
  66.     }
  67.     public void setInputStream(InputStream is) {
  68.         this.inputStream = is;
  69.     }
  70. }