1 package com.atlassian.plugin.webresource.util;
2
3 import com.atlassian.plugin.servlet.DownloadableResource;
4 import com.atlassian.plugin.servlet.DownloadException;
5
6 import java.io.IOException;
7 import java.io.OutputStream;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11
12
13
14 public class DownloadableResourceTestImpl implements DownloadableResource
15 {
16 private final String contentType;
17 private final String content;
18
19
20 public DownloadableResourceTestImpl(final String contentType, final String content)
21 {
22 this.contentType = contentType;
23 this.content = content;
24 }
25
26 public boolean isResourceModified(final HttpServletRequest request, final HttpServletResponse response)
27 {
28 return false;
29 }
30
31 public void serveResource(final HttpServletRequest request, final HttpServletResponse response)
32 throws DownloadException
33 {
34 try
35 {
36 writeContent(response.getOutputStream());
37 }
38 catch (IOException e)
39 {
40 throw new RuntimeException(e);
41 }
42 }
43
44 public void streamResource(final OutputStream out)
45 {
46 writeContent(out);
47 }
48
49 private void writeContent(final OutputStream out)
50 {
51 byte[] bytes = content.getBytes();
52 try
53 {
54 out.write(bytes);
55 }
56 catch (IOException e)
57 {
58 throw new RuntimeException(e);
59 }
60 }
61
62 public String getContentType()
63 {
64 return contentType;
65 }
66 }