title: weird IO operation behavior in jar file
body: <p>Well I just posted a (semi-like) question <a href="https://stackoverflow.com/questions/20452443/jar-file-unexpected-response">here</a>, and I asked the issue generally, but I've got the issue, and this is a IO problem.</p>
  
  <p>in our program we have to read a file (around 10MB) and decrypt it, I  am using the following class.</p>
  
  <pre><code>class FileStream extends InputStream {
    public int available() throws IOException {
      return baseStream.available();
    }
    public boolean markSupported() {
      return false;
    }
    InputStream baseStream;
    byte[] data = new byte[1048576];
    int loopRead = 0;
    int streamSize;
    int dataRead;
    public FileStream(InputStream is) throws Exception {
      this.baseStream = is;
      streamSize = is.available();
    }
    public int read() {
      if (dataRead == streamSize) {
        return -1;/* End of the stream */
      }
      dataRead++;
      if (loopRead == data.length) {
        decrypt();
      }
      return data[loopRead++];
    }
    byte[] tempRead = new byte[4096];// block(smallest) decryption size
    void decrypt() {
      try {
        int r;
        for (int i = 0; i &lt; (data.length / tempRead.length); i++) {
          System.out.print("Data Available: "+baseStream.available());
          r = baseStream.read(tempRead);// read from base stream, ERROR IS HERE!
          System.out.print("Data read: "+r);//not always 4096 in jar file, vary numbers!
          if (r &lt;= 0) {
            return;
          }
          System.arraycopy(tempRead, 0, data, (i * tempRead.length),
              tempRead.length);
        }// end-for
        // /////decrypt the data////////
        loopRead = 0;
      } catch (Exception ex) {
      }
    }
  }
  </code></pre>
  
  <p>it <strong>WORKS</strong> when I run it from <code>eclipse</code>, but when I generate the JAR file(export) and run it from command line (<code>java -Xmx1280M -jar app.jar</code>), it doesn't read the data correct.</p>
  
  <p>The block size(crypt block size) is 4096, so the size of file is dividable by 4096, I really don't know why this happens! it SHOULD read 4096 bytes of data each time, but it doesn't, and always the data availability is more than 4096(as should be).</p>
  
  <p>please help, what are the possible errors or situations would occur here?!</p>
  
  <p>thanks in advance.</p>