8000666: javadoc should write directly to Writer instead of composing strings
Reviewed-by: bpatel
This commit is contained in:
parent
ff931a19c1
commit
a0b8f099ab
@ -25,6 +25,8 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.tools.doclets.formats.html.markup.*;
|
||||
import com.sun.tools.doclets.internal.toolkit.*;
|
||||
@ -193,7 +195,7 @@ public class AnnotationTypeWriterImpl extends SubWriterHolderWriter
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void printDocument(Content contentTree) {
|
||||
public void printDocument(Content contentTree) throws IOException {
|
||||
printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType),
|
||||
true, contentTree);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
@ -202,7 +203,7 @@ public class ClassWriterImpl extends SubWriterHolderWriter
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void printDocument(Content contentTree) {
|
||||
public void printDocument(Content contentTree) throws IOException {
|
||||
printHtmlDocument(configuration.metakeywords.getMetaKeywords(classDoc),
|
||||
true, contentTree);
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void printDocument(Content contentTree) {
|
||||
public void printDocument(Content contentTree) throws IOException {
|
||||
printHtmlDocument(null, true, contentTree);
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class FrameOutputWriter extends HtmlDocletWriter {
|
||||
* Generate the contants in the "index.html" file. Print the frame details
|
||||
* as well as warning if browser is not supporting the Html frames.
|
||||
*/
|
||||
protected void generateFrameFile() {
|
||||
protected void generateFrameFile() throws IOException {
|
||||
Content frameset = getFrameDetails();
|
||||
if (configuration.windowtitle.length() > 0) {
|
||||
printFramesetDocument(configuration.windowtitle, configuration.notimestamp,
|
||||
|
@ -79,7 +79,7 @@ public class HelpWriter extends HtmlDocletWriter {
|
||||
/**
|
||||
* Generate the help file contents.
|
||||
*/
|
||||
protected void generateHelpFile() {
|
||||
protected void generateHelpFile() throws IOException {
|
||||
String title = configuration.getText("doclet.Window_Help_title");
|
||||
Content body = getBody(true, getWindowTitle(title));
|
||||
addTop(body);
|
||||
|
@ -361,7 +361,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
|
||||
* @param body the body htmltree to be included in the document
|
||||
*/
|
||||
public void printHtmlDocument(String[] metakeywords, boolean includeScript,
|
||||
Content body) {
|
||||
Content body) throws IOException {
|
||||
Content htmlDocType = DocType.Transitional();
|
||||
Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
|
||||
Content head = new HtmlTree(HtmlTag.HEAD);
|
||||
@ -391,7 +391,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
|
||||
head, body);
|
||||
Content htmlDocument = new HtmlDocument(htmlDocType,
|
||||
htmlComment, htmlTree);
|
||||
print(htmlDocument.toString());
|
||||
htmlDocument.write(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,7 +254,7 @@ public class PackageWriterImpl extends HtmlDocletWriter
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void printDocument(Content contentTree) {
|
||||
public void printDocument(Content contentTree) throws IOException {
|
||||
printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
|
||||
true, contentTree);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import com.sun.tools.doclets.internal.toolkit.util.DocletAbortException;
|
||||
* @author Atul M Dambalkar
|
||||
*/
|
||||
public class SerializedFormWriterImpl extends SubWriterHolderWriter
|
||||
implements com.sun.tools.doclets.internal.toolkit.SerializedFormWriter {
|
||||
implements SerializedFormWriter {
|
||||
|
||||
private static final String FILE_NAME = "serialized-form.html";
|
||||
|
||||
@ -214,7 +214,7 @@ public class SerializedFormWriterImpl extends SubWriterHolderWriter
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void printDocument(Content serializedTree) {
|
||||
public void printDocument(Content serializedTree) throws IOException {
|
||||
printHtmlDocument(null, true, serializedTree);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -38,7 +41,7 @@ import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
*
|
||||
* @author Bhavesh Patel
|
||||
*/
|
||||
public class Comment extends Content{
|
||||
public class Comment extends Content {
|
||||
|
||||
private String commentText;
|
||||
|
||||
@ -85,11 +88,13 @@ public class Comment extends Content{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
if (!endsWithNewLine(contentBuilder))
|
||||
contentBuilder.append(DocletConstants.NL);
|
||||
contentBuilder.append("<!-- ");
|
||||
contentBuilder.append(commentText);
|
||||
contentBuilder.append(" -->" + DocletConstants.NL);
|
||||
@Override
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
if (!atNewline)
|
||||
out.write(DocletConstants.NL);
|
||||
out.write("<!-- ");
|
||||
out.write(commentText);
|
||||
out.write(" -->" + DocletConstants.NL);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -112,7 +115,9 @@ public class DocType extends Content{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
contentBuilder.append(docType);
|
||||
@Override
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
out.write(docType);
|
||||
return true; // guaranteed by constructor
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ public abstract class HtmlDocWriter extends HtmlWriter {
|
||||
* @param frameset the frameset to be added to the HTML document
|
||||
*/
|
||||
public void printFramesetDocument(String title, boolean noTimeStamp,
|
||||
Content frameset) {
|
||||
Content frameset) throws IOException {
|
||||
Content htmlDocType = DocType.Frameset();
|
||||
Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
|
||||
Content head = new HtmlTree(HtmlTag.HEAD);
|
||||
@ -345,7 +345,7 @@ public abstract class HtmlDocWriter extends HtmlWriter {
|
||||
head, frameset);
|
||||
Content htmlDocument = new HtmlDocument(htmlDocType,
|
||||
htmlComment, htmlTree);
|
||||
print(htmlDocument.toString());
|
||||
htmlDocument.write(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,10 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -74,7 +77,7 @@ public class HtmlDocument extends Content {
|
||||
*
|
||||
* @param htmlContent html content to be added
|
||||
*/
|
||||
public void addContent(Content htmlContent) {
|
||||
public final void addContent(Content htmlContent) {
|
||||
if (htmlContent.isValid())
|
||||
docContent.add(htmlContent);
|
||||
}
|
||||
@ -101,8 +104,9 @@ public class HtmlDocument extends Content {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
for (Content c : docContent)
|
||||
c.write(contentBuilder);
|
||||
atNewline = c.write(out, atNewline);
|
||||
return atNewline;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,10 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -756,35 +759,41 @@ public class HtmlTree extends Content {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
if (!isInline() && !endsWithNewLine(contentBuilder))
|
||||
contentBuilder.append(DocletConstants.NL);
|
||||
@Override
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
if (!isInline() && !atNewline)
|
||||
out.write(DocletConstants.NL);
|
||||
String tagString = htmlTag.toString();
|
||||
contentBuilder.append("<");
|
||||
contentBuilder.append(tagString);
|
||||
out.write("<");
|
||||
out.write(tagString);
|
||||
Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
|
||||
HtmlAttr key;
|
||||
String value = "";
|
||||
while (iterator.hasNext()) {
|
||||
key = iterator.next();
|
||||
value = attrs.get(key);
|
||||
contentBuilder.append(" ");
|
||||
contentBuilder.append(key.toString());
|
||||
out.write(" ");
|
||||
out.write(key.toString());
|
||||
if (!value.isEmpty()) {
|
||||
contentBuilder.append("=\"");
|
||||
contentBuilder.append(value);
|
||||
contentBuilder.append("\"");
|
||||
out.write("=\"");
|
||||
out.write(value);
|
||||
out.write("\"");
|
||||
}
|
||||
}
|
||||
contentBuilder.append(">");
|
||||
out.write(">");
|
||||
boolean nl = false;
|
||||
for (Content c : content)
|
||||
c.write(contentBuilder);
|
||||
nl = c.write(out, nl);
|
||||
if (htmlTag.endTagRequired()) {
|
||||
contentBuilder.append("</");
|
||||
contentBuilder.append(tagString);
|
||||
contentBuilder.append(">");
|
||||
out.write("</");
|
||||
out.write(tagString);
|
||||
out.write(">");
|
||||
}
|
||||
if (!isInline()) {
|
||||
out.write(DocletConstants.NL);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!isInline())
|
||||
contentBuilder.append(DocletConstants.NL);
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ public class HtmlWriter extends PrintWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the script code to be embeded before the </HEAD> tag.
|
||||
* Print the script code to be embedded before the </HEAD> tag.
|
||||
*/
|
||||
protected void printWinTitleScript(String winTitle){
|
||||
if(winTitle != null && winTitle.length() > 0) {
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -87,7 +90,16 @@ public class RawHtml extends Content{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
contentBuilder.append(rawHtmlContent);
|
||||
public String toString() {
|
||||
return rawHtmlContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
out.write(rawHtmlContent);
|
||||
return rawHtmlContent.endsWith(DocletConstants.NL);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
package com.sun.tools.doclets.formats.html.markup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.Content;
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
@ -98,7 +101,10 @@ public class StringContent extends Content{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void write(StringBuilder contentBuilder) {
|
||||
contentBuilder.append(stringContent);
|
||||
@Override
|
||||
public boolean write(Writer out, boolean atNewline) throws IOException {
|
||||
String s = stringContent.toString();
|
||||
out.write(s);
|
||||
return s.endsWith(DocletConstants.NL);
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public interface AnnotationTypeWriter {
|
||||
*
|
||||
* @param contentTree content tree that will be printed as a document
|
||||
*/
|
||||
public void printDocument(Content contentTree);
|
||||
public void printDocument(Content contentTree) throws IOException ;
|
||||
|
||||
/**
|
||||
* Close the writer.
|
||||
|
@ -180,7 +180,7 @@ public interface ClassWriter {
|
||||
*
|
||||
* @param contentTree content tree that will be printed as a document
|
||||
*/
|
||||
public void printDocument(Content contentTree);
|
||||
public void printDocument(Content contentTree) throws IOException;
|
||||
|
||||
/**
|
||||
* Close the writer.
|
||||
|
@ -139,6 +139,6 @@ public interface ConstantsSummaryWriter {
|
||||
*
|
||||
* @param contentTree content tree which should be printed
|
||||
*/
|
||||
public abstract void printDocument(Content contentTree);
|
||||
public abstract void printDocument(Content contentTree) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,10 @@
|
||||
|
||||
package com.sun.tools.doclets.internal.toolkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
||||
|
||||
/**
|
||||
@ -44,10 +48,16 @@ public abstract class Content {
|
||||
*
|
||||
* @return string representation of the content
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
write(contentBuilder);
|
||||
return contentBuilder.toString();
|
||||
StringWriter out = new StringWriter();
|
||||
try {
|
||||
write(out, true);
|
||||
} catch (IOException e) {
|
||||
// cannot happen from StringWriter
|
||||
throw new DocletAbortException();
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,10 +75,10 @@ public abstract class Content {
|
||||
public abstract void addContent(String stringContent);
|
||||
|
||||
/**
|
||||
* Writes content to a StringBuilder.
|
||||
* Writes content to a writer.
|
||||
*
|
||||
*/
|
||||
public abstract void write(StringBuilder contentBuilder);
|
||||
public abstract boolean write(Writer writer, boolean atNewline) throws IOException ;
|
||||
|
||||
/**
|
||||
* Returns true if the content is empty.
|
||||
|
@ -115,7 +115,7 @@ public interface PackageSummaryWriter {
|
||||
*
|
||||
* @param contentTree the content tree that will be printed
|
||||
*/
|
||||
public abstract void printDocument(Content contentTree);
|
||||
public abstract void printDocument(Content contentTree) throws IOException;
|
||||
|
||||
/**
|
||||
* Close the writer.
|
||||
|
@ -151,7 +151,7 @@ public interface SerializedFormWriter {
|
||||
*
|
||||
* @param serializedTree the content tree that will be printed
|
||||
*/
|
||||
public abstract void printDocument(Content serializedTree);
|
||||
public abstract void printDocument(Content serializedTree) throws IOException;
|
||||
|
||||
/**
|
||||
* Write the serialized form for a given field.
|
||||
|
@ -650,9 +650,9 @@ public class Util {
|
||||
fos = new FileOutputStream(filename);
|
||||
}
|
||||
if (docencoding == null) {
|
||||
return new OutputStreamWriter(fos);
|
||||
return new BufferedWriter(new OutputStreamWriter(fos));
|
||||
} else {
|
||||
return new OutputStreamWriter(fos, docencoding);
|
||||
return new BufferedWriter(new OutputStreamWriter(fos, docencoding));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user