- Scanner scan = new Scanner(data);
- scan.useDelimiter("\n");
- while (scan.hasNext()) {
- String line = scan.next();
-
- if (line.startsWith("ZIP:")) {
- line = StringUtils.unzip64(line.substring("ZIP:".length()));
- read(line);
+ if (in == null) {
+ throw new NullPointerException("InputStream is null");
+ }
+
+ boolean first = true;
+ while (stream.next()) {
+ if (stream.eof()) {
+ if (first) {
+ throw new NullPointerException(
+ "InputStream empty, normal termination");
+ }
+ return this;
+ }
+ first = false;
+
+ boolean zip = stream.startsWiths("ZIP:");
+ boolean b64 = stream.startsWiths("B64:");
+
+ if (zip || b64) {
+ stream.skip("XXX:".length());
+
+ InputStream decoded = stream.open();
+ if (zip) {
+ decoded = new GZIPInputStream(decoded);
+ }
+ decoded = new Base64InputStream(decoded, false);
+
+ try {
+ read(decoded);
+ } finally {
+ decoded.close();
+ }