blob: f2d5b904ab29f3336e5b38a94f426f24e4b0106e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.pdf;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* class used to store the bytes for a PDFStream. It's actually a generic
* cached byte array, along with a factory that returns either an
* in-memory or tempfile based implementation based on the global
* cacheToFile setting.
*/
public abstract class StreamCache {
/**
* Global setting; controls whether to use tempfiles or not.
*/
private static boolean cacheToFile = false;
/**
* Change the global cacheToFile flag.
*/
public static void setCacheToFile(boolean tizit) {
cacheToFile = tizit;
}
/**
* Get the value of the global cacheToFile flag.
*/
public static boolean getCacheToFile() {
return cacheToFile;
}
/**
* Get the correct implementation (based on cacheToFile) of
* StreamCache.
*/
public static StreamCache createStreamCache() throws IOException {
if (cacheToFile)
return new TempFileStreamCache();
else
return new InMemoryStreamCache();
}
/**
* Get the current OutputStream. Do not store it - it may change
* from call to call.
*/
public abstract OutputStream getOutputStream() throws IOException;
/**
* Filter the cache with the supplied PDFFilter.
*/
public abstract void applyFilter(PDFFilter filter) throws IOException;
/**
* Outputs the cached bytes to the given stream.
*/
public abstract void outputStreamData(OutputStream stream) throws IOException;
/**
* Returns the current size of the stream.
*/
public abstract int getSize() throws IOException;
/**
* Closes the cache and frees resources.
*/
public abstract void close() throws IOException;
/**
* Clears and resets the cache.
*/
public abstract void reset() throws IOException;
}
|