- Scanner scan = new Scanner(data);
- try {
- scan.useDelimiter("\n");
- while (scan.hasNext()) {
- String line = scan.next();
-
- if (line.startsWith("ZIP:")) {
- try {
- line = StringUtils.unzip64(line.substring("ZIP:"
- .length()));
- } catch (IOException e) {
- throw new IOException(
- "Internal error when decoding ZIP content: input may be corrupt");
- }
- read(line);
- } else {
- processLine(line);
+ // TODO: fix NexInStream: next() MUST be called first time, too
+ // TODO: NexInStream: add getBytes() (size downloaded)
+ // TODO: public InputStrem open() (open/close do nothing)
+ // TODO: public boolean eof()
+ // TODO: public nextAll(): next, but disable separation of sub-streams
+ // TODO: close(alsoCloseIncludedField)
+
+ NextableInputStream stream = new NextableInputStream(in,
+ new NextableInputStreamStep('\n'));
+
+ if (in == null || stream.eof()) {
+ if (in == null) {
+ throw new NullPointerException("InputStream is null");
+ }
+ throw new NullPointerException("InputStream is empty");
+ }
+
+ while (stream.next()) {
+ boolean zip = stream.startsWiths("ZIP:");
+ boolean b64 = stream.startsWiths("B64:");
+
+ if (zip || b64) {
+ InputStream decoded = StringUtils.unbase64(stream.open(), zip);
+ try {
+ read(decoded);
+ } finally {
+ decoded.close();