Example usage for java.util.logging Level FINEST

List of usage examples for java.util.logging Level FINEST

Introduction

In this page you can find the example usage for java.util.logging Level FINEST.

Prototype

Level FINEST

To view the source code for java.util.logging Level FINEST.

Click Source Link

Document

FINEST indicates a highly detailed tracing message.

Usage

From source file:net.sf.freecol.FreeCol.java

/**
 * Processes the command-line arguments and takes appropriate
 * actions for each of them.//ww w  . j av  a 2s. c o m
 *
 * @param args The command-line arguments.
 */
private static void handleArgs(String[] args) {
    Options options = new Options();
    final String help = Messages.message("cli.help");
    final File dummy = new File("dummy");
    final String argDirectory = Messages.message("cli.arg.directory");

    // Help options.
    options.addOption(OptionBuilder.withLongOpt("usage").withDescription(help).create());
    options.addOption(OptionBuilder.withLongOpt("help").withDescription(help).create());

    // Special options handled early.
    options.addOption(OptionBuilder.withLongOpt("freecol-data")
            .withDescription(Messages.message("cli.freecol-data")).withArgName(argDirectory).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("default-locale").withDescription(Messages.message("cli.default-locale"))
                    .withArgName(Messages.message("cli.arg.locale")).hasArg().create());

    // Ordinary options, handled here.
    options.addOption(OptionBuilder.withLongOpt("advantages")
            .withDescription(Messages.message(
                    StringTemplate.template("cli.advantages").addName("%advantages%", getValidAdvantages())))
            .withArgName(Messages.message("cli.arg.advantages")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("check-savegame").withDescription(Messages.message("cli.check-savegame"))
                    .withArgName(Messages.message("cli.arg.file")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("clientOptions").withDescription(Messages.message("cli.clientOptions"))
                    .withArgName(Messages.message("cli.arg.clientOptions")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("debug")
            .withDescription(Messages.message(
                    StringTemplate.template("cli.debug").addName("%modes%", FreeColDebugger.getDebugModes())))
            .withArgName(Messages.message("cli.arg.debug")).hasOptionalArg().create());
    options.addOption(OptionBuilder.withLongOpt("debug-run").withDescription(Messages.message("cli.debug-run"))
            .withArgName(Messages.message("cli.arg.debugRun")).hasOptionalArg().create());
    options.addOption(OptionBuilder.withLongOpt("debug-start")
            .withDescription(Messages.message("cli.debug-start")).create());
    options.addOption(
            OptionBuilder.withLongOpt("difficulty").withDescription(Messages.message("cli.difficulty"))
                    .withArgName(Messages.message("cli.arg.difficulty")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("europeans").withDescription(Messages.message("cli.european-count"))
                    .withArgName(Messages.message("cli.arg.europeans")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("fast").withDescription(Messages.message("cli.fast")).create());
    options.addOption(OptionBuilder.withLongOpt("font").withDescription(Messages.message("cli.font"))
            .withArgName(Messages.message("cli.arg.font")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("full-screen")
            .withDescription(Messages.message("cli.full-screen")).create());
    options.addOption(OptionBuilder.withLongOpt("gui-scale")
            .withDescription(Messages
                    .message(StringTemplate.template("cli.gui-scale").addName("%scales%", getValidGUIScales())))
            .withArgName(Messages.message("cli.arg.gui-scale")).hasOptionalArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("headless").withDescription(Messages.message("cli.headless")).create());
    options.addOption(
            OptionBuilder.withLongOpt("load-savegame").withDescription(Messages.message("cli.load-savegame"))
                    .withArgName(Messages.message("cli.arg.file")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("log-console")
            .withDescription(Messages.message("cli.log-console")).create());
    options.addOption(OptionBuilder.withLongOpt("log-file").withDescription(Messages.message("cli.log-file"))
            .withArgName(Messages.message("cli.arg.name")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("log-level").withDescription(Messages.message("cli.log-level"))
            .withArgName(Messages.message("cli.arg.loglevel")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("name").withDescription(Messages.message("cli.name"))
            .withArgName(Messages.message("cli.arg.name")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("no-intro").withDescription(Messages.message("cli.no-intro")).create());
    options.addOption(OptionBuilder.withLongOpt("no-java-check")
            .withDescription(Messages.message("cli.no-java-check")).create());
    options.addOption(OptionBuilder.withLongOpt("no-memory-check")
            .withDescription(Messages.message("cli.no-memory-check")).create());
    options.addOption(
            OptionBuilder.withLongOpt("no-sound").withDescription(Messages.message("cli.no-sound")).create());
    options.addOption(
            OptionBuilder.withLongOpt("no-splash").withDescription(Messages.message("cli.no-splash")).create());
    options.addOption(
            OptionBuilder.withLongOpt("private").withDescription(Messages.message("cli.private")).create());
    options.addOption(OptionBuilder.withLongOpt("seed").withDescription(Messages.message("cli.seed"))
            .withArgName(Messages.message("cli.arg.seed")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("server").withDescription(Messages.message("cli.server")).create());
    options.addOption(
            OptionBuilder.withLongOpt("server-name").withDescription(Messages.message("cli.server-name"))
                    .withArgName(Messages.message("cli.arg.name")).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("server-port").withDescription(Messages.message("cli.server-port"))
                    .withArgName(Messages.message("cli.arg.port")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("splash").withDescription(Messages.message("cli.splash"))
            .withArgName(Messages.message("cli.arg.file")).hasOptionalArg().create());
    options.addOption(OptionBuilder.withLongOpt("tc").withDescription(Messages.message("cli.tc"))
            .withArgName(Messages.message("cli.arg.name")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("timeout").withDescription(Messages.message("cli.timeout"))
            .withArgName(Messages.message("cli.arg.timeout")).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("user-cache-directory")
            .withDescription(Messages.message("cli.user-cache-directory")).withArgName(argDirectory)
            .withType(dummy).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("user-config-directory")
            .withDescription(Messages.message("cli.user-config-directory")).withArgName(argDirectory)
            .withType(dummy).hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("user-data-directory")
            .withDescription(Messages.message("cli.user-data-directory")).withArgName(argDirectory)
            .withType(dummy).hasArg().create());
    options.addOption(
            OptionBuilder.withLongOpt("version").withDescription(Messages.message("cli.version")).create());
    options.addOption(OptionBuilder.withLongOpt("windowed").withDescription(Messages.message("cli.windowed"))
            .withArgName(Messages.message("cli.arg.dimensions")).hasOptionalArg().create());

    CommandLineParser parser = new PosixParser();
    boolean usageError = false;
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help") || line.hasOption("usage")) {
            printUsage(options, 0);
        }

        if (line.hasOption("default-locale")) {
            ; // Do nothing, already handled in main().
        }
        if (line.hasOption("freecol-data")) {
            ; // Do nothing, already handled in main().
        }

        if (line.hasOption("advantages")) {
            String arg = line.getOptionValue("advantages");
            Advantages a = selectAdvantages(arg);
            if (a == null) {
                fatal(StringTemplate.template("cli.error.advantages")
                        .addName("%advantages%", getValidAdvantages()).addName("%arg%", arg));
            }
        }

        if (line.hasOption("check-savegame")) {
            String arg = line.getOptionValue("check-savegame");
            if (!FreeColDirectories.setSavegameFile(arg)) {
                fatal(StringTemplate.template("cli.err.save").addName("%string%", arg));
            }
            checkIntegrity = true;
            standAloneServer = true;
        }

        if (line.hasOption("clientOptions")) {
            String fileName = line.getOptionValue("clientOptions");
            if (!FreeColDirectories.setClientOptionsFile(fileName)) {
                // Not fatal.
                gripe(StringTemplate.template("cli.error.clientOptions").addName("%string%", fileName));
            }
        }

        if (line.hasOption("debug")) {
            // If the optional argument is supplied use limited mode.
            String arg = line.getOptionValue("debug");
            if (arg == null || arg.isEmpty()) {
                // Let empty argument default to menus functionality.
                arg = FreeColDebugger.DebugMode.MENUS.toString();
            }
            if (!FreeColDebugger.setDebugModes(arg)) { // Not fatal.
                gripe(StringTemplate.template("cli.error.debug").addName("%modes%",
                        FreeColDebugger.getDebugModes()));
            }
            // user set log level has precedence
            if (!line.hasOption("log-level"))
                logLevel = Level.FINEST;
        }
        if (line.hasOption("debug-run")) {
            FreeColDebugger.enableDebugMode(FreeColDebugger.DebugMode.MENUS);
            FreeColDebugger.configureDebugRun(line.getOptionValue("debug-run"));
        }
        if (line.hasOption("debug-start")) {
            debugStart = true;
            FreeColDebugger.enableDebugMode(FreeColDebugger.DebugMode.MENUS);
        }

        if (line.hasOption("difficulty")) {
            String arg = line.getOptionValue("difficulty");
            String difficulty = selectDifficulty(arg);
            if (difficulty == null) {
                fatal(StringTemplate.template("cli.error.difficulties")
                        .addName("%difficulties%", getValidDifficulties()).addName("%arg%", arg));
            }
        }

        if (line.hasOption("europeans")) {
            int e = selectEuropeanCount(line.getOptionValue("europeans"));
            if (e < 0) {
                gripe(StringTemplate.template("cli.error.europeans").addAmount("%min%", EUROPEANS_MIN));
            }
        }

        if (line.hasOption("fast")) {
            fastStart = true;
            introVideo = false;
        }

        if (line.hasOption("font")) {
            fontName = line.getOptionValue("font");
        }

        if (line.hasOption("full-screen")) {
            windowSize = null;
        }

        if (line.hasOption("gui-scale")) {
            String arg = line.getOptionValue("gui-scale");
            if (!setGUIScale(arg)) {
                gripe(StringTemplate.template("cli.error.gui-scale").addName("%scales%", getValidGUIScales())
                        .addName("%arg%", arg));
            }
        }

        if (line.hasOption("headless")) {
            headless = true;
        }

        if (line.hasOption("load-savegame")) {
            String arg = line.getOptionValue("load-savegame");
            if (!FreeColDirectories.setSavegameFile(arg)) {
                fatal(StringTemplate.template("cli.error.save").addName("%string%", arg));
            }
        }

        if (line.hasOption("log-console")) {
            consoleLogging = true;
        }
        if (line.hasOption("log-file")) {
            FreeColDirectories.setLogFilePath(line.getOptionValue("log-file"));
        }
        if (line.hasOption("log-level")) {
            setLogLevel(line.getOptionValue("log-level"));
        }

        if (line.hasOption("name")) {
            setName(line.getOptionValue("name"));
        }

        if (line.hasOption("no-intro")) {
            introVideo = false;
        }
        if (line.hasOption("no-java-check")) {
            javaCheck = false;
        }
        if (line.hasOption("no-memory-check")) {
            memoryCheck = false;
        }
        if (line.hasOption("no-sound")) {
            sound = false;
        }
        if (line.hasOption("no-splash")) {
            splashStream = null;
        }

        if (line.hasOption("private")) {
            publicServer = false;
        }

        if (line.hasOption("server")) {
            standAloneServer = true;
        }
        if (line.hasOption("server-name")) {
            serverName = line.getOptionValue("server-name");
        }
        if (line.hasOption("server-port")) {
            String arg = line.getOptionValue("server-port");
            if (!setServerPort(arg)) {
                fatal(StringTemplate.template("cli.error.serverPort").addName("%string%", arg));
            }
        }

        if (line.hasOption("seed")) {
            FreeColSeed.setFreeColSeed(line.getOptionValue("seed"));
        }

        if (line.hasOption("splash")) {
            String splash = line.getOptionValue("splash");
            try {
                FileInputStream fis = new FileInputStream(splash);
                splashStream = fis;
            } catch (FileNotFoundException fnfe) {
                gripe(StringTemplate.template("cli.error.splash").addName("%name%", splash));
            }
        }

        if (line.hasOption("tc")) {
            setTC(line.getOptionValue("tc")); // Failure is deferred.
        }

        if (line.hasOption("timeout")) {
            String arg = line.getOptionValue("timeout");
            if (!setTimeout(arg)) { // Not fatal
                gripe(StringTemplate.template("cli.error.timeout").addName("%string%", arg).addName("%minimum%",
                        Integer.toString(TIMEOUT_MIN)));
            }
        }

        if (line.hasOption("user-cache-directory")) {
            String arg = line.getOptionValue("user-cache-directory");
            String errMsg = FreeColDirectories.setUserCacheDirectory(arg);
            if (errMsg != null) { // Not fatal.
                gripe(StringTemplate.template(errMsg).addName("%string%", arg));
            }
        }

        if (line.hasOption("user-config-directory")) {
            String arg = line.getOptionValue("user-config-directory");
            String errMsg = FreeColDirectories.setUserConfigDirectory(arg);
            if (errMsg != null) { // Not fatal.
                gripe(StringTemplate.template(errMsg).addName("%string%", arg));
            }
        }

        if (line.hasOption("user-data-directory")) {
            String arg = line.getOptionValue("user-data-directory");
            String errMsg = FreeColDirectories.setUserDataDirectory(arg);
            if (errMsg != null) { // Fatal, unable to save.
                fatal(StringTemplate.template(errMsg).addName("%string%", arg));
            }
        }

        if (line.hasOption("version")) {
            System.out.println("FreeCol " + getVersion());
            System.exit(0);
        }

        if (line.hasOption("windowed")) {
            String arg = line.getOptionValue("windowed");
            setWindowSize(arg); // Does not fail
        }

    } catch (ParseException e) {
        System.err.println("\n" + e.getMessage() + "\n");
        usageError = true;
    }
    if (usageError)
        printUsage(options, 1);
}

From source file:hudson.plugins.repo.RepoScm.java

private String getStaticManifest(final Launcher launcher, final FilePath workspace, final OutputStream logger,
        final EnvVars env) throws IOException, InterruptedException {
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    final List<String> commands = new ArrayList<String>(6);
    commands.add(getDescriptor().getExecutable());
    commands.add("manifest");
    commands.add("-o");
    commands.add("-");
    commands.add("-r");
    // TODO: should we pay attention to the output from this?
    launcher.launch().stderr(logger).stdout(output).pwd(workspace).cmds(commands).envs(env).join();
    final String manifestText = output.toString();
    debug.log(Level.FINEST, manifestText);
    return manifestText;
}

From source file:hudson.plugins.repo.RepoScm.java

private String getManifestRevision(final Launcher launcher, final FilePath workspace, final OutputStream logger,
        final EnvVars env) throws IOException, InterruptedException {
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    final List<String> commands = new ArrayList<String>(6);
    commands.add("git");
    commands.add("rev-parse");
    commands.add("HEAD");
    launcher.launch().stderr(logger).stdout(output).pwd(new FilePath(workspace, ".repo/manifests"))
            .cmds(commands).envs(env).join();
    final String manifestText = output.toString().trim();
    debug.log(Level.FINEST, manifestText);
    return manifestText;
}

From source file:org.apache.myfaces.ov2021.application.jsp.JspStateManagerImpl.java

protected Object serializeView(FacesContext context, Object serializedView) {
    if (log.isLoggable(Level.FINEST))
        log.finest("Entering serializeView");

    if (isSerializeStateInSession(context)) {
        if (log.isLoggable(Level.FINEST))
            log.finest("Processing serializeView - serialize state in session");

        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
        try {/*from  w  ww.  ja  v  a  2s.  c  o  m*/
            OutputStream os = baos;
            if (isCompressStateInSession(context)) {
                if (log.isLoggable(Level.FINEST))
                    log.finest("Processing serializeView - serialize compressed");

                os.write(COMPRESSED_FLAG);
                os = new GZIPOutputStream(os, 1024);
            } else {
                if (log.isLoggable(Level.FINEST))
                    log.finest("Processing serializeView - serialize uncompressed");

                os.write(UNCOMPRESSED_FLAG);
            }

            Object[] stateArray = (Object[]) serializedView;

            ObjectOutputStream out = new ObjectOutputStream(os);
            out.writeObject(stateArray[0]);
            out.writeObject(stateArray[1]);
            out.close();
            baos.close();

            if (log.isLoggable(Level.FINEST))
                log.finest("Exiting serializeView - serialized. Bytes : " + baos.size());
            return baos.toByteArray();
        } catch (IOException e) {
            log.log(Level.SEVERE, "Exiting serializeView - Could not serialize state: " + e.getMessage(), e);
            return null;
        }
    }

    if (log.isLoggable(Level.FINEST))
        log.finest("Exiting serializeView - do not serialize state in session.");

    return serializedView;

}

From source file:edu.umass.cs.gigapaxos.PaxosInstanceStateMachine.java

protected void sendMessagingTask(MessagingTask mtask) {
    if (mtask == null || mtask.isEmpty())
        return;//from  w w  w .ja  v a2s .c  o  m
    if (this.paxosState != null && this.paxosState.isStopped()
            && !mtask.msgs[0].getType().equals(PaxosPacketType.DECISION)
            && !mtask.msgs[0].getType().equals(PaxosPacketType.CHECKPOINT_STATE))
        return;
    // if (TESTPaxosConfig.isCrashed(this.getMyID()))return;

    log.log(Level.FINEST, "{0} sending: {1}", new Object[] { this, mtask });
    mtask.putPaxosIDVersion(this.getPaxosID(), this.getVersion());
    try {
        // assert(this.paxosState.isActive());
        paxosManager.send(mtask);
    } catch (IOException ioe) {
        log.severe(this + " encountered IOException while sending " + mtask);
        ioe.printStackTrace();
        /* We can't throw this exception upward because it will get sent all
         * the way back up to PacketDemultiplexer whose incoming packet
         * initiated this whole chain of events. It seems silly for
         * PacketDemultiplexer to throw an IOException caused by the sends
         * resulting from processing that packet. So we should handle this
         * exception right here. But what should we do? We can ignore it as
         * the network does not need to be reliable anyway. Revisit as
         * needed. */
    } catch (JSONException je) {
        /* Same thing for other exceptions. Nothing useful to do here */
        log.severe(this + " encountered JSONException while sending " + mtask);
        je.printStackTrace();
    }
}

From source file:edu.usu.sdl.openstorefront.service.PersistenceService.java

/**
 * This will run the query and then unwrap if desired
 *
 * @param <T>//from  ww w. j a  v  a2  s  .c  o  m
 * @param query
 * @param parameterMap
 * @param dataClass
 * @param unwrap
 * @return
 */
public <T> List<T> query(String query, Map<String, Object> parameterMap, Class<T> dataClass, boolean unwrap) {
    OObjectDatabaseTx db = getConnection();
    List<T> results = new ArrayList<>();
    try {
        if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST, query);
        }
        //look for empty collection
        if (parameterMap != null) {
            for (Object value : parameterMap.values()) {
                if (value != null && value instanceof Collection) {
                    if (((Collection) value).isEmpty()) {
                        throw new OpenStorefrontRuntimeException(
                                "Unable to complete query with a empty collection.",
                                "Check query and parameter map");
                    }
                }
            }
        }

        results = db.query(new OSQLSynchQuery<>(query), parameterMap);
        if (unwrap) {
            results = unwrapProxy(db, dataClass, results);
        }
    } finally {
        closeConnection(db);
    }
    return results;
}

From source file:at.irian.myfaces.wscope.renderkit.html.WsServerSideStateCacheImpl.java

@Override
public Object saveSerializedView(FacesContext facesContext, Object serializedView) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Processing saveSerializedView - server-side state saving - save state");
    }//from   ww w . j  av a 2s.c  om
    //save state in server session
    saveSerializedViewInServletSession(facesContext, serializedView);

    if (log.isLoggable(Level.FINEST)) {
        log.finest("Exiting saveSerializedView - server-side state saving - saved state");
    }

    return encodeSerializedState(facesContext, serializedView);
}

From source file:edu.usu.sdl.openstorefront.service.UserServiceImpl.java

@Override
public void processAllUserMessages(boolean sendNow) {
    cleanupOldUserMessages();// w w  w.  ja va2s  . co m

    UserMessage userMessageExample = new UserMessage();
    userMessageExample.setActiveStatus(UserMessage.ACTIVE_STATUS);

    List<UserMessage> userMessages = persistenceService.queryByExample(UserMessage.class, userMessageExample);
    int minQueueMinutes = Convert
            .toInteger(PropertiesManager.getValue(PropertiesManager.KEY_MESSAGE_MIN_QUEUE_MINUTES, "10"));
    int maxRetries = Convert
            .toInteger(PropertiesManager.getValue(PropertiesManager.KEY_MESSAGE_MAX_RETRIES, "5"));
    if (minQueueMinutes < 0) {
        minQueueMinutes = 0;
    }
    long queueMills = System.currentTimeMillis() - TimeUtil.minutesToMillis(minQueueMinutes);

    //remove dups
    Map<String, UserMessage> messageMap = new HashMap<>();
    for (UserMessage userMessage : userMessages) {
        if (messageMap.containsKey(userMessage.uniqueKey())) {
            log.log(Level.FINE,
                    MessageFormat.format("Removing duplicate user message: ", userMessage.uniqueKey()));
        } else {
            messageMap.put(userMessage.uniqueKey(), userMessage);
        }
    }

    for (UserMessage userMessage : messageMap.values()) {

        if (sendNow || userMessage.getCreateDts().getTime() <= queueMills) {

            boolean updateUserMessage = false;
            UserMessage userMessageExisting = persistenceService.findById(UserMessage.class,
                    userMessage.getUserMessageId());
            if (userMessage.getRetryCount() < maxRetries) {
                try {
                    getUserServicePrivate().sendUserMessage(userMessage);
                } catch (MailException mailException) {
                    log.log(Level.FINE, "Unable to send message.", mailException);
                    userMessageExisting.setBodyOfMessage(
                            "Unable to send message to user.  Mail Server down? " + mailException.getMessage());
                    userMessageExisting.setRetryCount(userMessage.getRetryCount() + 1);
                    updateUserMessage = true;
                } catch (Exception e) {
                    log.log(Level.SEVERE, "Unexpected error.  Failed sending message. (Halt sending of "
                            + userMessage.getUserMessageId() + " message.)", e);
                    userMessageExisting.setActiveStatus(UserMessage.INACTIVE_STATUS);
                    userMessageExisting.setBodyOfMessage(
                            "System expection occured while sending message. See logs for details");
                    updateUserMessage = true;
                }
            } else {
                userMessageExisting.setActiveStatus(UserMessage.INACTIVE_STATUS);
                userMessageExisting.setBodyOfMessage("Exceed max reties.  Inactivated  message.");
                updateUserMessage = true;
            }

            if (updateUserMessage) {

                userMessageExisting.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                userMessageExisting.setUpdateDts(TimeUtil.currentDate());
                persistenceService.persist(userMessageExisting);
            }

        } else {
            log.log(Level.FINEST,
                    MessageFormat.format("Not time yet to send email to user: {0}", userMessage.getUsername()));
        }

    }

}

From source file:is.hi.bok.deduplicator.DeDuplicator.java

/**
 * Process a CrawlURI looking up in the index by content digest
 *
 * @param curi The CrawlURI to process/*from w w w  .j a  v a2s .  c  o m*/
 * @param currHostStats A statistics object for the current host. If per host statistics tracking is enabled this
 * must be non null and the method will increment appropriate counters on it.
 * @return The result of the lookup (a Lucene document). If a duplicate is not found null is returned.
 */
protected Document lookupByDigest(CrawlURI curi, Statistics currHostStats) {
    Document duplicate = null;
    String currentDigest = null;
    Object digest = curi.getContentDigest();
    if (digest != null) {
        currentDigest = Base32.encode((byte[]) digest);
    } else {
        logger.warning("Digest received from CrawlURI is null. Null Document returned");
        return null;
    }

    Query query = queryField(DigestIndexer.FIELD_DIGEST, currentDigest);
    try {
        AllDocsCollector collectAllCollector = new AllDocsCollector();
        index.search(query, collectAllCollector);

        List<ScoreDoc> hits = collectAllCollector.getHits();

        StringBuffer mirrors = new StringBuffer();
        mirrors.append("mirrors: ");
        if (hits != null && hits.size() > 0) {
            // Can definitely be more then one
            // Note: We may find an equivalent match before we find an
            // (existing) exact match.
            // TODO: Ensure that an exact match is recorded if it exists.
            Iterator<ScoreDoc> hitsIterator = hits.iterator();
            while (hitsIterator.hasNext() && duplicate == null) {
                ScoreDoc hit = hitsIterator.next();
                int docId = hit.doc;
                Document doc = index.doc(docId);
                String indexURL = doc.get(DigestIndexer.FIELD_URL);
                // See if the current hit is an exact match.
                if (curi.toString().equals(indexURL)) {
                    duplicate = doc;
                    stats.exactURLDuplicates++;
                    if (statsPerHost) {
                        currHostStats.exactURLDuplicates++;
                    }
                    logger.finest("Found exact match for " + curi.toString());
                }

                // If not, then check if it is an equivalent match (if
                // equivalent matches are allowed).
                if (duplicate == null && equivalent) {
                    String normalURL = DigestIndexer.stripURL(curi.toString());
                    String indexNormalURL = doc.get(DigestIndexer.FIELD_URL_NORMALIZED);
                    if (normalURL.equals(indexNormalURL)) {
                        duplicate = doc;
                        stats.equivalentURLDuplicates++;
                        if (statsPerHost) {
                            currHostStats.equivalentURLDuplicates++;
                        }
                        curi.addAnnotation("equivalent to " + indexURL);
                        logger.finest("Found equivalent match for " + curi.toString() + ". Normalized: "
                                + normalURL + ". Equivalent to: " + indexURL);
                    }
                }

                if (duplicate == null) {
                    // Will only be used if no exact (or equivalent) match
                    // is found.
                    mirrors.append(indexURL + " ");
                }
            }
            if (duplicate == null) {
                stats.mirrorNumber++;
                if (statsPerHost) {
                    currHostStats.mirrorNumber++;
                }
                logger.log(Level.FINEST, "Found mirror URLs for " + curi.toString() + ". " + mirrors);
            }
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Error accessing index.", e);
    }
    return duplicate;
}