title: InputStream, mark(), reset()
body: <p>How are <code>mark()</code> and <code>reset()</code> methods working exactly(in code below), step by step ? I tried to write my own example but is starts to throw wrong mark exception or similar to that, and I cannot understand what is the point of placing mark and reset methods in this code because I don't see difference with this or without.</p>
  
  <pre><code>import java.io.*;
  
  class BufferedInputStreamDemo {
      public static void main(String args[]) {
          String s = "&amp;copy; is a copyright symbol, "
                  + "however &amp;copy isn't.\n";
          byte buf[] = s.getBytes();
  
          ByteArrayInputStream in = new ByteArrayInputStream(buf);
          int c;
          boolean marked = false;
  
          //try_with_resources
          try (BufferedInputStream f = new BufferedInputStream(in)) {
              while ((c = f.read()) != -1) {
                  switch (c) {
                      case '&amp;':
                          if (!marked) {
                              f.mark(32);
                              marked = true;
                          } else {
                              marked = false;
                          }
                          break;
                      case ';':
                          if (marked) {
                              marked = false;
                              System.out.print("(c)");
                          } else
                              System.out.print((char) c);
                          break;
                      case ' ':
                          if (marked) {
                              marked = false;
                              f.reset();
                              System.out.print("&amp;");
                          } else
                              System.out.print((char) c);
                          break;
                      default:
                          if (!marked)
                              System.out.print((char) c);
                          break;
                  }
              }
          } catch (IOException e) {
              System.out.println("I/O Error: " + e);
          }
      }
  }
  </code></pre>