KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > bytes > OutputStream


1 /*
2   Copyright 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.bytes;
28
29 import java.io.EOFException JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 /**
33   Output stream default implementation.
34 */

35 public final class OutputStream
36   implements IOutputStream
37 {
38   // <class>
39
// <dynamic>
40
// <fields>
41
private java.io.OutputStream JavaDoc stream;
42   // </fields>
43

44   // <constructors>
45
public OutputStream(
46     java.io.OutputStream JavaDoc stream
47     )
48   {this.stream = stream;}
49   // </constructors>
50

51   // <interface>
52
// <public>
53
// <IOutputStream>
54
public int write(
55     byte[] data
56     )
57   {
58     try
59     {stream.write(data);}
60     catch(IOException JavaDoc e)
61     {throw new RuntimeException JavaDoc(e);}
62
63     return data.length;
64   }
65
66   public int write(
67     byte[] data,
68     int offset,
69     int length
70     )
71   {
72     try
73     {stream.write(data,offset,length);}
74     catch(IOException JavaDoc e)
75     {throw new RuntimeException JavaDoc(e);}
76
77     return length;
78   }
79
80   public int write(
81     String JavaDoc data
82     )
83   {
84     try
85     {stream.write(data.getBytes("ISO-8859-1"));}
86     catch(IOException JavaDoc e)
87     {throw new RuntimeException JavaDoc(e);}
88
89     return data.length();
90   }
91
92   public int write(
93     IInputStream data
94     )
95   {
96     try
97     {
98       // TODO:IMPL bufferize in order to limit memory usage!!!
99
byte[] baseData = new byte[(int)data.getLength()];
100       // Force the source pointer to the BOF (as we must copy the entire content)!
101
data.seek(0);
102       // Read source content!
103
data.read(baseData);
104       // Write target content!
105
return write(baseData);
106     }
107     catch(EOFException JavaDoc e)
108     {throw new RuntimeException JavaDoc(e);}
109   }
110   // </IOutputStream>
111
// </public>
112
// </interface>
113
// </dynamic>
114
// </class>
115
}
Popular Tags