X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FImporter.java;h=a017fabfd362ea3ad27f72e0a6305856db2e41a1;hp=5d7d8d05ee30e298b802125abc63128c748ccb88;hb=564bbbdbc349805ff7fc1142facbedae87e5dc0e;hpb=1d20e650389b5aaaaa5de4213cefefade582da5d diff --git a/src/be/nikiroo/utils/serial/Importer.java b/src/be/nikiroo/utils/serial/Importer.java index 5d7d8d0..a017fab 100644 --- a/src/be/nikiroo/utils/serial/Importer.java +++ b/src/be/nikiroo/utils/serial/Importer.java @@ -68,37 +68,35 @@ public class Importer { NoSuchMethodException, ClassNotFoundException, IOException, NullPointerException { - // 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"); + try { + if (in == null || stream.eof()) { + if (in == null) { + throw new NullPointerException("InputStream is null"); + } + throw new NullPointerException("InputStream is empty"); } - 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(); + 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(); + } + } else { + processLine(stream); } - } else { - processLine(stream); } + } finally { + stream.close(false); } return this; @@ -217,37 +215,6 @@ public class Importer { } } - /** - * Find the given needle in the data and return its position (or -1 if not - * found). - * - * @param data - * the data to look through - * @param offset - * the offset at wich to start searching - * @param needle - * the needle to find - * - * @return the position of the needle if found, -1 if not found - */ - private int find(byte[] data, int offset, byte[] needle) { - for (int i = offset; i + needle.length - 1 < data.length; i++) { - boolean same = true; - for (int j = 0; j < needle.length; j++) { - if (data[i + j] != needle[j]) { - same = false; - break; - } - } - - if (same) { - return i; - } - } - - return -1; - } - /** * Return the current deserialised value. *