static MultiItem deserialize()

in curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/ItemSerializer.java [39:74]


    static <T> MultiItem<T> deserialize(byte[] bytes, QueueSerializer<T> serializer) throws Exception {
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
        int version = in.readInt();
        if (version != VERSION) {
            throw new IOException(String.format("Incorrect version. Expected %d - Found: %d", VERSION, version));
        }

        List<T> items = Lists.newArrayList();
        for (; ; ) {
            byte opcode = in.readByte();
            if (opcode == EOF_OPCODE) {
                break;
            }

            if (opcode != ITEM_OPCODE) {
                throw new IOException(String.format("Incorrect opcode. Expected %d - Found: %d", ITEM_OPCODE, opcode));
            }
            int size = in.readInt();
            if (size < 0) {
                throw new IOException(String.format("Bad size: %d", size));
            }
            byte[] itemBytes = new byte[size];
            if (size > 0) {
                in.readFully(itemBytes);
            }
            items.add(serializer.deserialize(itemBytes));
        }

        final Iterator<T> iterator = items.iterator();
        return new MultiItem<T>() {
            @Override
            public T nextItem() {
                return iterator.hasNext() ? iterator.next() : null;
            }
        };
    }