• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / sitemesh2 / 59

22 Mar 2026 02:30AM UTC coverage: 40.347%. Remained the same
59

push

github

hazendaz
[mvn] Update maven wrapper

698 of 1891 branches covered (36.91%)

Branch coverage included in aggregate %.

1555 of 3693 relevant lines covered (42.11%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/opensymphony/module/sitemesh/filter/RoutablePrintWriter.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/* This software is published under the terms of the OpenSymphony Software
6
 * License version 1.1, of which a copy has been included with this
7
 * distribution in the LICENSE.txt file. */
8
package com.opensymphony.module.sitemesh.filter;
9

10
import com.opensymphony.module.sitemesh.SitemeshBuffer;
11
import com.opensymphony.module.sitemesh.SitemeshBufferFragment;
12
import com.opensymphony.module.sitemesh.SitemeshWriter;
13

14
import java.io.IOException;
15
import java.io.PrintWriter;
16
import java.io.Writer;
17

18
/**
19
 * Provides a PrintWriter that routes through to another PrintWriter, however the destination can be changed at any
20
 * point. The destination can be passed in using a factory, so it will not be created until it's actually needed.
21
 *
22
 * @author Joe Walnes
23
 */
24
public class RoutablePrintWriter extends PrintWriter implements SitemeshWriter {
25

26
    /** The destination. */
27
    private PrintWriter destination;
28

29
    /** The factory. */
30
    private DestinationFactory factory;
31

32
    /**
33
     * Factory to lazily instantiate the destination.
34
     */
35
    public interface DestinationFactory {
36

37
        /**
38
         * Activate destination.
39
         *
40
         * @return the prints the writer
41
         *
42
         * @throws IOException
43
         *             Signals that an I/O exception has occurred.
44
         */
45
        PrintWriter activateDestination() throws IOException;
46
    }
47

48
    /**
49
     * Instantiates a new routable print writer.
50
     *
51
     * @param factory
52
     *            the factory
53
     */
54
    public RoutablePrintWriter(DestinationFactory factory) {
55
        super(new NullWriter());
×
56
        this.factory = factory;
×
57
    }
×
58

59
    /**
60
     * Gets the destination.
61
     *
62
     * @return the destination
63
     */
64
    private PrintWriter getDestination() {
65
        if (destination == null) {
×
66
            try {
67
                destination = factory.activateDestination();
×
68
            } catch (IOException e) {
×
69
                setError();
×
70
            }
×
71
        }
72
        return destination;
×
73
    }
74

75
    /**
76
     * Update destination.
77
     *
78
     * @param factory
79
     *            the factory
80
     */
81
    public void updateDestination(DestinationFactory factory) {
82
        destination = null;
×
83
        this.factory = factory;
×
84
    }
×
85

86
    @Override
87
    public void close() {
88
        getDestination().close();
×
89
    }
×
90

91
    @Override
92
    public void println(Object x) {
93
        getDestination().println(x);
×
94
    }
×
95

96
    @Override
97
    public void println(String x) {
98
        getDestination().println(x);
×
99
    }
×
100

101
    @Override
102
    public void println(char x[]) {
103
        getDestination().println(x);
×
104
    }
×
105

106
    @Override
107
    public void println(double x) {
108
        getDestination().println(x);
×
109
    }
×
110

111
    @Override
112
    public void println(float x) {
113
        getDestination().println(x);
×
114
    }
×
115

116
    @Override
117
    public void println(long x) {
118
        getDestination().println(x);
×
119
    }
×
120

121
    @Override
122
    public void println(int x) {
123
        getDestination().println(x);
×
124
    }
×
125

126
    @Override
127
    public void println(char x) {
128
        getDestination().println(x);
×
129
    }
×
130

131
    @Override
132
    public void println(boolean x) {
133
        getDestination().println(x);
×
134
    }
×
135

136
    @Override
137
    public void println() {
138
        getDestination().println();
×
139
    }
×
140

141
    @Override
142
    public void print(Object obj) {
143
        getDestination().print(obj);
×
144
    }
×
145

146
    @Override
147
    public void print(String s) {
148
        getDestination().print(s);
×
149
    }
×
150

151
    @Override
152
    public void print(char s[]) {
153
        getDestination().print(s);
×
154
    }
×
155

156
    @Override
157
    public void print(double d) {
158
        getDestination().print(d);
×
159
    }
×
160

161
    @Override
162
    public void print(float f) {
163
        getDestination().print(f);
×
164
    }
×
165

166
    @Override
167
    public void print(long l) {
168
        getDestination().print(l);
×
169
    }
×
170

171
    @Override
172
    public void print(int i) {
173
        getDestination().print(i);
×
174
    }
×
175

176
    @Override
177
    public void print(char c) {
178
        getDestination().print(c);
×
179
    }
×
180

181
    @Override
182
    public void print(boolean b) {
183
        getDestination().print(b);
×
184
    }
×
185

186
    @Override
187
    public void write(String s) {
188
        getDestination().write(s);
×
189
    }
×
190

191
    @Override
192
    public void write(String s, int off, int len) {
193
        getDestination().write(s, off, len);
×
194
    }
×
195

196
    @Override
197
    public void write(char buf[]) {
198
        getDestination().write(buf);
×
199
    }
×
200

201
    @Override
202
    public void write(char buf[], int off, int len) {
203
        getDestination().write(buf, off, len);
×
204
    }
×
205

206
    @Override
207
    public void write(int c) {
208
        getDestination().write(c);
×
209
    }
×
210

211
    @Override
212
    public boolean checkError() {
213
        return getDestination().checkError();
×
214
    }
215

216
    @Override
217
    public void flush() {
218
        getDestination().flush();
×
219
    }
×
220

221
    /**
222
     * Just to keep super constructor for PrintWriter happy - it's never actually used.
223
     */
224
    private static class NullWriter extends Writer {
225

226
        /**
227
         * Instantiates a new null writer.
228
         */
229
        protected NullWriter() {
×
230
        }
×
231

232
        @Override
233
        public void write(char cbuf[], int off, int len) throws IOException {
234
            throw new UnsupportedOperationException();
×
235
        }
236

237
        @Override
238
        public void flush() throws IOException {
239
            throw new UnsupportedOperationException();
×
240
        }
241

242
        @Override
243
        public void close() throws IOException {
244
            throw new UnsupportedOperationException();
×
245
        }
246

247
    }
248

249
    @Override
250
    public boolean writeSitemeshBufferFragment(SitemeshBufferFragment bufferFragment) throws IOException {
251
        PrintWriter destination = getDestination();
×
252
        if (destination instanceof SitemeshWriter) {
×
253
            return ((SitemeshWriter) destination).writeSitemeshBufferFragment(bufferFragment);
×
254
        }
255
        bufferFragment.writeTo(destination);
×
256
        return true;
×
257
    }
258

259
    @Override
260
    public SitemeshBuffer getSitemeshBuffer() {
261
        PrintWriter destination = getDestination();
×
262
        if (destination instanceof SitemeshWriter) {
×
263
            return ((SitemeshWriter) destination).getSitemeshBuffer();
×
264
        }
265
        throw new IllegalStateException("Print writer is not a sitemesh buffer");
×
266
    }
267
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc