1 4 5 9 10 package org.openlaszlo.data; 11 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpServletResponse ; 14 15 import java.io.InputStream ; 16 import java.io.File ; 17 import java.io.IOException ; 18 import java.io.FileNotFoundException ; 19 20 import org.openlaszlo.utils.FileUtils; 21 import org.openlaszlo.utils.TempFileInputStream; 22 import org.openlaszlo.utils.ChainedException; 23 24 import org.apache.log4j.Logger; 25 26 29 public abstract class Converter { 30 31 private static Logger mLogger = Logger.getLogger(Converter.class); 32 33 38 public abstract InputStream convertToSWF(Data data, 39 HttpServletRequest req, HttpServletResponse res) 40 throws ConversionException, IOException ; 41 42 47 public abstract String chooseEncoding(HttpServletRequest req); 48 49 55 public InputStream encode(HttpServletRequest req, InputStream in, 56 String enc) throws IOException { 57 58 if (enc != null && !enc.equals("")) { 59 File tempFile = File.createTempFile("lzuc-", null); 60 mLogger.debug("Temporary file is " + tempFile.getAbsolutePath()); 61 try { 62 FileUtils.encode(in, tempFile, enc); 63 } catch (IOException e) { 64 FileUtils.close(in); 65 throw e; 66 } 67 try { 68 in = new TempFileInputStream(tempFile); 69 } catch (FileNotFoundException e) { 70 throw new ChainedException(e); 71 } 72 } 73 return in; 74 } 75 } 76 | Popular Tags |