/*
Method for see references in Eclipse. This version does not have a
dependency on a specific Eclipse version.

@param term  The indexterm to be processed.
@param printWriter The Writer used for writing content to disk.
189800
private void outputIndexEntry(final IndexTerm term, final XMLStreamWriter serializer) throws XMLStreamException {

        final List<IndexTermTarget> targets = term.getTargetList();

        boolean foundIndexTerm = false;
        boolean foundIndexsee = false;

        String indexSeeRefTerm = null;

        /*
         * Use the cloned List to find the index-see reference in the list. If
         * found use that target URI for the href value, otherwise return a
         * warning to the build. RFE 2987769 Eclipse index-see
         */
        final int termCloneNum = termCloneList.size();

        // Index-see and index-see-also terms should also generate links to its
        // target
        // Otherwise, the term won't be displayed in the index tab.
        if (!targets.isEmpty()) {
            for (final IndexTermTarget target : targets) {
                final String targetUri = target.getTargetURI();
                final String targetName = target.getTargetName();
                if (targetUri == null) {
                    serializer.writeStartElement("topic");
                    serializer.writeAttribute("title", target.getTargetName());
                    serializer.writeEndElement(); // topic
                } else if (targetName != null && targetName.trim().length() > 0) {
                    /*
                     * Check to see if the target Indexterm is a "see"
                     * reference.Added inIndexsee so we know that we are still
                     * processing contentfrom a referenced indexterm.
                     */
                    if (term.getTermPrefix() != null || inIndexsee) {
                        indexSeeRefTerm = term.getTermName();
                        inIndexsee = true;
                        foundIndexsee = true;
                        // Find the term with an href.
                        for (int j = 0; j < termCloneNum; j++) {
                            final IndexTerm termClone = termCloneList.get(j);
                            if (term.getTermName().equals(termClone.getTermName())) {
                                foundIndexTerm = true;
                                if (termClone.getTargetList().size() > 0) {
                                    serializer.writeStartElement("topic");
                                    final IndexTermTarget indexTermTarget = termClone.getTargetList().get(0);
                                    serializer.writeAttribute("href", replaceExtName(indexTermTarget.getTargetURI()));
                                    if (indexTermTarget.getTargetName() != null && !indexTermTarget.getTargetName().trim().isEmpty()) {
                                        serializer.writeAttribute("title", indexTermTarget.getTargetName());
                                    }
                                    serializer.writeEndElement(); // topic
                                }
                                /*
                                 * We found the term we are looking for, but it
                                 * does not have a target name (title). We need
                                 * to take a look at the subterms for the
                                 * redirect and
                                 */
                                termCloneList = termClone.getSubTerms();
                                break;
                            }
                        }// end for
                        // If there are no subterms, then we are done.
                        if (term.getSubTerms().size() == 0) {
                            inIndexsee = false;
                        }
                    } else {
                        serializer.writeStartElement("topic");
                        serializer.writeAttribute("href", replaceExtName(targetUri));
                        if (targetName.trim().length() > 0) {
                            serializer.writeAttribute("title", target.getTargetName());
                        }
                        serializer.writeEndElement(); // topic
                    }
                }
            }//end for
            if (!foundIndexTerm && foundIndexsee && indexSeeRefTerm != null && !indexSeeRefTerm.equals("***")){
                logger.warn(MessageUtils.getMessage("DOTJ050W", indexSeeRefTerm.trim()).toString());
            }
        }

    }
913337
protected void write(PrintWriter writer, String indent) {
        writer.print("(");

        if (!isEmpty()) {
            Token root = getRoot(true);
            int type = root.getType();
            int meaning = root.getMeaning();


            //
            // Display our type, text, and (optional) meaning

            writer.print(Types.getDescription(type));

            if (meaning != type) {
                writer.print(" as ");
                writer.print(Types.getDescription(meaning));
            }

            if (getStartLine() > -1) {
                writer.print(" at " + getStartLine() + ":" + getStartColumn());
            }

            String text = root.getText();
            int length = text.length();
            if (length > 0) {
                writer.print(": ");
                if (length > 40) {
                    text = text.substring(0, 17) + "..." + text.substring(length - 17, length);
                }

                writer.print(" \"");
                writer.print(text);
                writer.print("\" ");
            } else if (children() > 0) {
                writer.print(": ");
            }


            //
            // Recurse to display the children.

            int count = size();
            if (count > 1) {
                writer.println("");

                String indent1 = indent + "  ";
                String indent2 = indent + "   ";
                for (int i = 1; i < count; i++) {
                    writer.print(indent1);
                    writer.print(i);
                    writer.print(": ");

                    get(i, true).write(writer, indent2);
                }

                writer.print(indent);
            }
        }

        if (indent.length() > 0) {
            writer.println(")");
        } else {
            writer.print(")");
        }
    }
570165
public void outputAnnotationIndex(PrintWriter writer) {
        for (String ann : annotationIndex.keySet()) {
            writer.print(ann);
            writer.print(": ");
            Set<String> classes = annotationIndex.get(ann);
            Iterator<String> it = classes.iterator();
            while (it.hasNext()) {
                writer.print(it.next());
                if (it.hasNext())
                    writer.print(", ");
            }
            writer.println();
        }
    }
38941
public void addSubTerms(final List<IndexTerm> terms) {
        int subTermsNum;
        if (terms == null) {
            return;
        }

        subTermsNum = terms.size();
        for (int i = 0; i < subTermsNum; i++) {
            addSubTerm(terms.get(i));
        }
    }
714711
public final void writeMethod(int access, Method method, ClassVisitor visitor) {
    writeMethodTo(new CodeBuilder(access, method, null, visitor));
  }
317542
public void printStackTrace(PrintWriter printWriter) {
    if (mStackTrace == null) {
      printWriter.print(getMessage());
    }
    else {
      printWriter.print(mStackTrace);
    }
  }
47008
public void writeOntTxt(PrintWriter pw) {
        for (String id : terms.keySet()) {
            OntologyTerm term = terms.get(id);
            Set<String> synSet = new HashSet<String>();
            synSet.add(term.getName());
            for (Synonym s : term.getSynonyms()) {
                String st = s.getType();
                if (id.startsWith("PTCO")
                        || (st != null && !st
                                .matches(".*(InChI|SMILES|FORMULA).*"))) {
                    String synonym = s.getSyn();
                    if (!synonym.matches("\\S")) {// reject ontology terms
                                                  // consisting of a single
                                                  // letter as these produce too
                                                  // many false positives
                        synSet.add(synonym);
                    }
                }
            }

            pw.println("[" + id + "]");
            for (String syn : synSet)
                pw.println(syn);
            pw.println();
        }
        pw.flush();
    }
1251915
public synchronized void print(java.io.PrintWriter printWriter)
    {
        printWriter.println("State Dump for:" + cclass.getName()
                            + " headSequenceNumber=" + headSequenceNumber + "(long)" + " tailSequenceNumber=" + tailSequenceNumber + "(long)"
                        );
        printWriter.println();

        printWriter.println("Sublists...");
        for (int i = 0; i < subLists.length; i++)
        {
            subLists[i].print(printWriter);
        } // for subLists...

    }
858364
public void print(java.io.PrintWriter printWriter)
    {
        printWriter.println("State Dump for:" + cclass.getName()
                            + " sequenceNumber=" + sequenceNumber + "(int)"
                            + " allocationAllowed=" + allocationAllowed + "(boolean)"
                            + " storeName=" + storeName + "(String)"
                            + "\n objectStoreIdentifier=" + objectStoreIdentifier + "(int)"
                            + " storeStrategy=" + storeStrategy + "(int)" + strategyNames[storeStrategy] + "(String)"
                            + " persistent=" + persistent + "(boolean)"
                            + " objectManagerState=" + objectManagerState + "(ObjectManagerState)"
                        );
        printWriter.println();

        printWriter.println("inMemoryTokens...");
        for (java.util.Iterator tokenIterator = inMemoryTokens.values().iterator(); tokenIterator.hasNext();) {
            java.lang.ref.Reference reference = (java.lang.ref.Reference) tokenIterator.next();
            if (reference != null) {
                Token token = (Token) reference.get();
                if (token != null)
                    printWriter.println(token.toString());
            }
        } // for ... inMemoryTokens.

    }
1239014
@Override
    public void xmlWriteOn(FormattedWriter writer) throws IOException
    {
        if (consumerDispatcher != null)
        {
            writer.newLine();
            writer.taggedValue("consumerDispatcher", consumerDispatcher.toString());
        }
    }
175435
public void printProbs(String filename,
                         DocumentReaderAndWriter<IN> readerAndWriter) {
    // only for the OCR data does this matter
    flags.ocrTrain = false;

    ObjectBank<List<IN>> docs =
      makeObjectBankFromFile(filename, readerAndWriter);
    printProbsDocuments(docs);
  }
911461
public synchronized void print(java.io.PrintWriter printWriter)
    {
        try {
            printWriter.println("State Dump for:" + cclass.getName()
                                + "\n size()=" + size() + "(long)" + " size(null)=" + size(null) + "(long)");
            printWriter.println();

            printWriter.println("Tokens in order...");
            try {
                for (Iterator iterator = iterator();; printWriter.println(((Token) iterator.next(null)).toString()));
            } catch (java.util.NoSuchElementException exception) {
                // No FFDC code needed.
                // We have run off the end of the other collection.
            } // try.

        } catch (ObjectManagerException objectManagerException) {
            // No FFDC code needed.
            printWriter.println("Caught objectManagerException=" + objectManagerException);
            objectManagerException.printStackTrace(printWriter);
        } // try...

        printWriter.println();
    }
476869
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
            value = {"VA_FORMAT_STRING_USES_NEWLINE"},
            justification = "We don't want platform specific"
    )
    public static void printThreadInfo(PrintWriter writer, ThreadInfo t, ThreadMXBean mbean) {
        long cpuPercentage;
        try {
            long cpuTime = mbean.getThreadCpuTime(t.getThreadId());
            long threadUserTime = mbean.getThreadUserTime(t.getThreadId());
            cpuPercentage = (cpuTime == 0) ? 0: 100 * threadUserTime / cpuTime;
        } catch (UnsupportedOperationException x) {
            SupportLogFormatter.printStackTrace(x, writer);
            cpuPercentage = 0;
        }
        writer.printf("\"%s\" id=%d (0x%x) state=%s cpu=%d%%",
                t.getThreadName(),
                t.getThreadId(),
                t.getThreadId(),
                t.getThreadState(),
                cpuPercentage);
        final LockInfo lock = t.getLockInfo();
        if (lock != null && t.getThreadState() != Thread.State.BLOCKED) {
            writer.printf("\n    - waiting on <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
            writer.printf("\n    - locked <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
        } else if (lock != null && t.getThreadState() == Thread.State.BLOCKED) {
            writer.printf("\n    - waiting to lock <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
        }

        if (t.isSuspended()) {
            writer.print(" (suspended)");
        }

        if (t.isInNative()) {
            writer.print(" (running in native)");
        }

        writer.println();
        if (t.getLockOwnerName() != null) {
            writer.printf("      owned by \"%s\" id=%d (0x%x)\n",
                    t.getLockOwnerName(),
                    t.getLockOwnerId(),
                    t.getLockOwnerId());
        }

        final StackTraceElement[] elements = t.getStackTrace();
        final MonitorInfo[] monitors = t.getLockedMonitors();

        for (int i = 0; i < elements.length; i++) {
            final StackTraceElement element = elements[i];
            writer.printf("    at %s\n", element);
            for (int j = 1; j < monitors.length; j++) {
                final MonitorInfo monitor = monitors[j];
                if (monitor.getLockedStackDepth() == i) {
                    writer.printf("      - locked %s\n", monitor);
                }
            }
        }
        writer.println();

        final LockInfo[] locks = t.getLockedSynchronizers();
        if (locks.length > 0) {
            writer.printf("    Locked synchronizers: count = %d\n", locks.length);
            for (LockInfo l : locks) {
                writer.printf("      - %s\n", l);
            }
            writer.println();
        }
    }
1315677
private void initializeSecondaryIndexer() {
    SecondaryIndex secondaryIndexAnnotation = field.getAnnotation(SecondaryIndex.class);
    if (secondaryIndexAnnotation == null) {
      return;
    }
    String indexName = secondaryIndexAnnotation.name();
    if (indexName == null || indexName.trim().length() == 0) {
      indexName = DEFAULT_SECONDARY_INDEX_PREFIX + mappedName;
    }
    this.secondaryIndexName = indexName;
    try {
      secondaryIndexer = IndexerFactory.getInstance().getIndexer(field);
    } catch (Exception exp) {
      String pattern = "No suitable Indexer found or error occurred while creating the indexer "
          + "for field %s in class %s";
      String message = String.format(pattern, field.getName(), field.getDeclaringClass().getName());
      throw new EntityManagerException(message, exp);
    }

  }
575311
public static void write(String fileName, Collection<? extends Object> entries) {
        if (fileName == null) {
            throw new IllegalArgumentException("Must specify a file name to write to");
        }
        PrintWriter writer = null;
        File file = new File(fileName);
        try {
            file.mkdirs();
            if (file.exists()) {
                file.delete();
            }
            writer = new PrintWriter(new FileWriter(file), true);
            for (Object entry : entries) {
                writer.println(String.valueOf(entry));
            }
        }
        catch (Exception e) {
            throw new RuntimeException("Problem writing to " + file.getAbsolutePath(), e);
        }
        finally {
            try {
            	if(writer != null) {
            		writer.close();
                }
            }
            catch (Exception e) {
                //
            }
        }
    }
604905
public void write() throws Exception {
    PrintWriter out;
    String output = output();

    if (outFile != null) {
      out = new PrintWriter(Files.newBufferedWriter(outFile.toPath(), UTF_8));
    } else if (inPlace) {
      assert docFile != null
          : "@AssumeAssertion(nullness): dependent: docFile is non-null if inPlace is true";
      out = new PrintWriter(Files.newBufferedWriter(docFile.toPath(), UTF_8));
    } else {
      out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)));
    }

    out.println(output);
    out.flush();
    out.close();
  }
603157
public void xmlWriteOn(FormattedWriter writer) throws IOException
  {
    super.xmlWriteOn(writer);
    
    writer.newLine();
    writer.taggedValue("subscriberID", _subState.getSubscriberID());

    writer.newLine();
    writer.startTag("topics");
    writer.indent();

    String[] topics = _subState.getTopics();

    if (topics != null)
    {
      for (int i = 0; i < topics.length; i++)
      {
        writer.newLine();
        writer.taggedValue("topic", topics[i]);
      }
    }

    writer.outdent();
    writer.newLine();
    writer.endTag("topics");
    writer.newLine();
    writer.taggedValue("toBeDeleted", toBeDeleted);
  }