• 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/util/OutputConverter.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
package com.opensymphony.module.sitemesh.util;
6

7
import java.io.ByteArrayInputStream;
8
import java.io.IOException;
9
import java.io.InputStreamReader;
10
import java.io.StringWriter;
11
import java.io.Writer;
12
import java.nio.charset.StandardCharsets;
13

14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

17
/**
18
 * A converter from one character type to another
19
 * <p>
20
 * This class is not threadsafe.
21
 */
22
public class OutputConverter {
×
23

24
    /** The Logger. */
25
    private static final Logger logger = LoggerFactory.getLogger(OutputConverter.class);
×
26

27
    /**
28
     * Resin versions 2.1.12 and previously have encoding problems for internationalization.
29
     * <p>
30
     * This is fixed in Resin 2.1.13. Once 2.1.13 is used more widely, this parameter (and class) can be removed.
31
     */
32
    public static final String WORK_AROUND_RESIN_I18N_BUG = "sitemesh.resin.i18n.workaround";
33

34
    /**
35
     * Gets the writer.
36
     *
37
     * @param out
38
     *            the out
39
     *
40
     * @return the writer
41
     */
42
    public static Writer getWriter(Writer out) {
43
        if (Boolean.getBoolean(WORK_AROUND_RESIN_I18N_BUG)) {
×
44
            return new ResinWriter(out);
×
45
        }
46
        return out;
×
47
    }
48

49
    /**
50
     * Convert.
51
     *
52
     * @param inputString
53
     *            the input string
54
     *
55
     * @return the string
56
     */
57
    public static String convert(String inputString) {
58
        if (Boolean.getBoolean(WORK_AROUND_RESIN_I18N_BUG)) {
×
59
            StringWriter sr = new StringWriter();
×
60
            resinConvert(inputString, sr);
×
61
            return sr.getBuffer().toString();
×
62
        }
63
        return inputString;
×
64
    }
65

66
    /**
67
     * To get internationalized characters to work on Resin, some conversions need to take place.
68
     */
69
    static class ResinWriter extends Writer {
70

71
        /** The target. */
72
        private final Writer target;
73

74
        /** The buffer. */
75
        private final CharArrayWriter buffer = new CharArrayWriter();
×
76

77
        /**
78
         * Instantiates a new resin writer.
79
         *
80
         * @param target
81
         *            the target
82
         */
83
        public ResinWriter(Writer target) {
×
84
            this.target = target;
×
85
        }
×
86

87
        @Override
88
        public void close() throws IOException {
89
            flush();
×
90
        }
×
91

92
        @Override
93
        public void flush() throws IOException {
94
            resinConvert(buffer.toString(), target);
×
95
            buffer.reset();
×
96
        }
×
97

98
        @Override
99
        public void write(char[] cbuf, int off, int len) throws IOException {
100
            buffer.write(cbuf, off, len);
×
101
            flush();
×
102
        }
×
103
    }
104

105
    /**
106
     * Resin convert.
107
     *
108
     * @param inputString
109
     *            the input string
110
     * @param writer
111
     *            the writer
112
     */
113
    private static void resinConvert(String inputString, Writer writer) {
114
        // does this need to be made configurable? Or are these two always correct?
115
        try (InputStreamReader reader = new InputStreamReader(
×
116
                new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8)), StandardCharsets.ISO_8859_1)) {
×
117
            int i;
118
            while ((i = reader.read()) != -1) {
×
119
                writer.write(i);
×
120
            }
121
        } catch (IOException e) {
×
122
            logger.error("Unable to perform resinConvert", e);
×
123
        }
×
124
    }
×
125

126
}
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