public static List<SubscriptionItem> readFrom(
            final InputStream in, @Nullable final ImportExportEventListener eventListener)
            throws InvalidSourceException {
        if (in == null) {
            throw new InvalidSourceException("input is null");
        }

        final List<SubscriptionItem> channels = new ArrayList<>();

        try {
            final JsonObject parentObject = JsonParser.object().from(in);

            if (!parentObject.has(JSON_SUBSCRIPTIONS_ARRAY_KEY)) {
                throw new InvalidSourceException("Channels array is null");
            }

            final JsonArray channelsArray = parentObject.getArray(JSON_SUBSCRIPTIONS_ARRAY_KEY);

            if (eventListener != null) {
                eventListener.onSizeReceived(channelsArray.size());
            }

            for (final Object o : channelsArray) {
                if (o instanceof JsonObject) {
                    final JsonObject itemObject = (JsonObject) o;
                    final int serviceId = itemObject.getInt(JSON_SERVICE_ID_KEY, 0);
                    final String url = itemObject.getString(JSON_URL_KEY);
                    final String name = itemObject.getString(JSON_NAME_KEY);

                    if (url != null && name != null && !url.isEmpty() && !name.isEmpty()) {
                        channels.add(new SubscriptionItem(serviceId, url, name));
                        if (eventListener != null) {
                            eventListener.onItemCompleted(name);
                        }
                    }
                }
            }
        } catch (final Throwable e) {
            throw new InvalidSourceException("Couldn't parse json", e);
        }

        return channels;
    }
@Test
    public void testInvalidSource() {
        final List<String> invalidList = Arrays.asList(
                "{}",
                "",
                null,
                "gibberish");

        for (final String invalidContent : invalidList) {
            try {
                if (invalidContent != null) {
                    final byte[] bytes = invalidContent.getBytes(StandardCharsets.UTF_8);
                    ImportExportJsonHelper.readFrom((new ByteArrayInputStream(bytes)), null);
                } else {
                    ImportExportJsonHelper.readFrom(null, null);
                }

                fail("didn't throw exception");
            } catch (final Exception e) {
                final boolean isExpectedException =
                        e instanceof SubscriptionExtractor.InvalidSourceException;
                assertTrue("\"" + e.getClass().getSimpleName()
                        + "\" is not the expected exception", isExpectedException);
            }
        }
    }