title: Java class.getResourceAsStream() returns incorrect byte
body: <p>I have just run into a very strange problem with getResourceAsStream().</p>
  
  <p>In my prod project JUnit test I read test data using getResourceAsStream(), I found that getResourceAsStream() sometimes substitutes some bytes:</p>
  
  <pre><code>byte[] fileBytes = FileUtils.readFileToByteArray(new File(
      "resources/test/parser/test-short-enc.xml"));
  
  printBytes(fileBytes);
  
  byte[] classPathBytes = IOUtils.toByteArray(ParserTest.class
      .getResourceAsStream("/test/parser/test-short-enc.xml"))
  
  printBytes(classPathBytes);
  </code></pre>
  
  <p>In this project output looks like this:</p>
  
  <p>D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 <strong>D1 81</strong> D1 82 D0 B8 D0 BA D0 B0</p>
  
  <p>D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 <strong>D1 3F</strong> D1 82 D0 B8 D0 BA D0 B0</p>
  
  <p>After this, I decided to create a small bug-showing project and host it at Github as an example. Here's the link: <a href="https://github.com/snowindy/getResourceAsStream-Bug" rel="nofollow">https://github.com/snowindy/getResourceAsStream-Bug</a></p>
  
  <p>I essentially copied the code needed, after run, I could not see the problem reproducing:</p>
  
  <p>D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 <strong>D1 81</strong> D1 82 D0 B8 D0 BA D0 B0</p>
  
  <p>D0 9A D1 80 D0 B8 D0 BC D0 B8 D0 BD D0 B0 D0 BB D0 B8 <strong>D1 81</strong> D1 82 D0 B8 D0 BA D0 B0</p>
  
  <p>The printBytes function looks like this:</p>
  
  <pre><code>public static void printBytes(byte[] bv) {
      System.out.println();
      for (byte b : bv) {
          System.out.print(' ');
          System.out.print(String.format("%02X", b));
      }
  }
  </code></pre>
  
  <p><em>What can it be??</em></p>
  
  <p>I use eclipse, UTF-8 workspace encoding, the file contains cyrilic word "Криминалистика", it's a UTF-8 no-BOM file.</p>
  
  <p>I use JavaSE-1.6 (jdk1.6.0_29) for both projects,
  I have Windows 7 OS, windows-1252 system encoding.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I was finally able to reproduce the bug. I updated the project so you can test it: <a href="https://github.com/snowindy/getResourceAsStream-Bug" rel="nofollow">https://github.com/snowindy/getResourceAsStream-Bug</a></p>
  
  <p>The bug appears only if you have this code in maven pom.xml. This means it's maven-specific</p>
  
  <pre><code>&lt;build&gt;
      &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;resources&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
  ...
  </code></pre>