1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package net.fortuna.ical4j.data;
35
36 import java.io.IOException;
37 import java.io.OutputStream;
38 import java.io.OutputStreamWriter;
39 import java.io.Writer;
40
41 import net.fortuna.ical4j.model.Calendar;
42 import net.fortuna.ical4j.model.ValidationException;
43
44 /***
45 * Writes an iCalendar model to an output stream.
46 *
47 * @author benf
48 */
49 public class CalendarOutputter {
50
51 private boolean validating;
52
53 /***
54 * Default constructor.
55 */
56 public CalendarOutputter() {
57 this(true);
58 }
59
60 /***
61 * @param validating indicates whether to validate
62 * calendar when outputting to stream
63 */
64 public CalendarOutputter(final boolean validating) {
65 this.validating = validating;
66 }
67
68 /***
69 * Outputs an iCalender string to the specified output stream.
70 *
71 * @param calendar
72 * calendar to write to ouput stream
73 * @param out
74 * an output stream
75 * @throws IOException
76 * thrown when unable to write to output stream
77 */
78 public final void output(final Calendar calendar, final OutputStream out)
79 throws IOException, ValidationException {
80
81 output(calendar, new OutputStreamWriter(out));
82 }
83
84 /***
85 * Outputs an iCalender string to the specified writer.
86 *
87 * @param calendar
88 * calendar to write to writer
89 * @param out
90 * a writer
91 * @throws IOException
92 * thrown when unable to write to writer
93 */
94 public final void output(final Calendar calendar, final Writer out)
95 throws IOException, ValidationException {
96
97 if (isValidating()) {
98 calendar.validate();
99 }
100
101 FoldingWriter writer = new FoldingWriter(out);
102
103 try {
104
105 writer.write(calendar.toString());
106 }
107 finally {
108
109 writer.close();
110 }
111 }
112
113 /***
114 * @return Returns the validating.
115 */
116 public boolean isValidating() {
117 return validating;
118 }
119
120 /***
121 * @param validating The validating to set.
122 */
123 public void setValidating(boolean validating) {
124 this.validating = validating;
125 }
126 }