1 17 18 19 20 package org.apache.fop.pdf; 21 22 import java.io.IOException ; 23 24 27 public class StreamCacheFactory { 28 29 private static boolean defaultCacheToFile = false; 30 private static StreamCacheFactory fileInstance = null; 31 private static StreamCacheFactory memoryInstance = null; 32 33 private boolean cacheToFile = false; 34 35 40 public static StreamCacheFactory getInstance(boolean cacheToFile) { 41 if (cacheToFile) { 42 if (fileInstance == null) { 43 fileInstance = new StreamCacheFactory(true); 44 } 45 return fileInstance; 46 } else { 47 if (memoryInstance == null) { 48 memoryInstance = new StreamCacheFactory(false); 49 } 50 return memoryInstance; 51 } 52 } 53 54 59 public static StreamCacheFactory getInstance() { 60 return getInstance(defaultCacheToFile); 61 } 62 63 67 public static void setDefaultCacheToFile(boolean cacheToFile) { 68 defaultCacheToFile = cacheToFile; 69 } 70 71 75 public StreamCacheFactory(boolean cacheToFile) { 76 this.cacheToFile = cacheToFile; 77 } 78 79 85 public StreamCache createStreamCache() throws IOException { 86 if (this.cacheToFile) { 87 return new TempFileStreamCache(); 88 } else { 89 return new InMemoryStreamCache(); 90 } 91 } 92 93 100 public StreamCache createStreamCache(int hintSize) throws IOException { 101 if (this.cacheToFile) { 102 return new TempFileStreamCache(); 103 } else { 104 return new InMemoryStreamCache(hintSize); 105 } 106 } 107 108 112 public boolean getCacheToFile() { 113 return this.cacheToFile; 114 } 115 116 117 } 118 | Popular Tags |