1 50 51 package com.lowagie.text.rtf.document.output; 52 53 import java.io.BufferedInputStream ; 54 import java.io.BufferedOutputStream ; 55 import java.io.File ; 56 import java.io.FileInputStream ; 57 import java.io.FileOutputStream ; 58 import java.io.IOException ; 59 import java.io.OutputStream ; 60 61 62 70 public class RtfDiskCache implements RtfDataCache { 71 72 75 private BufferedOutputStream data = null; 76 79 private File tempFile = null; 80 81 86 public RtfDiskCache() throws IOException { 87 this.tempFile = File.createTempFile("iText", null); 88 this.data = new BufferedOutputStream (new FileOutputStream (tempFile)); 89 } 90 91 94 public OutputStream getOutputStream() { 95 return this.data; 96 } 97 98 101 public void writeTo(OutputStream target) throws IOException { 102 this.data.close(); 103 BufferedInputStream tempIn = new BufferedInputStream (new FileInputStream (this.tempFile)); 104 byte[] buffer = new byte[8192]; 105 int bytesRead = -1; 106 while((bytesRead = tempIn.read(buffer)) >= 0) { 107 target.write(buffer, 0, bytesRead); 108 } 109 tempIn.close(); 110 this.tempFile.delete(); 111 } 112 113 } 114 | Popular Tags |