Mon, 15 Oct 2012 17:07:55 -0700
8000666: javadoc should write directly to Writer instead of composing strings
Reviewed-by: bpatel
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java Fri Oct 12 14:53:50 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/AnnotationTypeWriterImpl.java Mon Oct 15 17:07:55 2012 -0700 1.3 @@ -25,6 +25,8 @@ 1.4 1.5 package com.sun.tools.doclets.formats.html; 1.6 1.7 +import java.io.IOException; 1.8 + 1.9 import com.sun.javadoc.*; 1.10 import com.sun.tools.doclets.formats.html.markup.*; 1.11 import com.sun.tools.doclets.internal.toolkit.*; 1.12 @@ -193,7 +195,7 @@ 1.13 /** 1.14 * {@inheritDoc} 1.15 */ 1.16 - public void printDocument(Content contentTree) { 1.17 + public void printDocument(Content contentTree) throws IOException { 1.18 printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType), 1.19 true, contentTree); 1.20 }
2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Fri Oct 12 14:53:50 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Mon Oct 15 17:07:55 2012 -0700 2.3 @@ -25,6 +25,7 @@ 2.4 2.5 package com.sun.tools.doclets.formats.html; 2.6 2.7 +import java.io.IOException; 2.8 import java.util.*; 2.9 2.10 import com.sun.javadoc.*; 2.11 @@ -202,7 +203,7 @@ 2.12 /** 2.13 * {@inheritDoc} 2.14 */ 2.15 - public void printDocument(Content contentTree) { 2.16 + public void printDocument(Content contentTree) throws IOException { 2.17 printHtmlDocument(configuration.metakeywords.getMetaKeywords(classDoc), 2.18 true, contentTree); 2.19 }
3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java Fri Oct 12 14:53:50 2012 -0700 3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java Mon Oct 15 17:07:55 2012 -0700 3.3 @@ -303,7 +303,7 @@ 3.4 /** 3.5 * {@inheritDoc} 3.6 */ 3.7 - public void printDocument(Content contentTree) { 3.8 + public void printDocument(Content contentTree) throws IOException { 3.9 printHtmlDocument(null, true, contentTree); 3.10 } 3.11 }
4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java Fri Oct 12 14:53:50 2012 -0700 4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java Mon Oct 15 17:07:55 2012 -0700 4.3 @@ -95,7 +95,7 @@ 4.4 * Generate the contants in the "index.html" file. Print the frame details 4.5 * as well as warning if browser is not supporting the Html frames. 4.6 */ 4.7 - protected void generateFrameFile() { 4.8 + protected void generateFrameFile() throws IOException { 4.9 Content frameset = getFrameDetails(); 4.10 if (configuration.windowtitle.length() > 0) { 4.11 printFramesetDocument(configuration.windowtitle, configuration.notimestamp,
5.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Fri Oct 12 14:53:50 2012 -0700 5.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Mon Oct 15 17:07:55 2012 -0700 5.3 @@ -79,7 +79,7 @@ 5.4 /** 5.5 * Generate the help file contents. 5.6 */ 5.7 - protected void generateHelpFile() { 5.8 + protected void generateHelpFile() throws IOException { 5.9 String title = configuration.getText("doclet.Window_Help_title"); 5.10 Content body = getBody(true, getWindowTitle(title)); 5.11 addTop(body);
6.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Fri Oct 12 14:53:50 2012 -0700 6.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon Oct 15 17:07:55 2012 -0700 6.3 @@ -361,7 +361,7 @@ 6.4 * @param body the body htmltree to be included in the document 6.5 */ 6.6 public void printHtmlDocument(String[] metakeywords, boolean includeScript, 6.7 - Content body) { 6.8 + Content body) throws IOException { 6.9 Content htmlDocType = DocType.Transitional(); 6.10 Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); 6.11 Content head = new HtmlTree(HtmlTag.HEAD); 6.12 @@ -391,7 +391,7 @@ 6.13 head, body); 6.14 Content htmlDocument = new HtmlDocument(htmlDocType, 6.15 htmlComment, htmlTree); 6.16 - print(htmlDocument.toString()); 6.17 + htmlDocument.write(this, true); 6.18 } 6.19 6.20 /**
7.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java Fri Oct 12 14:53:50 2012 -0700 7.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageWriterImpl.java Mon Oct 15 17:07:55 2012 -0700 7.3 @@ -254,7 +254,7 @@ 7.4 /** 7.5 * {@inheritDoc} 7.6 */ 7.7 - public void printDocument(Content contentTree) { 7.8 + public void printDocument(Content contentTree) throws IOException { 7.9 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc), 7.10 true, contentTree); 7.11 }
8.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java Fri Oct 12 14:53:50 2012 -0700 8.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java Mon Oct 15 17:07:55 2012 -0700 8.3 @@ -42,7 +42,7 @@ 8.4 * @author Atul M Dambalkar 8.5 */ 8.6 public class SerializedFormWriterImpl extends SubWriterHolderWriter 8.7 - implements com.sun.tools.doclets.internal.toolkit.SerializedFormWriter { 8.8 + implements SerializedFormWriter { 8.9 8.10 private static final String FILE_NAME = "serialized-form.html"; 8.11 8.12 @@ -214,7 +214,7 @@ 8.13 /** 8.14 * {@inheritDoc} 8.15 */ 8.16 - public void printDocument(Content serializedTree) { 8.17 + public void printDocument(Content serializedTree) throws IOException { 8.18 printHtmlDocument(null, true, serializedTree); 8.19 } 8.20
9.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java Fri Oct 12 14:53:50 2012 -0700 9.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/Comment.java Mon Oct 15 17:07:55 2012 -0700 9.3 @@ -25,6 +25,9 @@ 9.4 9.5 package com.sun.tools.doclets.formats.html.markup; 9.6 9.7 +import java.io.IOException; 9.8 +import java.io.Writer; 9.9 + 9.10 import com.sun.tools.doclets.internal.toolkit.Content; 9.11 import com.sun.tools.doclets.internal.toolkit.util.*; 9.12 9.13 @@ -38,7 +41,7 @@ 9.14 * 9.15 * @author Bhavesh Patel 9.16 */ 9.17 -public class Comment extends Content{ 9.18 +public class Comment extends Content { 9.19 9.20 private String commentText; 9.21 9.22 @@ -85,11 +88,13 @@ 9.23 /** 9.24 * {@inheritDoc} 9.25 */ 9.26 - public void write(StringBuilder contentBuilder) { 9.27 - if (!endsWithNewLine(contentBuilder)) 9.28 - contentBuilder.append(DocletConstants.NL); 9.29 - contentBuilder.append("<!-- "); 9.30 - contentBuilder.append(commentText); 9.31 - contentBuilder.append(" -->" + DocletConstants.NL); 9.32 + @Override 9.33 + public boolean write(Writer out, boolean atNewline) throws IOException { 9.34 + if (!atNewline) 9.35 + out.write(DocletConstants.NL); 9.36 + out.write("<!-- "); 9.37 + out.write(commentText); 9.38 + out.write(" -->" + DocletConstants.NL); 9.39 + return true; 9.40 } 9.41 }
10.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java Fri Oct 12 14:53:50 2012 -0700 10.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/DocType.java Mon Oct 15 17:07:55 2012 -0700 10.3 @@ -25,6 +25,9 @@ 10.4 10.5 package com.sun.tools.doclets.formats.html.markup; 10.6 10.7 +import java.io.IOException; 10.8 +import java.io.Writer; 10.9 + 10.10 import com.sun.tools.doclets.internal.toolkit.Content; 10.11 import com.sun.tools.doclets.internal.toolkit.util.*; 10.12 10.13 @@ -112,7 +115,9 @@ 10.14 /** 10.15 * {@inheritDoc} 10.16 */ 10.17 - public void write(StringBuilder contentBuilder) { 10.18 - contentBuilder.append(docType); 10.19 + @Override 10.20 + public boolean write(Writer out, boolean atNewline) throws IOException { 10.21 + out.write(docType); 10.22 + return true; // guaranteed by constructor 10.23 } 10.24 }
11.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Fri Oct 12 14:53:50 2012 -0700 11.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Mon Oct 15 17:07:55 2012 -0700 11.3 @@ -325,7 +325,7 @@ 11.4 * @param frameset the frameset to be added to the HTML document 11.5 */ 11.6 public void printFramesetDocument(String title, boolean noTimeStamp, 11.7 - Content frameset) { 11.8 + Content frameset) throws IOException { 11.9 Content htmlDocType = DocType.Frameset(); 11.10 Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); 11.11 Content head = new HtmlTree(HtmlTag.HEAD); 11.12 @@ -345,7 +345,7 @@ 11.13 head, frameset); 11.14 Content htmlDocument = new HtmlDocument(htmlDocType, 11.15 htmlComment, htmlTree); 11.16 - print(htmlDocument.toString()); 11.17 + htmlDocument.write(this, true); 11.18 } 11.19 11.20 /**
12.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocument.java Fri Oct 12 14:53:50 2012 -0700 12.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocument.java Mon Oct 15 17:07:55 2012 -0700 12.3 @@ -25,7 +25,10 @@ 12.4 12.5 package com.sun.tools.doclets.formats.html.markup; 12.6 12.7 +import java.io.IOException; 12.8 +import java.io.Writer; 12.9 import java.util.*; 12.10 + 12.11 import com.sun.tools.doclets.internal.toolkit.Content; 12.12 import com.sun.tools.doclets.internal.toolkit.util.*; 12.13 12.14 @@ -74,7 +77,7 @@ 12.15 * 12.16 * @param htmlContent html content to be added 12.17 */ 12.18 - public void addContent(Content htmlContent) { 12.19 + public final void addContent(Content htmlContent) { 12.20 if (htmlContent.isValid()) 12.21 docContent.add(htmlContent); 12.22 } 12.23 @@ -101,8 +104,9 @@ 12.24 /** 12.25 * {@inheritDoc} 12.26 */ 12.27 - public void write(StringBuilder contentBuilder) { 12.28 + public boolean write(Writer out, boolean atNewline) throws IOException { 12.29 for (Content c : docContent) 12.30 - c.write(contentBuilder); 12.31 + atNewline = c.write(out, atNewline); 12.32 + return atNewline; 12.33 } 12.34 }
13.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Fri Oct 12 14:53:50 2012 -0700 13.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Mon Oct 15 17:07:55 2012 -0700 13.3 @@ -25,7 +25,10 @@ 13.4 13.5 package com.sun.tools.doclets.formats.html.markup; 13.6 13.7 +import java.io.IOException; 13.8 +import java.io.Writer; 13.9 import java.util.*; 13.10 + 13.11 import com.sun.tools.doclets.internal.toolkit.Content; 13.12 import com.sun.tools.doclets.internal.toolkit.util.*; 13.13 13.14 @@ -756,35 +759,41 @@ 13.15 /** 13.16 * {@inheritDoc} 13.17 */ 13.18 - public void write(StringBuilder contentBuilder) { 13.19 - if (!isInline() && !endsWithNewLine(contentBuilder)) 13.20 - contentBuilder.append(DocletConstants.NL); 13.21 + @Override 13.22 + public boolean write(Writer out, boolean atNewline) throws IOException { 13.23 + if (!isInline() && !atNewline) 13.24 + out.write(DocletConstants.NL); 13.25 String tagString = htmlTag.toString(); 13.26 - contentBuilder.append("<"); 13.27 - contentBuilder.append(tagString); 13.28 + out.write("<"); 13.29 + out.write(tagString); 13.30 Iterator<HtmlAttr> iterator = attrs.keySet().iterator(); 13.31 HtmlAttr key; 13.32 String value = ""; 13.33 while (iterator.hasNext()) { 13.34 key = iterator.next(); 13.35 value = attrs.get(key); 13.36 - contentBuilder.append(" "); 13.37 - contentBuilder.append(key.toString()); 13.38 + out.write(" "); 13.39 + out.write(key.toString()); 13.40 if (!value.isEmpty()) { 13.41 - contentBuilder.append("=\""); 13.42 - contentBuilder.append(value); 13.43 - contentBuilder.append("\""); 13.44 + out.write("=\""); 13.45 + out.write(value); 13.46 + out.write("\""); 13.47 } 13.48 } 13.49 - contentBuilder.append(">"); 13.50 + out.write(">"); 13.51 + boolean nl = false; 13.52 for (Content c : content) 13.53 - c.write(contentBuilder); 13.54 + nl = c.write(out, nl); 13.55 if (htmlTag.endTagRequired()) { 13.56 - contentBuilder.append("</"); 13.57 - contentBuilder.append(tagString); 13.58 - contentBuilder.append(">"); 13.59 + out.write("</"); 13.60 + out.write(tagString); 13.61 + out.write(">"); 13.62 } 13.63 - if (!isInline()) 13.64 - contentBuilder.append(DocletConstants.NL); 13.65 + if (!isInline()) { 13.66 + out.write(DocletConstants.NL); 13.67 + return true; 13.68 + } else { 13.69 + return false; 13.70 + } 13.71 } 13.72 }
14.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Fri Oct 12 14:53:50 2012 -0700 14.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Mon Oct 15 17:07:55 2012 -0700 14.3 @@ -266,7 +266,7 @@ 14.4 } 14.5 14.6 /** 14.7 - * Print the script code to be embeded before the </HEAD> tag. 14.8 + * Print the script code to be embedded before the </HEAD> tag. 14.9 */ 14.10 protected void printWinTitleScript(String winTitle){ 14.11 if(winTitle != null && winTitle.length() > 0) {
15.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/RawHtml.java Fri Oct 12 14:53:50 2012 -0700 15.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/RawHtml.java Mon Oct 15 17:07:55 2012 -0700 15.3 @@ -25,6 +25,9 @@ 15.4 15.5 package com.sun.tools.doclets.formats.html.markup; 15.6 15.7 +import java.io.IOException; 15.8 +import java.io.Writer; 15.9 + 15.10 import com.sun.tools.doclets.internal.toolkit.Content; 15.11 import com.sun.tools.doclets.internal.toolkit.util.*; 15.12 15.13 @@ -87,7 +90,16 @@ 15.14 /** 15.15 * {@inheritDoc} 15.16 */ 15.17 - public void write(StringBuilder contentBuilder) { 15.18 - contentBuilder.append(rawHtmlContent); 15.19 + public String toString() { 15.20 + return rawHtmlContent; 15.21 + } 15.22 + 15.23 + /** 15.24 + * {@inheritDoc} 15.25 + */ 15.26 + @Override 15.27 + public boolean write(Writer out, boolean atNewline) throws IOException { 15.28 + out.write(rawHtmlContent); 15.29 + return rawHtmlContent.endsWith(DocletConstants.NL); 15.30 } 15.31 }
16.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java Fri Oct 12 14:53:50 2012 -0700 16.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java Mon Oct 15 17:07:55 2012 -0700 16.3 @@ -25,6 +25,9 @@ 16.4 16.5 package com.sun.tools.doclets.formats.html.markup; 16.6 16.7 +import java.io.IOException; 16.8 +import java.io.Writer; 16.9 + 16.10 import com.sun.tools.doclets.internal.toolkit.Content; 16.11 import com.sun.tools.doclets.internal.toolkit.util.*; 16.12 16.13 @@ -98,7 +101,10 @@ 16.14 /** 16.15 * {@inheritDoc} 16.16 */ 16.17 - public void write(StringBuilder contentBuilder) { 16.18 - contentBuilder.append(stringContent); 16.19 + @Override 16.20 + public boolean write(Writer out, boolean atNewline) throws IOException { 16.21 + String s = stringContent.toString(); 16.22 + out.write(s); 16.23 + return s.endsWith(DocletConstants.NL); 16.24 } 16.25 }
17.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/AnnotationTypeWriter.java Fri Oct 12 14:53:50 2012 -0700 17.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/AnnotationTypeWriter.java Mon Oct 15 17:07:55 2012 -0700 17.3 @@ -153,7 +153,7 @@ 17.4 * 17.5 * @param contentTree content tree that will be printed as a document 17.6 */ 17.7 - public void printDocument(Content contentTree); 17.8 + public void printDocument(Content contentTree) throws IOException ; 17.9 17.10 /** 17.11 * Close the writer.
18.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/ClassWriter.java Fri Oct 12 14:53:50 2012 -0700 18.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/ClassWriter.java Mon Oct 15 17:07:55 2012 -0700 18.3 @@ -180,7 +180,7 @@ 18.4 * 18.5 * @param contentTree content tree that will be printed as a document 18.6 */ 18.7 - public void printDocument(Content contentTree); 18.8 + public void printDocument(Content contentTree) throws IOException; 18.9 18.10 /** 18.11 * Close the writer.
19.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/ConstantsSummaryWriter.java Fri Oct 12 14:53:50 2012 -0700 19.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/ConstantsSummaryWriter.java Mon Oct 15 17:07:55 2012 -0700 19.3 @@ -139,6 +139,6 @@ 19.4 * 19.5 * @param contentTree content tree which should be printed 19.6 */ 19.7 - public abstract void printDocument(Content contentTree); 19.8 + public abstract void printDocument(Content contentTree) throws IOException; 19.9 19.10 }
20.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java Fri Oct 12 14:53:50 2012 -0700 20.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java Mon Oct 15 17:07:55 2012 -0700 20.3 @@ -25,6 +25,10 @@ 20.4 20.5 package com.sun.tools.doclets.internal.toolkit; 20.6 20.7 +import java.io.IOException; 20.8 +import java.io.StringWriter; 20.9 +import java.io.Writer; 20.10 + 20.11 import com.sun.tools.doclets.internal.toolkit.util.*; 20.12 20.13 /** 20.14 @@ -44,10 +48,16 @@ 20.15 * 20.16 * @return string representation of the content 20.17 */ 20.18 + @Override 20.19 public String toString() { 20.20 - StringBuilder contentBuilder = new StringBuilder(); 20.21 - write(contentBuilder); 20.22 - return contentBuilder.toString(); 20.23 + StringWriter out = new StringWriter(); 20.24 + try { 20.25 + write(out, true); 20.26 + } catch (IOException e) { 20.27 + // cannot happen from StringWriter 20.28 + throw new DocletAbortException(); 20.29 + } 20.30 + return out.toString(); 20.31 } 20.32 20.33 /** 20.34 @@ -65,10 +75,10 @@ 20.35 public abstract void addContent(String stringContent); 20.36 20.37 /** 20.38 - * Writes content to a StringBuilder. 20.39 + * Writes content to a writer. 20.40 * 20.41 */ 20.42 - public abstract void write(StringBuilder contentBuilder); 20.43 + public abstract boolean write(Writer writer, boolean atNewline) throws IOException ; 20.44 20.45 /** 20.46 * Returns true if the content is empty.
21.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/PackageSummaryWriter.java Fri Oct 12 14:53:50 2012 -0700 21.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/PackageSummaryWriter.java Mon Oct 15 17:07:55 2012 -0700 21.3 @@ -115,7 +115,7 @@ 21.4 * 21.5 * @param contentTree the content tree that will be printed 21.6 */ 21.7 - public abstract void printDocument(Content contentTree); 21.8 + public abstract void printDocument(Content contentTree) throws IOException; 21.9 21.10 /** 21.11 * Close the writer.
22.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/SerializedFormWriter.java Fri Oct 12 14:53:50 2012 -0700 22.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/SerializedFormWriter.java Mon Oct 15 17:07:55 2012 -0700 22.3 @@ -151,7 +151,7 @@ 22.4 * 22.5 * @param serializedTree the content tree that will be printed 22.6 */ 22.7 - public abstract void printDocument(Content serializedTree); 22.8 + public abstract void printDocument(Content serializedTree) throws IOException; 22.9 22.10 /** 22.11 * Write the serialized form for a given field.
23.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Fri Oct 12 14:53:50 2012 -0700 23.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Mon Oct 15 17:07:55 2012 -0700 23.3 @@ -650,9 +650,9 @@ 23.4 fos = new FileOutputStream(filename); 23.5 } 23.6 if (docencoding == null) { 23.7 - return new OutputStreamWriter(fos); 23.8 + return new BufferedWriter(new OutputStreamWriter(fos)); 23.9 } else { 23.10 - return new OutputStreamWriter(fos, docencoding); 23.11 + return new BufferedWriter(new OutputStreamWriter(fos, docencoding)); 23.12 } 23.13 } 23.14