1 package com.atlassian.plugin.cache.filecache.impl;
2
3 import com.atlassian.plugin.cache.filecache.FileCacheStreamProvider;
4 import com.atlassian.plugin.servlet.DownloadException;
5
6 import java.io.IOException;
7 import java.io.OutputStream;
8
9 public class MockFileCacheStreamProvider implements FileCacheStreamProvider {
10 final String contents;
11 final RuntimeException re;
12 int callCount = 0;
13
14 public MockFileCacheStreamProvider(String contents) {
15 this(contents, null);
16 }
17 public MockFileCacheStreamProvider(String contents, RuntimeException re) {
18 this.contents = contents;
19 this.re = re;
20 }
21
22 @Override
23 public void writeStream(OutputStream dest) throws DownloadException {
24 callCount++;
25 try {
26 dest.write(contents.getBytes());
27 if (re != null) {
28 throw re;
29 }
30 } catch (IOException e) {
31 throw new DownloadException(e);
32 }
33 }
34 }