1 package com.atlassian.core.spool;
2
3 import java.io.InputStream;
4 import java.io.IOException;
5
6
7
8
9
10
11 public class SmartSpool implements ThresholdingSpool
12 {
13 private Spool overThresholdSpool = new BufferedFileSpool();
14 private ThresholdingSpool thresholdingSpool = new DeferredSpool();
15
16 public void setThresholdBytes(int bytes)
17 {
18 thresholdingSpool.setThresholdBytes(bytes);
19 }
20
21 public int getThresholdBytes()
22 {
23 return thresholdingSpool.getThresholdBytes();
24 }
25
26 public InputStream spool(InputStream is) throws IOException
27 {
28
29 if (is.available() > getThresholdBytes())
30 return overThresholdSpool.spool(is);
31
32
33
34
35 return thresholdingSpool.spool(is);
36 }
37
38
39
40
41
42
43 public void setOverThresholdSpool(Spool overThresholdSpool)
44 {
45 this.overThresholdSpool = overThresholdSpool;
46 }
47
48
49
50
51
52
53 public void setThresholdingSpool(ThresholdingSpool thresholdingSpool)
54 {
55 this.thresholdingSpool = thresholdingSpool;
56 }
57 }