Documento.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. /**
  21.  * Package accordo di servizio parte comune
  22.  *
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @version 1.4, 02/08/06
  26.  */

  27. package it.gov.spcoop.sica.dao;

  28. import java.io.ByteArrayOutputStream;
  29. import java.io.IOException;
  30. import java.io.InputStream;
  31. import java.io.Serializable;

  32. /**
  33.  * Documento inserito in un accordo
  34.  *
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class Documento implements Serializable {

  41.     /**
  42.      *
  43.      */
  44.     private static final long serialVersionUID = 2982135475324753831L;
  45.    
  46.     public Documento(){}
  47.     public Documento(String nome,String tipo,byte[] contenuto){
  48.         this.nome = nome;
  49.         this.tipo = tipo;
  50.         this.contenuto = contenuto;
  51.     }
  52.    
  53.     public Documento(String nome,String tipo,InputStream contenuto) throws IOException{
  54.         this.nome = nome;
  55.         this.tipo = tipo;
  56.        
  57.         ByteArrayOutputStream bout = new ByteArrayOutputStream();
  58.         byte[]buffer = new byte[1024];
  59.         int byteLetti = -1;
  60.         while( (byteLetti = contenuto.read(buffer))!=-1){
  61.             bout.write(buffer,0,byteLetti);
  62.         }
  63.         bout.flush();
  64.         bout.close();
  65.         this.contenuto = bout.toByteArray();
  66.     }
  67.    
  68.     private String nome;
  69.     private byte[] contenuto;
  70.     /** doc, xsd, ....*/
  71.     private String tipo;
  72.    
  73.     public String getNome() {
  74.         return this.nome;
  75.     }
  76.     public void setNome(String nome) {
  77.         this.nome = nome;
  78.     }
  79.     public byte[] getContenuto() {
  80.         return this.contenuto;
  81.     }
  82.     public void setContenuto(byte[] contenuto) {
  83.         this.contenuto = contenuto;
  84.     }
  85.     public String getTipo() {
  86.         return this.tipo;
  87.     }
  88.     public void setTipo(String tipo) {
  89.         this.tipo = tipo;
  90.     }
  91.    
  92. }