Example usage for java.net URL host

List of usage examples for java.net URL host

Introduction

In this page you can find the example usage for java.net URL host.

Prototype

String host

To view the source code for java.net URL host.

Click Source Link

Usage

From source file:com.crosstreelabs.cognitio.Main.java

private void loadSeeds() throws IOException {
    Collection<File> seedFiles = new ArrayList<>();
    if (mc.conductorSeedFiles != null && !mc.conductorSeedFiles.isEmpty()) {
        seedFiles = mc.conductorSeedFiles;
    } else {/*from  w w w .j  av a2  s .c  om*/
        seedFiles.add(new File(mc.getHomeDirectory(), "seeds.txt"));
    }
    if (seedFiles.isEmpty()) {
        return;
    }

    final HostService hostService = injector.get(HostService.class);
    final CatalogueService catalogueService = injector.get(CatalogueService.class);

    for (File seedFile : seedFiles) {
        if (!seedFile.exists()) {
            LOGGER.warn("Seed file {} does not exist", seedFile);
            continue;
        }

        Iterator<String> it = FileUtils.lineIterator(seedFile);
        while (it.hasNext()) {
            String line = it.next();
            if (line == null || line.trim().isEmpty() || line.trim().startsWith("#")) {
                continue;
            }

            line = line.trim();

            io.mola.galimatias.URL url;
            try {
                url = io.mola.galimatias.URL.parse(line);
            } catch (GalimatiasParseException ex) {
                continue;
            }
            String tld = InternetDomainName.from(url.host().toString()).topPrivateDomain().toString();

            Host host = hostService.findByDomain(tld);
            if (host == null) {
                host = new Host();
                host.host = tld;
            }

            CatalogueEntry seed = new CatalogueEntry();
            seed.location = line;
            seed.initialDepth = 0;
            seed.status = Status.PENDING;
            seed.host = host;
            if (catalogueService.findForLocation(seed.location) == null) {
                LOGGER.info("Found seed: {}", line);
                catalogueService.save(seed);
            }
        }
    }
}