<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.3</li>
<li>Operating System version: macOs</li>
<li>Java version: JDK 1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">We are going to serialize direct to Hessian OutputStream for protobuf extension, and read directly from InputStream. The change is going to export the Hessian InputStream &amp; OutputStream for direct write.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="private final Hessian2ObjectOutput delegate;

protected ProtobufObjectOutput(OutputStream os) {
  this.delegate = new Hessian2ObjectOutput(os);
}

void writeBytesForPBObject(Object obj, Class clazz) throws IOException {
  try (OutputStream os = delegate.getOutputStream()) {
    if (obj instanceof MessageLite) {
      try {
        ((MessageLite) obj).writeTo(os);
      } catch (IOException e) {
        throw new RuntimeException(&quot;Google PB序列化失败，序列化对象的类型为&quot; + obj.getClass().getName(), e);
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">private final Hessian2ObjectOutput delegate;

protected ProtobufObjectOutput(OutputStream os) {
  this.delegate = new Hessian2ObjectOutput(os);
}

void writeBytesForPBObject(Object obj, Class clazz) throws IOException {
  try (OutputStream os = delegate.getOutputStream()) {
    if (obj instanceof MessageLite) {
      try {
        ((MessageLite) obj).writeTo(os);
      } catch (IOException e) {
        throw new RuntimeException("Google PB序列化失败，序列化对象的类型为" + obj.getClass().getName(), e);
      }
    }
  }
}
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.5</li>
<li>Operating System version: Windows 10 1903</li>
<li>Java version: 1.8.0_221</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>in root folder execute "mvn clean test"</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">pass unit test</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">org.opentest4j.AssertionFailedError: expected:  but was: <br>
at org.apache.dubbo.common.extension.AdaptiveClassCodeGeneratorTest.testGenerate(AdaptiveClassCodeGeneratorTest.java:45)</p>
<h3 dir="auto">Any try</h3>
<p dir="auto">the souce of  is AdaptiveClassCodeGeneratorTest</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class AdaptiveClassCodeGeneratorTest {

    @Test
    public void testGenerate() throws IOException {
        AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, &quot;adaptive&quot;);
        String value = generator.generate();
        URL url = getClass().getResource(&quot;/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive&quot;);
        try (InputStream inputStream = url.openStream()) {
            String content = IOUtils.read(new InputStreamReader(inputStream, &quot;UTF-8&quot;));
            assertTrue(content.contains(value));
        }
    }
}"><pre class="notranslate"><code class="notranslate">public class AdaptiveClassCodeGeneratorTest {

    @Test
    public void testGenerate() throws IOException {
        AdaptiveClassCodeGenerator generator = new AdaptiveClassCodeGenerator(HasAdaptiveExt.class, "adaptive");
        String value = generator.generate();
        URL url = getClass().getResource("/org/apache/dubbo/common/extension/adaptive/HasAdaptiveExt$Adaptive");
        try (InputStream inputStream = url.openStream()) {
            String content = IOUtils.read(new InputStreamReader(inputStream, "UTF-8"));
            assertTrue(content.contains(value));
        }
    }
}
</code></pre></div>
<p dir="auto">When I add the following code to it, the unit pass.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            value = value.replace(&quot;\r&quot;,&quot;&quot;);
            value = value.replace(&quot;\n&quot;,&quot;&quot;);
            content = content.replace(&quot;\r&quot;,&quot;&quot;);
            content = content.replace(&quot;\n&quot;,&quot;&quot;);"><pre class="notranslate"><code class="notranslate">            value = value.replace("\r","");
            value = value.replace("\n","");
            content = content.replace("\r","");
            content = content.replace("\n","");
</code></pre></div>