ced0d669ab1efc9fd41a3cba419bfb753f9d1916
[mir.git] / source / mir / misc / FileUtil.java
1
2 /*
3  * put your module comment here
4  */
5
6
7 package mir.misc;
8
9 import  java.lang.*;
10 import  java.util.*;
11 import  java.io.*;
12 import  java.net.*;
13 import  freemarker.template.*;
14 import  mir.entity.*;
15 import  mir.storage.*;
16
17 import javax.servlet.http.*;
18 import javax.servlet.*;
19
20 /**
21  * Hilfsklasse zum Mergen von Template und Daten
22  */
23 public final class FileUtil {
24
25   private static String producerStorageRoot;
26
27   //
28   // Initialisierung
29
30   static {
31     producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
32   }
33
34   /**
35    * Privater Konstruktor, um versehentliche Instantiierung zu verhindern
36    */
37   private FileUtil () {
38   }
39
40   public static boolean write(String filename, byte[] in)
41     throws IOException {
42
43                 boolean retVal = false;
44
45                 if (in!=null) {
46                         try {
47         File f = null;
48         f = new File(filename);
49                                 File dir = new File(f.getParent());
50                                 dir.mkdirs();
51
52                                 FileOutputStream outStream;
53                                 outStream = new FileOutputStream(f);
54                                 outStream.write(in);
55                                 outStream.close();
56                                 retVal = true;
57                         } catch(IOException e) {
58         throw new IOException(e.toString());
59       }
60     }
61                 return retVal;
62         }
63
64   public static boolean read(String filename, byte out[])
65     throws IOException {
66
67     File f = null;
68     f = new File(filename);
69
70                 if (f.exists()) {
71                         try {
72         if (out.length != f.length())
73           return false;
74                                 FileInputStream inStream;
75                                 inStream = new FileInputStream(f);
76                                 inStream.read(out);
77                                 inStream.close();
78                         } catch(IOException e) {
79         throw new IOException(e.toString());
80       }
81     } else {
82       return false;
83     }
84     return true;
85   }
86     
87   public static long getSize(String filename) {
88     File f = null;
89     f = new File(filename);
90     long l=0;
91
92     if (f.exists()) {
93       return f.length();
94     } else {
95       return -1;
96     }
97   }
98
99  
100 }