1 package ch.ige.edossier.util;
2
3 import java.io.FileOutputStream;
4 import java.io.IOException;
5 import java.io.OutputStream;
6 import java.net.HttpURLConnection;
7 import java.net.URL;
8 import java.util.Map;
9 import org.apache.log4j.Logger;
10
11
21 public abstract class ImageWriter
22 {
23 private static String ToJPEGServletURL = "http://localhost:8080/edossier/imageservlet";
24
25 private static final Logger LOG = Logger.getLogger( ImageWriter.class );
27
28 protected static final double CONVERSION_DPCM_TO_DPI = 2.54;
29 protected String imageWidth;
30 protected String imageHeigth;
31 protected int xDensity;
32 protected int yDensity;
33 protected int imageWidthInPixel;
34 protected int imageHeigthInPixel;
35
36 public abstract Map processImage( String outputPath, byte[] image ) throws IOException;
37
38 protected void writeToFile( byte[] image, String path )
39 {
40 try
41 {
42 OutputStream os = new FileOutputStream( path );
43 os.write( image );
44 os.flush();
45 os.close();
46 }
47 catch( IOException ex )
48 {
49 LOG.error( ex.getMessage() );
50 }
51 }
52
53
59 protected String callServlet( String imagePath, String imageType )
60 {
61 String status;
62 try
63 {
64 URL url = new URL( ToJPEGServletURL + "?tiffPath=" + imagePath + "&bildTyp=" + imageType );
65 HttpURLConnection con = ( HttpURLConnection )url.openConnection();
66 con.setUseCaches( false );
67 status = con.getResponseMessage();
68 }
69 catch( IOException ex )
70 {
71 LOG.error( ex.getMessage() );
72 status = ex.getMessage();
73 }
74 return status;
75 }
76
77 }
78