blob: e4375e536a5b44f5555dda50f8d2b8954435e6f9 [file] [log] [blame]
<HTML><HEAD><META CONTENT="text/html; charset=UTF-8" HTTP-EQUIV="Content-Type"/><TITLE>EMMA Coverage Report</TITLE><STYLE TYPE="text/css"> TABLE,TD,TH {border-style:solid; border-color:black;} TD,TH {background:white;margin:0;line-height:100%;padding-left:0.5em;padding-right:0.5em;} TD {border-width:0 1px 0 0;} TH {border-width:1px 1px 1px 0;} TR TD.h {color:red;} TABLE {border-spacing:0; border-collapse:collapse;border-width:0 0 1px 1px;} P,H1,H2,H3,TH {font-family:verdana,arial,sans-serif;font-size:10pt;} TD {font-family:courier,monospace;font-size:10pt;} TABLE.hdft {border-spacing:0;border-collapse:collapse;border-style:none;} TABLE.hdft TH,TABLE.hdft TD {border-style:none;line-height:normal;} TABLE.hdft TH.tl,TABLE.hdft TD.tl {background:#6699CC;color:white;} TABLE.hdft TD.nv {background:#6633DD;color:white;} .nv A:link {color:white;} .nv A:visited {color:white;} .nv A:active {color:yellow;} TABLE.hdft A:link {color:white;} TABLE.hdft A:visited {color:white;} TABLE.hdft A:active {color:yellow;} .in {color:#356085;} TABLE.s TD {padding-left:0.25em;padding-right:0.25em;} TABLE.s TD.l {padding-left:0.25em;padding-right:0.25em;text-align:right;background:#F0F0F0;} TABLE.s TR.z TD {background:#FF9999;} TABLE.s TR.p TD {background:#FFFF88;} TABLE.s TR.c TD {background:#CCFFCC;} A:link {color:#0000EE;text-decoration:none;} A:visited {color:#0000EE;text-decoration:none;} A:hover {color:#0000EE;text-decoration:underline;} TABLE.cn {border-width:0 0 1px 0;} TABLE.s {border-width:1px 0 1px 1px;} TD.h {color:red;border-width:0 1px 0 0;} TD.f {border-width:0 1px 0 1px;} TD.hf {color:red;border-width:0 1px 0 1px;} TH.f {border-width:1px 1px 1px 1px;} TR.cis TD {background:#F0F0F0;} TR.cis TD {border-width:1px 1px 1px 0;} TR.cis TD.h {color:red;border-width:1px 1px 1px 0;} TR.cis TD.f {border-width:1px 1px 1px 1px;} TR.cis TD.hf {color:red;border-width:1px 1px 1px 1px;} TD.b {border-style:none;background:transparent;line-height:50%;} TD.bt {border-width:1px 0 0 0;background:transparent;line-height:50%;} TR.o TD {background:#F0F0F0;}TABLE.it {border-style:none;}TABLE.it TD,TABLE.it TH {border-style:none;}</STYLE></HEAD><BODY><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="tl"><A HREF="http://www.eclemma.org/">EMMA</A> Coverage Report (generated Fri Feb 20 18:44:54 GMT 2009)</TH></TR><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="78.html">org.eclipse.wst.sse.core.internal.document</A>]</TD></TR></TABLE><H2>COVERAGE SUMMARY FOR SOURCE FILE [<SPAN CLASS="in">AbstractDocumentLoader.java</SPAN>]</H2><TABLE CELLSPACING="0" WIDTH="100%"><TR><TH>name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD>AbstractDocumentLoader.java</TD><TD>100% (1/1)</TD><TD CLASS="h">24%  (4/17)</TD><TD CLASS="h">11%  (65/567)</TD><TD CLASS="h">11%  (16.4/153)</TD></TR></TABLE><H3>COVERAGE BREAKDOWN BY CLASS AND METHOD</H3><TABLE CLASS="cn" CELLSPACING="0" WIDTH="100%"><TR><TH CLASS="f">name</TH><TH>class, %</TH><TH>method, %</TH><TH>block, %</TH><TH>line, %</TH></TR><TR><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD><TD CLASS="b"> </TD></TR><TR CLASS="cis"><TD CLASS="f">class <A HREF="#0">AbstractDocumentLoader</A></TD><TD>100% (1/1)</TD><TD CLASS="h">24%  (4/17)</TD><TD CLASS="h">11%  (65/567)</TD><TD CLASS="h">11%  (16.4/153)</TD></TR><TR><TD CLASS="f"><A HREF="#1">convertLineDelimiters (StringBuffer, String): StringBuffer</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/70)</TD><TD CLASS="h">0%   (0/17)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#2">createNewStructuredDocument (IFile): IEncodedDocument</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/52)</TD><TD CLASS="h">0%   (0/15)</TD></TR><TR><TD CLASS="f"><A HREF="#3">createNewStructuredDocument (String, InputStream): IEncodedDocument</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/6)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#4">createNewStructuredDocument (String, InputStream, EncodingRule): IEncodedDocu...</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/61)</TD><TD CLASS="h">0%   (0/17)</TD></TR><TR><TD CLASS="f"><A HREF="#5">getCharPostionOfFailure (BufferedReader): int</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/28)</TD><TD CLASS="h">0%   (0/13)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#6">getCodedReaderCreator (): CodedReaderCreator</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/11)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR><TD CLASS="f"><A HREF="#7">getEncodingMemento (): EncodingMemento</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/11)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#8">getFullPreparedReader (): Reader</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/11)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR><TD CLASS="f"><A HREF="#9">getPreferredNewLineDelimiter (): String</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/4)</TD><TD CLASS="h">0%   (0/1)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#a">handleLineDelimiter (StringBuffer, IEncodedDocument): StringBuffer</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/46)</TD><TD CLASS="h">0%   (0/13)</TD></TR><TR><TD CLASS="f"><A HREF="#b">readInputStream (Reader): StringBuffer</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/66)</TD><TD CLASS="h">0%   (0/14)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#c">reload (IEncodedDocument, Reader): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/96)</TD><TD CLASS="h">0%   (0/27)</TD></TR><TR><TD CLASS="f"><A HREF="#d">setDocumentContentsFromReader (IEncodedDocument, Reader): void</A></TD><TD> </TD><TD CLASS="h">0%   (0/1)</TD><TD CLASS="h">0%   (0/9)</TD><TD CLASS="h">0%   (0/3)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#e">getPlatformLineDelimiterPreference (IFile): String</A></TD><TD> </TD><TD>100% (1/1)</TD><TD CLASS="h">42%  (18/43)</TD><TD CLASS="h">34%  (2.4/7)</TD></TR><TR><TD CLASS="f"><A HREF="#f">createNewStructuredDocument (): IEncodedDocument</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>87%  (40/46)</TD><TD>85%  (11/13)</TD></TR><TR CLASS="o"><TD CLASS="f"><A HREF="#0">AbstractDocumentLoader (): void</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (3/3)</TD><TD>100% (2/2)</TD></TR><TR><TD CLASS="f"><A HREF="#11">getPreferredNewLineDelimiter (IFile): String</A></TD><TD> </TD><TD>100% (1/1)</TD><TD>100% (4/4)</TD><TD>100% (1/1)</TD></TR></TABLE><P></P><TABLE CLASS="s" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="l">1</TD><TD>/*******************************************************************************</TD></TR><TR><TD CLASS="l">2</TD><TD> * Copyright (c) 2001, 2006 IBM Corporation and others.</TD></TR><TR><TD CLASS="l">3</TD><TD> * All rights reserved. This program and the accompanying materials</TD></TR><TR><TD CLASS="l">4</TD><TD> * are made available under the terms of the Eclipse Public License v1.0</TD></TR><TR><TD CLASS="l">5</TD><TD> * which accompanies this distribution, and is available at</TD></TR><TR><TD CLASS="l">6</TD><TD> * http://www.eclipse.org/legal/epl-v10.html</TD></TR><TR><TD CLASS="l">7</TD><TD> *</TD></TR><TR><TD CLASS="l">8</TD><TD> * Contributors:</TD></TR><TR><TD CLASS="l">9</TD><TD> *     IBM Corporation - initial API and implementation</TD></TR><TR><TD CLASS="l">10</TD><TD> *     Jens Lukowski/Innoopract - initial renaming/restructuring</TD></TR><TR><TD CLASS="l">11</TD><TD> *     </TD></TR><TR><TD CLASS="l">12</TD><TD> *******************************************************************************/</TD></TR><TR><TD CLASS="l">13</TD><TD>package org.eclipse.wst.sse.core.internal.document;</TD></TR><TR><TD CLASS="l">14</TD><TD> </TD></TR><TR><TD CLASS="l">15</TD><TD>import java.io.BufferedReader;</TD></TR><TR><TD CLASS="l">16</TD><TD>import java.io.IOException;</TD></TR><TR><TD CLASS="l">17</TD><TD>import java.io.InputStream;</TD></TR><TR><TD CLASS="l">18</TD><TD>import java.io.Reader;</TD></TR><TR><TD CLASS="l">19</TD><TD>import java.io.UnsupportedEncodingException;</TD></TR><TR><TD CLASS="l">20</TD><TD>import java.nio.charset.MalformedInputException;</TD></TR><TR><TD CLASS="l">21</TD><TD>import java.nio.charset.UnmappableCharacterException;</TD></TR><TR><TD CLASS="l">22</TD><TD> </TD></TR><TR><TD CLASS="l">23</TD><TD>import org.eclipse.core.resources.IFile;</TD></TR><TR><TD CLASS="l">24</TD><TD>import org.eclipse.core.resources.ProjectScope;</TD></TR><TR><TD CLASS="l">25</TD><TD>import org.eclipse.core.runtime.CoreException;</TD></TR><TR><TD CLASS="l">26</TD><TD>import org.eclipse.core.runtime.Platform;</TD></TR><TR><TD CLASS="l">27</TD><TD>import org.eclipse.core.runtime.preferences.IScopeContext;</TD></TR><TR><TD CLASS="l">28</TD><TD>import org.eclipse.core.runtime.preferences.InstanceScope;</TD></TR><TR><TD CLASS="l">29</TD><TD>import org.eclipse.jface.text.Document;</TD></TR><TR><TD CLASS="l">30</TD><TD>import org.eclipse.jface.text.IDocument;</TD></TR><TR><TD CLASS="l">31</TD><TD>import org.eclipse.jface.text.IDocumentExtension3;</TD></TR><TR><TD CLASS="l">32</TD><TD>import org.eclipse.jface.text.IDocumentPartitioner;</TD></TR><TR><TD CLASS="l">33</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.CodedIO;</TD></TR><TR><TD CLASS="l">34</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator;</TD></TR><TR><TD CLASS="l">35</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences;</TD></TR><TR><TD CLASS="l">36</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;</TD></TR><TR><TD CLASS="l">37</TD><TD>import org.eclipse.wst.sse.core.internal.encoding.EncodingRule;</TD></TR><TR><TD CLASS="l">38</TD><TD>import org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail;</TD></TR><TR><TD CLASS="l">39</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument;</TD></TR><TR><TD CLASS="l">40</TD><TD>import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;</TD></TR><TR><TD CLASS="l">41</TD><TD> </TD></TR><TR><TD CLASS="l">42</TD><TD> </TD></TR><TR><TD CLASS="l">43</TD><TD> </TD></TR><TR><TD CLASS="l">44</TD><TD>/**</TD></TR><TR><TD CLASS="l">45</TD><TD> * This class reads a file and creates an Structured Model.</TD></TR><TR><TD CLASS="l">46</TD><TD> */</TD></TR><TR><TD CLASS="l">47</TD><TD>public abstract class AbstractDocumentLoader implements IDocumentLoader {</TD></TR><TR><TD CLASS="l">48</TD><TD> </TD></TR><TR><TD CLASS="l">49</TD><TD>        private CodedReaderCreator fCodedReaderCreator;</TD></TR><TR><TD CLASS="l">50</TD><TD>        protected IDocumentCharsetDetector fDocumentEncodingDetector;</TD></TR><TR><TD CLASS="l">51</TD><TD>        // private boolean fPropertiesObtained;</TD></TR><TR><TD CLASS="l">52</TD><TD> </TD></TR><TR><TD CLASS="l">53</TD><TD>        protected EncodingMemento fEncodingMemento;</TD></TR><TR><TD CLASS="l">54</TD><TD>        protected Reader fFullPreparedReader;</TD></TR><TR><TD CLASS="l">55</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="0">56</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">57</TD><TD>         * AbstractLoader constructor also initializes encoding converter/mapper</TD></TR><TR><TD CLASS="l">58</TD><TD>         */</TD></TR><TR><TD CLASS="l">59</TD><TD>        public AbstractDocumentLoader() {</TD></TR><TR CLASS="c"><TD CLASS="l">60</TD><TD>                super();</TD></TR><TR CLASS="c"><TD CLASS="l"><A NAME="1">61</A></TD><TD>        }</TD></TR><TR><TD CLASS="l">62</TD><TD> </TD></TR><TR><TD CLASS="l">63</TD><TD>        protected final StringBuffer convertLineDelimiters(StringBuffer allTextBuffer, String lineDelimiterToUse) {</TD></TR><TR><TD CLASS="l">64</TD><TD>                // TODO: avoid use of String instance</TD></TR><TR CLASS="z"><TD CLASS="l">65</TD><TD>                String allText = allTextBuffer.toString();</TD></TR><TR CLASS="z"><TD CLASS="l">66</TD><TD>                IDocument tempDoc = new Document(allText);</TD></TR><TR CLASS="z"><TD CLASS="l">67</TD><TD>                if (lineDelimiterToUse == null)</TD></TR><TR CLASS="z"><TD CLASS="l">68</TD><TD>                        lineDelimiterToUse = System.getProperty(&#34;line.separator&#34;); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">69</TD><TD>                StringBuffer newText = new StringBuffer();</TD></TR><TR CLASS="z"><TD CLASS="l">70</TD><TD>                int lineCount = tempDoc.getNumberOfLines();</TD></TR><TR CLASS="z"><TD CLASS="l">71</TD><TD>                for (int i = 0; i &lt; lineCount; i++) {</TD></TR><TR><TD CLASS="l">72</TD><TD>                        try {</TD></TR><TR CLASS="z"><TD CLASS="l">73</TD><TD>                                org.eclipse.jface.text.IRegion lineInfo = tempDoc.getLineInformation(i);</TD></TR><TR CLASS="z"><TD CLASS="l">74</TD><TD>                                int lineStartOffset = lineInfo.getOffset();</TD></TR><TR CLASS="z"><TD CLASS="l">75</TD><TD>                                int lineLength = lineInfo.getLength();</TD></TR><TR CLASS="z"><TD CLASS="l">76</TD><TD>                                int lineEndOffset = lineStartOffset + lineLength;</TD></TR><TR CLASS="z"><TD CLASS="l">77</TD><TD>                                newText.append(allText.substring(lineStartOffset, lineEndOffset));</TD></TR><TR CLASS="z"><TD CLASS="l">78</TD><TD>                                if ((i &lt; lineCount - 1) &amp;&amp; (tempDoc.getLineDelimiter(i) != null))</TD></TR><TR CLASS="z"><TD CLASS="l">79</TD><TD>                                        newText.append(lineDelimiterToUse);</TD></TR><TR><TD CLASS="l">80</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">81</TD><TD>                        catch (org.eclipse.jface.text.BadLocationException exception) {</TD></TR><TR><TD CLASS="l">82</TD><TD>                                // should fix up to either throw nothing, or the right thing,</TD></TR><TR><TD CLASS="l">83</TD><TD>                                // but</TD></TR><TR><TD CLASS="l">84</TD><TD>                                // in the course of refactoring, this was easiest &#34;quick fix&#34;.</TD></TR><TR CLASS="z"><TD CLASS="l">85</TD><TD>                                throw new RuntimeException(exception);</TD></TR><TR><TD CLASS="l">86</TD><TD>                        }</TD></TR><TR><TD CLASS="l">87</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">88</TD><TD>                return newText;</TD></TR><TR><TD CLASS="l">89</TD><TD>        }</TD></TR><TR><TD CLASS="l">90</TD><TD> </TD></TR><TR><TD CLASS="l">91</TD><TD>        /**</TD></TR><TR><TD CLASS="l">92</TD><TD>         * This method must return a new instance of IEncodedDocument, that has</TD></TR><TR><TD CLASS="l">93</TD><TD>         * been initialized with appropriate parser. For many loaders, the</TD></TR><TR><TD CLASS="l">94</TD><TD>         * (default) parser used is known for any input. For others, the correct</TD></TR><TR><TD CLASS="l">95</TD><TD>         * parser (and its initialization) is normally dependent on the content of</TD></TR><TR><TD CLASS="l"><A NAME="f">96</A></TD><TD>         * the file. This no-argument method should assume &#34;empty input&#34; and would</TD></TR><TR><TD CLASS="l">97</TD><TD>         * therefore return the default parser for the default contentType.</TD></TR><TR><TD CLASS="l">98</TD><TD>         */</TD></TR><TR><TD CLASS="l">99</TD><TD>        public IEncodedDocument createNewStructuredDocument() {</TD></TR><TR CLASS="c"><TD CLASS="l">100</TD><TD>                IEncodedDocument structuredDocument = newEncodedDocument();</TD></TR><TR><TD CLASS="l">101</TD><TD>                // Make sure every structuredDocument has an Encoding Memento,</TD></TR><TR><TD CLASS="l">102</TD><TD>                // which is the default one for &#34;empty&#34; structuredDocuments</TD></TR><TR CLASS="c"><TD CLASS="l">103</TD><TD>                String charset = ContentTypeEncodingPreferences.useDefaultNameRules(getDocumentEncodingDetector());</TD></TR><TR CLASS="c"><TD CLASS="l">104</TD><TD>                String specDefaultCharset = getDocumentEncodingDetector().getSpecDefaultEncoding();</TD></TR><TR CLASS="c"><TD CLASS="l">105</TD><TD>                structuredDocument.setEncodingMemento(CodedIO.createEncodingMemento(charset, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT, specDefaultCharset));</TD></TR><TR><TD CLASS="l">106</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">107</TD><TD>                String lineDelimiter = getPreferredNewLineDelimiter(null);</TD></TR><TR CLASS="c"><TD CLASS="l">108</TD><TD>                if (lineDelimiter != null)</TD></TR><TR CLASS="z"><TD CLASS="l">109</TD><TD>                        structuredDocument.setPreferredLineDelimiter(lineDelimiter);</TD></TR><TR><TD CLASS="l">110</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">111</TD><TD>                IDocumentPartitioner defaultPartitioner = getDefaultDocumentPartitioner();</TD></TR><TR CLASS="c"><TD CLASS="l">112</TD><TD>                if (structuredDocument instanceof IDocumentExtension3) {</TD></TR><TR CLASS="c"><TD CLASS="l">113</TD><TD>                        ((IDocumentExtension3) structuredDocument).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, defaultPartitioner);</TD></TR><TR><TD CLASS="l">114</TD><TD>                }</TD></TR><TR><TD CLASS="l">115</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">116</TD><TD>                        structuredDocument.setDocumentPartitioner(defaultPartitioner);</TD></TR><TR><TD CLASS="l">117</TD><TD>                }</TD></TR><TR CLASS="c"><TD CLASS="l">118</TD><TD>                defaultPartitioner.connect(structuredDocument);</TD></TR><TR><TD CLASS="l">119</TD><TD> </TD></TR><TR CLASS="c"><TD CLASS="l">120</TD><TD>                return structuredDocument;</TD></TR><TR><TD CLASS="l">121</TD><TD>        }</TD></TR><TR><TD CLASS="l">122</TD><TD> </TD></TR><TR><TD CLASS="l">123</TD><TD>        /**</TD></TR><TR><TD CLASS="l"><A NAME="2">124</A></TD><TD>         * This abstract version should handle most cases, but won't if</TD></TR><TR><TD CLASS="l">125</TD><TD>         * contentType is sensitive to encoding, and/or embedded types</TD></TR><TR><TD CLASS="l">126</TD><TD>         */</TD></TR><TR><TD CLASS="l">127</TD><TD>        public IEncodedDocument createNewStructuredDocument(IFile iFile) throws IOException, CoreException {</TD></TR><TR CLASS="z"><TD CLASS="l">128</TD><TD>                IEncodedDocument structuredDocument = createNewStructuredDocument();</TD></TR><TR><TD CLASS="l">129</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">130</TD><TD>                String lineDelimiter = getPreferredNewLineDelimiter(iFile);</TD></TR><TR CLASS="z"><TD CLASS="l">131</TD><TD>                if (lineDelimiter != null)</TD></TR><TR CLASS="z"><TD CLASS="l">132</TD><TD>                        structuredDocument.setPreferredLineDelimiter(lineDelimiter);</TD></TR><TR><TD CLASS="l">133</TD><TD> </TD></TR><TR><TD CLASS="l">134</TD><TD>                try {</TD></TR><TR><TD CLASS="l">135</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">136</TD><TD>                        CodedReaderCreator creator = getCodedReaderCreator();</TD></TR><TR CLASS="z"><TD CLASS="l">137</TD><TD>                        creator.set(iFile);</TD></TR><TR CLASS="z"><TD CLASS="l">138</TD><TD>                        fEncodingMemento = creator.getEncodingMemento();</TD></TR><TR CLASS="z"><TD CLASS="l">139</TD><TD>                        structuredDocument.setEncodingMemento(fEncodingMemento);</TD></TR><TR CLASS="z"><TD CLASS="l">140</TD><TD>                        fFullPreparedReader = getCodedReaderCreator().getCodedReader();</TD></TR><TR><TD CLASS="l">141</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">142</TD><TD>                        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);</TD></TR><TR><TD CLASS="l">143</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">144</TD><TD>                finally {</TD></TR><TR CLASS="z"><TD CLASS="l">145</TD><TD>                        if (fFullPreparedReader != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">146</TD><TD>                                fFullPreparedReader.close();</TD></TR><TR><TD CLASS="l">147</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">148</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="3">149</A></TD><TD>                return structuredDocument;</TD></TR><TR><TD CLASS="l">150</TD><TD>        }</TD></TR><TR><TD CLASS="l">151</TD><TD> </TD></TR><TR><TD CLASS="l">152</TD><TD>        public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException {</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="4">153</A></TD><TD>                return createNewStructuredDocument(filename, inputStream, EncodingRule.CONTENT_BASED);</TD></TR><TR><TD CLASS="l">154</TD><TD>        }</TD></TR><TR><TD CLASS="l">155</TD><TD> </TD></TR><TR><TD CLASS="l">156</TD><TD>        public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream, EncodingRule encodingRule) throws UnsupportedEncodingException, IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">157</TD><TD>                if (filename == null &amp;&amp; inputStream == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">158</TD><TD>                        throw new IllegalArgumentException(&#34;can not have both null filename and inputstream&#34;); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">159</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">160</TD><TD>                IEncodedDocument structuredDocument = createNewStructuredDocument();</TD></TR><TR CLASS="z"><TD CLASS="l">161</TD><TD>                CodedReaderCreator codedReaderCreator = getCodedReaderCreator();</TD></TR><TR><TD CLASS="l">162</TD><TD>                try {</TD></TR><TR CLASS="z"><TD CLASS="l">163</TD><TD>                        codedReaderCreator.set(filename, inputStream);</TD></TR><TR CLASS="z"><TD CLASS="l">164</TD><TD>                        codedReaderCreator.setEncodingRule(encodingRule);</TD></TR><TR CLASS="z"><TD CLASS="l">165</TD><TD>                        fEncodingMemento = codedReaderCreator.getEncodingMemento();</TD></TR><TR CLASS="z"><TD CLASS="l">166</TD><TD>                        fFullPreparedReader = codedReaderCreator.getCodedReader();</TD></TR><TR CLASS="z"><TD CLASS="l">167</TD><TD>                        structuredDocument.setEncodingMemento(fEncodingMemento);</TD></TR><TR CLASS="z"><TD CLASS="l">168</TD><TD>                        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);</TD></TR><TR><TD CLASS="l">169</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">170</TD><TD>                catch (CoreException e) {</TD></TR><TR><TD CLASS="l">171</TD><TD>                        // impossible in this context</TD></TR><TR CLASS="z"><TD CLASS="l">172</TD><TD>                        throw new Error(e);</TD></TR><TR><TD CLASS="l">173</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">174</TD><TD>                finally {</TD></TR><TR CLASS="z"><TD CLASS="l">175</TD><TD>                        if (fFullPreparedReader != null) {</TD></TR><TR CLASS="z"><TD CLASS="l">176</TD><TD>                                fFullPreparedReader.close();</TD></TR><TR><TD CLASS="l">177</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">178</TD><TD>                }</TD></TR><TR><TD CLASS="l">179</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="5">180</A></TD><TD>                return structuredDocument;</TD></TR><TR><TD CLASS="l">181</TD><TD>        }</TD></TR><TR><TD CLASS="l">182</TD><TD> </TD></TR><TR><TD CLASS="l">183</TD><TD>        private int getCharPostionOfFailure(BufferedReader inputStream) {</TD></TR><TR CLASS="z"><TD CLASS="l">184</TD><TD>                int charPosition = 1;</TD></TR><TR CLASS="z"><TD CLASS="l">185</TD><TD>                int charRead = -1;</TD></TR><TR CLASS="z"><TD CLASS="l">186</TD><TD>                boolean errorFound = false;</TD></TR><TR CLASS="z"><TD CLASS="l">187</TD><TD>                do {</TD></TR><TR><TD CLASS="l">188</TD><TD>                        try {</TD></TR><TR CLASS="z"><TD CLASS="l">189</TD><TD>                                charRead = inputStream.read();</TD></TR><TR CLASS="z"><TD CLASS="l">190</TD><TD>                                charPosition++;</TD></TR><TR><TD CLASS="l">191</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">192</TD><TD>                        catch (IOException e) {</TD></TR><TR><TD CLASS="l">193</TD><TD>                                // this is expected, since we're expecting failure,</TD></TR><TR><TD CLASS="l">194</TD><TD>                                // so no need to do anything.</TD></TR><TR CLASS="z"><TD CLASS="l">195</TD><TD>                                errorFound = true;</TD></TR><TR CLASS="z"><TD CLASS="l">196</TD><TD>                                break;</TD></TR><TR><TD CLASS="l">197</TD><TD>                        }</TD></TR><TR><TD CLASS="l">198</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">199</TD><TD>                while (!(charRead == -1 || errorFound));</TD></TR><TR><TD CLASS="l">200</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">201</TD><TD>                if (errorFound)</TD></TR><TR><TD CLASS="l">202</TD><TD>                        // dmw, blindly modified to +1 to get unit tests to work, moving</TD></TR><TR><TD CLASS="l">203</TD><TD>                        // from Java 1.3, to 1.4</TD></TR><TR><TD CLASS="l">204</TD><TD>                        // not sure how/why this behavior would have changed. (Its as if</TD></TR><TR><TD CLASS="l">205</TD><TD>                        // 'read' is reporting error</TD></TR><TR><TD CLASS="l">206</TD><TD>                        // one character early).</TD></TR><TR CLASS="z"><TD CLASS="l">207</TD><TD>                        return charPosition + 1;</TD></TR><TR><TD CLASS="l">208</TD><TD>                else</TD></TR><TR CLASS="z"><TD CLASS="l">209</TD><TD>                        return -1;</TD></TR><TR><TD CLASS="l">210</TD><TD>        }</TD></TR><TR><TD CLASS="l">211</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="6">212</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">213</TD><TD>         * @return Returns the codedReaderCreator.</TD></TR><TR><TD CLASS="l">214</TD><TD>         */</TD></TR><TR><TD CLASS="l">215</TD><TD>        protected CodedReaderCreator getCodedReaderCreator() {</TD></TR><TR CLASS="z"><TD CLASS="l">216</TD><TD>                if (fCodedReaderCreator == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">217</TD><TD>                        fCodedReaderCreator = new CodedReaderCreator();</TD></TR><TR><TD CLASS="l">218</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">219</TD><TD>                return fCodedReaderCreator;</TD></TR><TR><TD CLASS="l">220</TD><TD>        }</TD></TR><TR><TD CLASS="l">221</TD><TD> </TD></TR><TR><TD CLASS="l">222</TD><TD>        /**</TD></TR><TR><TD CLASS="l">223</TD><TD>         * Creates the partitioner to be used with the</TD></TR><TR><TD CLASS="l">224</TD><TD>         * IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING partitioning</TD></TR><TR><TD CLASS="l">225</TD><TD>         * </TD></TR><TR><TD CLASS="l">226</TD><TD>         * @return IDocumentPartitioner</TD></TR><TR><TD CLASS="l">227</TD><TD>         */</TD></TR><TR><TD CLASS="l">228</TD><TD>        public abstract IDocumentPartitioner getDefaultDocumentPartitioner();</TD></TR><TR><TD CLASS="l">229</TD><TD> </TD></TR><TR><TD CLASS="l">230</TD><TD>        /**</TD></TR><TR><TD CLASS="l">231</TD><TD>         * Returns the encodingMemento.</TD></TR><TR><TD CLASS="l"><A NAME="7">232</A></TD><TD>         * </TD></TR><TR><TD CLASS="l">233</TD><TD>         * @return EncodingMemento</TD></TR><TR><TD CLASS="l">234</TD><TD>         */</TD></TR><TR><TD CLASS="l">235</TD><TD>        public EncodingMemento getEncodingMemento() {</TD></TR><TR CLASS="z"><TD CLASS="l">236</TD><TD>                if (fEncodingMemento == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">237</TD><TD>                        throw new IllegalStateException(&#34;Program Error: encodingMemento was accessed before it was set&#34;); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">238</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">239</TD><TD>                return fEncodingMemento;</TD></TR><TR><TD CLASS="l">240</TD><TD>        }</TD></TR><TR><TD CLASS="l">241</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="8">242</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">243</TD><TD>         * @return Returns the fullPreparedReader.</TD></TR><TR><TD CLASS="l">244</TD><TD>         */</TD></TR><TR><TD CLASS="l">245</TD><TD>        protected Reader getFullPreparedReader() throws UnsupportedEncodingException, CoreException, IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">246</TD><TD>                if (fFullPreparedReader == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">247</TD><TD>                        fFullPreparedReader = getCodedReaderCreator().getCodedReader();</TD></TR><TR><TD CLASS="l">248</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">249</TD><TD>                return fFullPreparedReader;</TD></TR><TR><TD CLASS="l">250</TD><TD>        }</TD></TR><TR><TD CLASS="l">251</TD><TD> </TD></TR><TR><TD CLASS="l">252</TD><TD>        /**</TD></TR><TR><TD CLASS="l">253</TD><TD>         * Returns the default line delimiter preference for the given file.</TD></TR><TR><TD CLASS="l">254</TD><TD>         * </TD></TR><TR><TD CLASS="l">255</TD><TD>         * @param file</TD></TR><TR><TD CLASS="l">256</TD><TD>         *            the file</TD></TR><TR><TD CLASS="l">257</TD><TD>         * @return the default line delimiter</TD></TR><TR><TD CLASS="l"><A NAME="e">258</A></TD><TD>         * @since 3.1</TD></TR><TR><TD CLASS="l">259</TD><TD>         */</TD></TR><TR><TD CLASS="l">260</TD><TD>        private String getPlatformLineDelimiterPreference(IFile file) {</TD></TR><TR><TD CLASS="l">261</TD><TD>                IScopeContext[] scopeContext;</TD></TR><TR CLASS="p"><TD CLASS="l" TITLE="40% line coverage (2 out of 5 instructions)">262</TD><TD TITLE="40% line coverage (2 out of 5 instructions)">                if (file != null &amp;&amp; file.getProject() != null) {</TD></TR><TR><TD CLASS="l">263</TD><TD>                        // project preference</TD></TR><TR CLASS="z"><TD CLASS="l">264</TD><TD>                        scopeContext = new IScopeContext[]{new ProjectScope(file.getProject())};</TD></TR><TR CLASS="z"><TD CLASS="l">265</TD><TD>                        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);</TD></TR><TR CLASS="z"><TD CLASS="l">266</TD><TD>                        if (lineDelimiter != null)</TD></TR><TR CLASS="z"><TD CLASS="l">267</TD><TD>                                return lineDelimiter;</TD></TR><TR><TD CLASS="l">268</TD><TD>                }</TD></TR><TR><TD CLASS="l">269</TD><TD>                // workspace preference</TD></TR><TR CLASS="c"><TD CLASS="l">270</TD><TD>                scopeContext = new IScopeContext[]{new InstanceScope()};</TD></TR><TR CLASS="c"><TD CLASS="l">271</TD><TD>                return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);</TD></TR><TR><TD CLASS="l">272</TD><TD>        }</TD></TR><TR><TD CLASS="l">273</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="9">274</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">275</TD><TD>         * @deprecated use getPreferredNewLineDelimiter(IFile) instead</TD></TR><TR><TD CLASS="l">276</TD><TD>         */</TD></TR><TR><TD CLASS="l">277</TD><TD>        protected String getPreferredNewLineDelimiter() {</TD></TR><TR CLASS="z"><TD CLASS="l">278</TD><TD>                return getPreferredNewLineDelimiter(null);</TD></TR><TR><TD CLASS="l">279</TD><TD>        }</TD></TR><TR><TD CLASS="l">280</TD><TD> </TD></TR><TR><TD CLASS="l"><A NAME="11">281</A></TD><TD>        /**</TD></TR><TR><TD CLASS="l">282</TD><TD>         * If subclass doesn't implement, return platform default</TD></TR><TR><TD CLASS="l">283</TD><TD>         */</TD></TR><TR><TD CLASS="l">284</TD><TD>        protected String getPreferredNewLineDelimiter(IFile file) {</TD></TR><TR CLASS="c"><TD CLASS="l">285</TD><TD>                return getPlatformLineDelimiterPreference(file);</TD></TR><TR><TD CLASS="l">286</TD><TD>        }</TD></TR><TR><TD CLASS="l">287</TD><TD> </TD></TR><TR><TD CLASS="l">288</TD><TD>        /**</TD></TR><TR><TD CLASS="l">289</TD><TD>         * A utility method, but depends on subclasses to impliment the preferred</TD></TR><TR><TD CLASS="l">290</TD><TD>         * end of line for a particular content type. Note: subclasses should not</TD></TR><TR><TD CLASS="l">291</TD><TD>         * re-implement this method (there's no reason to, even though its part of</TD></TR><TR><TD CLASS="l">292</TD><TD>         * interface). This method not only converts end-of-line characters, if</TD></TR><TR><TD CLASS="l">293</TD><TD>         * needed, but sets the correct end-of-line delimiter in</TD></TR><TR><TD CLASS="l">294</TD><TD>         * structuredDocument. Minor note: can't use this exact method in dumpers,</TD></TR><TR><TD CLASS="l">295</TD><TD>         * since the decision to change or not is a little different, and since</TD></TR><TR><TD CLASS="l">296</TD><TD>         * there we have to change text of structuredDocument if found to need</TD></TR><TR><TD CLASS="l">297</TD><TD>         * conversion. (Where as for loading, we assume we haven't yet set text in</TD></TR><TR><TD CLASS="l">298</TD><TD>         * structuredDocument, but will be done by other method just a tiny biy</TD></TR><TR><TD CLASS="l">299</TD><TD>         * later). Needs to be public to handle interface. It is in the interface</TD></TR><TR><TD CLASS="l">300</TD><TD>         * just so ModelManagerImpl can use it in a special circumstance.</TD></TR><TR><TD CLASS="l"><A NAME="a">301</A></TD><TD>         */</TD></TR><TR><TD CLASS="l">302</TD><TD>        public StringBuffer handleLineDelimiter(StringBuffer originalString, IEncodedDocument theFlatModel) {</TD></TR><TR><TD CLASS="l">303</TD><TD>                // TODO: need to handle line delimiters so Marker Positions are</TD></TR><TR><TD CLASS="l">304</TD><TD>                // updated</TD></TR><TR CLASS="z"><TD CLASS="l">305</TD><TD>                StringBuffer convertedText = null;</TD></TR><TR><TD CLASS="l">306</TD><TD>                // based on text, make a guess on what's being used as</TD></TR><TR><TD CLASS="l">307</TD><TD>                // line delimiter</TD></TR><TR CLASS="z"><TD CLASS="l">308</TD><TD>                String probableLineDelimiter = TextUtilities.determineLineDelimiter(originalString, theFlatModel.getLegalLineDelimiters(), System.getProperty(&#34;line.separator&#34;)); //$NON-NLS-1$</TD></TR><TR CLASS="z"><TD CLASS="l">309</TD><TD>                String preferredLineDelimiter = getPreferredNewLineDelimiter(null);</TD></TR><TR CLASS="z"><TD CLASS="l">310</TD><TD>                if (preferredLineDelimiter == null) {</TD></TR><TR><TD CLASS="l">311</TD><TD>                        // when preferredLineDelimiter is null, it means &#34;leave alone&#34;</TD></TR><TR><TD CLASS="l">312</TD><TD>                        // so no conversion needed.</TD></TR><TR><TD CLASS="l">313</TD><TD>                        // set here, only if null (should already be set, but if not,</TD></TR><TR><TD CLASS="l">314</TD><TD>                        // we'll set so any subsequent editing inserts what we're</TD></TR><TR><TD CLASS="l">315</TD><TD>                        // assuming)</TD></TR><TR CLASS="z"><TD CLASS="l">316</TD><TD>                        if (!theFlatModel.getPreferredLineDelimiter().equals(probableLineDelimiter)) {</TD></TR><TR CLASS="z"><TD CLASS="l">317</TD><TD>                                theFlatModel.setPreferredLineDelimiter(probableLineDelimiter);</TD></TR><TR><TD CLASS="l">318</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">319</TD><TD>                        convertedText = originalString;</TD></TR><TR><TD CLASS="l">320</TD><TD>                }</TD></TR><TR><TD CLASS="l">321</TD><TD>                else {</TD></TR><TR CLASS="z"><TD CLASS="l">322</TD><TD>                        if (!preferredLineDelimiter.equals(probableLineDelimiter)) {</TD></TR><TR><TD CLASS="l">323</TD><TD>                                // technically, wouldn't have to convert line delimiters</TD></TR><TR><TD CLASS="l">324</TD><TD>                                // here at beginning, but when we save, if the preferred</TD></TR><TR><TD CLASS="l">325</TD><TD>                                // line delimter is &#34;leave alone&#34; then we do leave alone,</TD></TR><TR><TD CLASS="l">326</TD><TD>                                // so best to be right from beginning.</TD></TR><TR CLASS="z"><TD CLASS="l">327</TD><TD>                                convertedText = convertLineDelimiters(originalString, preferredLineDelimiter);</TD></TR><TR CLASS="z"><TD CLASS="l">328</TD><TD>                                theFlatModel.setPreferredLineDelimiter(preferredLineDelimiter);</TD></TR><TR><TD CLASS="l">329</TD><TD>                        }</TD></TR><TR><TD CLASS="l">330</TD><TD>                        else {</TD></TR><TR><TD CLASS="l">331</TD><TD>                                // they are already the same, no conversion needed</TD></TR><TR CLASS="z"><TD CLASS="l">332</TD><TD>                                theFlatModel.setPreferredLineDelimiter(preferredLineDelimiter);</TD></TR><TR CLASS="z"><TD CLASS="l">333</TD><TD>                                convertedText = originalString;</TD></TR><TR><TD CLASS="l">334</TD><TD>                        }</TD></TR><TR><TD CLASS="l">335</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">336</TD><TD>                return convertedText;</TD></TR><TR><TD CLASS="l">337</TD><TD>        }</TD></TR><TR><TD CLASS="l">338</TD><TD> </TD></TR><TR><TD CLASS="l">339</TD><TD>        protected abstract IEncodedDocument newEncodedDocument();</TD></TR><TR><TD CLASS="l">340</TD><TD> </TD></TR><TR><TD CLASS="l">341</TD><TD>        /**</TD></TR><TR><TD CLASS="l">342</TD><TD>         * Very mechanical method, just to read the characters, once the reader is</TD></TR><TR><TD CLASS="l"><A NAME="b">343</A></TD><TD>         * correctly created. Can throw MalFormedInputException.</TD></TR><TR><TD CLASS="l">344</TD><TD>         */</TD></TR><TR><TD CLASS="l">345</TD><TD>        private StringBuffer readInputStream(Reader reader) throws IOException {</TD></TR><TR><TD CLASS="l">346</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">347</TD><TD>                int fBlocksRead = 0;</TD></TR><TR CLASS="z"><TD CLASS="l">348</TD><TD>                StringBuffer buffer = new StringBuffer();</TD></TR><TR CLASS="z"><TD CLASS="l">349</TD><TD>                int numRead = 0;</TD></TR><TR><TD CLASS="l">350</TD><TD>                try {</TD></TR><TR CLASS="z"><TD CLASS="l">351</TD><TD>                        char tBuff[] = new char[CodedIO.MAX_BUF_SIZE];</TD></TR><TR CLASS="z"><TD CLASS="l">352</TD><TD>                        while (numRead != -1) {</TD></TR><TR CLASS="z"><TD CLASS="l">353</TD><TD>                                numRead = reader.read(tBuff, 0, tBuff.length);</TD></TR><TR CLASS="z"><TD CLASS="l">354</TD><TD>                                if (numRead &gt; 0) {</TD></TR><TR CLASS="z"><TD CLASS="l">355</TD><TD>                                        buffer.append(tBuff, 0, numRead);</TD></TR><TR CLASS="z"><TD CLASS="l">356</TD><TD>                                        fBlocksRead++;</TD></TR><TR><TD CLASS="l">357</TD><TD>                                }</TD></TR><TR><TD CLASS="l">358</TD><TD>                        }</TD></TR><TR><TD CLASS="l">359</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">360</TD><TD>                catch (MalformedInputException e) {</TD></TR><TR CLASS="z"><TD CLASS="l">361</TD><TD>                        throw new MalformedInputExceptionWithDetail(fEncodingMemento.getJavaCharsetName(), fBlocksRead * CodedIO.MAX_BUF_SIZE + numRead + e.getInputLength());</TD></TR><TR><TD CLASS="l">362</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">363</TD><TD>                catch (UnmappableCharacterException e) {</TD></TR><TR CLASS="z"><TD CLASS="l">364</TD><TD>                        throw new MalformedInputExceptionWithDetail(fEncodingMemento.getJavaCharsetName(), fBlocksRead * CodedIO.MAX_BUF_SIZE + numRead + e.getInputLength());</TD></TR><TR><TD CLASS="l">365</TD><TD> </TD></TR><TR><TD CLASS="l">366</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="c">367</A></TD><TD>                return buffer;</TD></TR><TR><TD CLASS="l">368</TD><TD>        }</TD></TR><TR><TD CLASS="l">369</TD><TD> </TD></TR><TR><TD CLASS="l">370</TD><TD>        public void reload(IEncodedDocument encodedDocument, Reader inputStreamReader) throws IOException {</TD></TR><TR CLASS="z"><TD CLASS="l">371</TD><TD>                if (inputStreamReader == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">372</TD><TD>                        throw new IllegalArgumentException(&#34;stream reader can not be null&#34;); //$NON-NLS-1$</TD></TR><TR><TD CLASS="l">373</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">374</TD><TD>                int READ_BUFFER_SIZE = 8192;</TD></TR><TR CLASS="z"><TD CLASS="l">375</TD><TD>                int MAX_BUFFERED_SIZE_FOR_RESET_MARK = 200000;</TD></TR><TR><TD CLASS="l">376</TD><TD>                // temp .... eventually we'lll only read as needed</TD></TR><TR CLASS="z"><TD CLASS="l">377</TD><TD>                BufferedReader bufferedReader = new BufferedReader(inputStreamReader, MAX_BUFFERED_SIZE_FOR_RESET_MARK);</TD></TR><TR CLASS="z"><TD CLASS="l">378</TD><TD>                bufferedReader.mark(MAX_BUFFERED_SIZE_FOR_RESET_MARK);</TD></TR><TR CLASS="z"><TD CLASS="l">379</TD><TD>                StringBuffer buffer = new StringBuffer();</TD></TR><TR><TD CLASS="l">380</TD><TD>                try {</TD></TR><TR CLASS="z"><TD CLASS="l">381</TD><TD>                        int numRead = 0;</TD></TR><TR CLASS="z"><TD CLASS="l">382</TD><TD>                        char tBuff[] = new char[READ_BUFFER_SIZE];</TD></TR><TR CLASS="z"><TD CLASS="l">383</TD><TD>                        while ((numRead = bufferedReader.read(tBuff, 0, tBuff.length)) != -1) {</TD></TR><TR CLASS="z"><TD CLASS="l">384</TD><TD>                                buffer.append(tBuff, 0, numRead);</TD></TR><TR><TD CLASS="l">385</TD><TD>                        }</TD></TR><TR><TD CLASS="l">386</TD><TD>                        // remember -- we didn't open stream ... so we don't close it</TD></TR><TR><TD CLASS="l">387</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">388</TD><TD>                catch (MalformedInputException e) {</TD></TR><TR><TD CLASS="l">389</TD><TD>                        // int pos = e.getInputLength();</TD></TR><TR CLASS="z"><TD CLASS="l">390</TD><TD>                        EncodingMemento localEncodingMemento = getEncodingMemento();</TD></TR><TR CLASS="z"><TD CLASS="l">391</TD><TD>                        boolean couldReset = true;</TD></TR><TR CLASS="z"><TD CLASS="l">392</TD><TD>                        String encodingNameInError = localEncodingMemento.getJavaCharsetName();</TD></TR><TR CLASS="z"><TD CLASS="l">393</TD><TD>                        if (encodingNameInError == null) {</TD></TR><TR CLASS="z"><TD CLASS="l">394</TD><TD>                                encodingNameInError = localEncodingMemento.getDetectedCharsetName();</TD></TR><TR><TD CLASS="l">395</TD><TD>                        }</TD></TR><TR><TD CLASS="l">396</TD><TD>                        try {</TD></TR><TR CLASS="z"><TD CLASS="l">397</TD><TD>                                bufferedReader.reset();</TD></TR><TR><TD CLASS="l">398</TD><TD>                        }</TD></TR><TR CLASS="z"><TD CLASS="l">399</TD><TD>                        catch (IOException resetException) {</TD></TR><TR><TD CLASS="l">400</TD><TD>                                // the only errro that can occur during reset is an</TD></TR><TR><TD CLASS="l">401</TD><TD>                                // IOException</TD></TR><TR><TD CLASS="l">402</TD><TD>                                // due to already being past the rest mark. In that case, we</TD></TR><TR><TD CLASS="l">403</TD><TD>                                // throw more generic message</TD></TR><TR CLASS="z"><TD CLASS="l">404</TD><TD>                                couldReset = false;</TD></TR><TR><TD CLASS="l">405</TD><TD>                        }</TD></TR><TR><TD CLASS="l">406</TD><TD>                        // -1 can be used by UI layer as a code that &#34;position could not</TD></TR><TR><TD CLASS="l">407</TD><TD>                        // be</TD></TR><TR><TD CLASS="l">408</TD><TD>                        // determined&#34;</TD></TR><TR CLASS="z"><TD CLASS="l">409</TD><TD>                        int charPostion = -1;</TD></TR><TR CLASS="z"><TD CLASS="l">410</TD><TD>                        if (couldReset) {</TD></TR><TR><TD CLASS="l">411</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">412</TD><TD>                                charPostion = getCharPostionOfFailure(bufferedReader);</TD></TR><TR><TD CLASS="l">413</TD><TD>                                // getCharPostionOfFailure(new InputStreamReader(inStream,</TD></TR><TR><TD CLASS="l">414</TD><TD>                                // javaEncodingNameInError));</TD></TR><TR><TD CLASS="l">415</TD><TD>                        }</TD></TR><TR><TD CLASS="l">416</TD><TD>                        // all of that just to throw more accurate error</TD></TR><TR><TD CLASS="l">417</TD><TD>                        // note: we do the conversion to ianaName, instead of using the</TD></TR><TR><TD CLASS="l">418</TD><TD>                        // local</TD></TR><TR><TD CLASS="l">419</TD><TD>                        // variable,</TD></TR><TR><TD CLASS="l">420</TD><TD>                        // because this is ultimately only for the user error message</TD></TR><TR><TD CLASS="l">421</TD><TD>                        // (that</TD></TR><TR><TD CLASS="l">422</TD><TD>                        // is,</TD></TR><TR><TD CLASS="l">423</TD><TD>                        // the error occurred</TD></TR><TR><TD CLASS="l">424</TD><TD>                        // in context of javaEncodingName no matter what ianaEncodingName</TD></TR><TR><TD CLASS="l">425</TD><TD>                        // is</TD></TR><TR CLASS="z"><TD CLASS="l">426</TD><TD>                        throw new MalformedInputExceptionWithDetail(encodingNameInError, CodedIO.getAppropriateJavaCharset(encodingNameInError), charPostion, !couldReset, MAX_BUFFERED_SIZE_FOR_RESET_MARK);</TD></TR><TR><TD CLASS="l">427</TD><TD>                }</TD></TR><TR CLASS="z"><TD CLASS="l">428</TD><TD>                StringBuffer stringbuffer = buffer;</TD></TR><TR CLASS="z"><TD CLASS="l">429</TD><TD>                encodedDocument.set(stringbuffer.toString());</TD></TR><TR><TD CLASS="l">430</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l"><A NAME="d">431</A></TD><TD>        }</TD></TR><TR><TD CLASS="l">432</TD><TD> </TD></TR><TR><TD CLASS="l">433</TD><TD>        protected void setDocumentContentsFromReader(IEncodedDocument structuredDocument, Reader reader) throws IOException {</TD></TR><TR><TD CLASS="l">434</TD><TD> </TD></TR><TR CLASS="z"><TD CLASS="l">435</TD><TD>                StringBuffer allText = readInputStream(reader);</TD></TR><TR CLASS="z"><TD CLASS="l">436</TD><TD>                structuredDocument.set(allText.toString());</TD></TR><TR CLASS="z"><TD CLASS="l">437</TD><TD>        }</TD></TR><TR><TD CLASS="l">438</TD><TD>}</TD></TR></TABLE><P></P><TABLE CLASS="hdft" CELLSPACING="0" WIDTH="100%"><TR><TD CLASS="nv">[<A HREF="../xslUnitTestCoverage.html">all classes</A>][<A HREF="78.html">org.eclipse.wst.sse.core.internal.document</A>]</TD></TR><TR><TD CLASS="tl"><A HREF="http://www.eclemma.org/support.html">EMMA 2.0.5312 EclEmma Fix 1</A> (C) Vladimir Roubtsov</TD></TR></TABLE></BODY></HTML>