+ * Returns a Reader for the given input after wrapping it in a buffered input
+ * stream, and then checking if it needs to be wrapped by a GZipInputStream
+ *
+ * @param input
+ * @return
+ */
+ private BufferedReader checkForGzipStream(InputStream input) throws Exception {
+
+ // NB: stackoverflow https://stackoverflow.com/questions/4818468/how-to-check-if-inputstream-is-gzipped
+ // could use a PushBackInputStream rather than a BufferedInputStream
+
+ BufferedInputStream bufinput;
+ if (!input.markSupported()) {
+ bufinput= new BufferedInputStream(input,16);
+ input = bufinput;
+ }
+ input.mark(4);
+ byte[] bytes=input.readNBytes(2);
+ input.reset();
+ if (bytes.length==2 && isGzipStream(bytes)) {
+ return getGzipReader(input);
+ }
+ // return a buffered reader for the stream.
+ InputStreamReader isReader= new InputStreamReader(input);
+ BufferedReader toReadFrom=new BufferedReader(isReader);
+ return toReadFrom;
+ }
+ /**