25
25
26
26
package org .opensolaris .opengrok .web ;
27
27
28
+ import java .io .BufferedInputStream ;
28
29
import java .io .File ;
29
30
import java .io .FileInputStream ;
30
- import java .io .FileReader ;
31
31
import java .io .IOException ;
32
+ import java .io .InputStream ;
32
33
import java .io .InputStreamReader ;
33
34
import java .io .Reader ;
34
35
import java .io .UnsupportedEncodingException ;
@@ -1169,10 +1170,10 @@ public static boolean dump(Writer out, File file, boolean compressed) {
1169
1170
* For backward compatibility, read the OpenGrok-produced document
1170
1171
* using the system default charset.
1171
1172
*/
1172
- try (Reader in = compressed
1173
- ? new InputStreamReader ( new GZIPInputStream (
1174
- new FileInputStream ( file )))
1175
- : new FileReader ( file )) {
1173
+ try (InputStream iss = new BufferedInputStream (
1174
+ new FileInputStream ( file ))) {
1175
+ Reader in = compressed ? new InputStreamReader ( new GZIPInputStream (
1176
+ iss )) : new InputStreamReader ( iss );
1176
1177
dump (out , in );
1177
1178
return true ;
1178
1179
} catch (IOException e ) {
@@ -1182,6 +1183,61 @@ public static boolean dump(Writer out, File file, boolean compressed) {
1182
1183
return false ;
1183
1184
}
1184
1185
1186
+ /**
1187
+ * Silently dump an xref file to the given destination. All
1188
+ * {@link IOException}s get caught and logged, but not re-thrown.
1189
+ * @param out dump destination
1190
+ * @param file file to dump
1191
+ * @param compressed if {@code true} the denoted file is assumed to be
1192
+ * gzipped
1193
+ * @param contextPath an optional override of "/source/" as the context path
1194
+ * @return {@code true} on success (everything read and written)
1195
+ * @throws NullPointerException if a parameter is {@code null}.
1196
+ */
1197
+ public static boolean dumpXref (Writer out , File file , boolean compressed ,
1198
+ String contextPath ) {
1199
+ if (!file .exists ()) {
1200
+ return false ;
1201
+ }
1202
+ /**
1203
+ * For backward compatibility, read the OpenGrok-produced document
1204
+ * using the system default charset.
1205
+ */
1206
+ try (InputStream iss = new BufferedInputStream (
1207
+ new FileInputStream (file ))) {
1208
+ Reader in = compressed ? new InputStreamReader (new GZIPInputStream (
1209
+ iss )) : new InputStreamReader (iss );
1210
+ dumpXref (out , in , contextPath );
1211
+ return true ;
1212
+ } catch (IOException e ) {
1213
+ LOGGER .log (Level .WARNING , "An error occured while piping file " +
1214
+ file , e );
1215
+ }
1216
+ return false ;
1217
+ }
1218
+
1219
+ /**
1220
+ * Silently dump an xref file to the given destination. All
1221
+ * {@link IOException}s get caught and logged, but not re-thrown.
1222
+ * @param out dump destination
1223
+ * @param in source to read
1224
+ * @param contextPath an optional override of "/source/" as the context path
1225
+ * @throws IOException as defined by the given reader/writer
1226
+ * @throws NullPointerException if a parameter is {@code null}.
1227
+ */
1228
+ public static void dumpXref (Writer out , Reader in , String contextPath )
1229
+ throws IOException {
1230
+ if (in == null || out == null ) {
1231
+ return ;
1232
+ }
1233
+ XrefSourceTransformer xform = new XrefSourceTransformer (in );
1234
+ xform .setWriter (out );
1235
+ xform .setContextPath (contextPath );
1236
+ while (xform .yylex ()) {
1237
+ // Nothing else to do.
1238
+ }
1239
+ }
1240
+
1185
1241
/**
1186
1242
* Print list of messages into output
1187
1243
*
0 commit comments