1   package com.atlassian.core.spool;
2   
3   import java.io.ByteArrayInputStream;
4   import java.io.IOException;
5   import java.io.InputStream;
6   
7   import org.apache.commons.io.IOUtils;
8   import org.apache.commons.io.output.ByteArrayOutputStream;
9   
10  /**
11   * A very simple spool that uses a ByteArray buffer. Default buffer size is 10KiB
12   */
13  
14  public class ByteArraySpool implements Spool
15  {
16      private int initialBufferSize = 10 * 1024;
17  
18      public int getInitialBufferSize()
19      {
20          return initialBufferSize;
21      }
22  
23      /**
24       * Configure the initial size of the byte array buffer.
25       *
26       * @param initialBufferSize The initial size of the buffer in bytes
27       */
28      public void setInitialBufferSize(int initialBufferSize)
29      {
30          this.initialBufferSize = initialBufferSize;
31      }
32  
33      public InputStream spool(InputStream is) throws IOException
34      {
35          ByteArrayOutputStream buf = new ByteArrayOutputStream(initialBufferSize);
36          IOUtils.copy(is, buf);
37          return new ByteArrayInputStream(buf.toByteArray());
38      }
39  
40  }