KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > util > ByteArrayDataSource


1 /*
2  * Copyright (C) 2003 Erik Swenson - eswenson@opensourcesoft.net
3  *
4  * This program is free software; you can redistribute it and/or modify it under the terms of the
5  * GNU General Public License as published by the Free Software Foundation; either version 2 of the
6  * License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
10  * the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along with this program; if
13  * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
14  * 02111-1307, USA.
15  *
16  */

17
18 package org.efs.openreports.util;
19
20 import java.io.*;
21
22 import javax.activation.DataSource JavaDoc;
23
24 public class ByteArrayDataSource implements DataSource JavaDoc
25 {
26     private byte[] data;
27     private String JavaDoc type;
28     private String JavaDoc name;
29
30     public ByteArrayDataSource(byte[] data, String JavaDoc type)
31     {
32         this.type = type;
33         this.data = data;
34     }
35
36     public InputStream getInputStream() throws IOException
37     {
38         if (data == null)
39             throw new IOException("No data.");
40
41         return new ByteArrayInputStream(data);
42     }
43
44     public OutputStream getOutputStream() throws IOException
45     {
46         throw new IOException("Not supported.");
47     }
48
49     public String JavaDoc getContentType()
50     {
51         return type;
52     }
53
54     public void setContentType(String JavaDoc type)
55     {
56         this.type = type;
57     }
58
59     public String JavaDoc getName()
60     {
61         return name;
62     }
63
64     public void setName(String JavaDoc name)
65     {
66         this.name = name;
67     }
68
69 }
70
Popular Tags