MCPcopy Index your code
hub / github.com/apache/tomcat / convert

Method convert

java/org/apache/tomcat/buildutil/Txt2Html.java:130–167  ·  view source on GitHub ↗

Perform the actual copy and conversion @param from The input file @param to The output file @throws IOException Thrown if an error occurs during the conversion

(File from, File to)

Source from the content-addressed store, hash-verified

128 * @throws IOException Thrown if an error occurs during the conversion
129 */
130 private void convert(File from, File to) throws IOException {
131 // Open files:
132 try (BufferedReader in =
133 new BufferedReader(new InputStreamReader(new FileInputStream(from), SOURCE_ENCODING))) {
134 try (PrintWriter out =
135 new PrintWriter(new OutputStreamWriter(new FileOutputStream(to), StandardCharsets.UTF_8))) {
136
137 // Output header:
138 out.print("<!DOCTYPE html><html><head><meta charset=\"UTF-8\" />" +
139 "<title>Source Code</title></head><body><pre>");
140
141 // Convert, line-by-line:
142 String line;
143 while ((line = in.readLine()) != null) {
144 StringBuilder result = new StringBuilder();
145 int len = line.length();
146 for (int i = 0; i < len; i++) {
147 char c = line.charAt(i);
148 switch (c) {
149 case '&':
150 result.append("&amp;");
151 break;
152 case '<':
153 result.append("&lt;");
154 break;
155 default:
156 result.append(c);
157 }
158 }
159 out.print(result.toString() + LINE_SEPARATOR);
160 }
161
162 // Output footer:
163 out.print("</pre></body></html>");
164
165 }
166 }
167 }
168
169}
170

Callers 1

executeMethod · 0.95

Calls 6

lengthMethod · 0.80
charAtMethod · 0.80
toStringMethod · 0.65
printMethod · 0.45
readLineMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected