View Javadoc

1   package com.atlassian.core.util;
2   
3   import java.io.BufferedInputStream;
4   import java.io.IOException;
5   import java.io.InputStream;
6   
7   /**
8    * Decorated subclass of {@link BufferedInputStream} that can be read multiple times as it marks the stream
9    * with {@link Integer#MAX_VALUE} and resets the stream when {@code close()} is called.
10   */
11  public class ReusableBufferedInputStream extends BufferedInputStream
12  {
13      public ReusableBufferedInputStream(InputStream inputStream)
14      {
15          super(inputStream);
16          super.mark(Integer.MAX_VALUE);
17      }
18  
19      /**
20       * Calls {@link java.io.BufferedInputStream#reset()} instead of closing the stream.
21       * @throws IOException
22       */
23      @Override
24      public void close() throws IOException
25      {
26          super.reset();
27      }
28  
29      /**
30       * Actually closes the ReusableBufferedInputStream by calling {@link java.io.BufferedInputStream#close()}.
31       * @throws IOException
32       */
33      public void destroy() throws IOException
34      {
35          super.close();
36      }
37  }