1 package net.sf.jour.processor;
2
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8
9 public class DirectoryOutputWriter implements OutputWriter {
10
11 private File dir;
12
13 public DirectoryOutputWriter(File dir) {
14 this.dir = dir;
15 }
16
17 public boolean needUpdate(Entry entry) {
18
19 return true;
20 }
21
22 public void write(Entry entry) throws IOException {
23
24
25
26 String name = entry.getName().replace('/', File.separatorChar);
27 File file = new File(dir.getAbsolutePath() + File.separatorChar + name);
28 File dir = file.getParentFile();
29 if (!dir.exists()) {
30 dir.mkdirs();
31 }
32 if (entry.isDirectory()) {
33 file.mkdirs();
34 return;
35 }
36
37 OutputStream out = null;
38 InputStream in = null;
39 try {
40 out = new FileOutputStream(file);
41 in = entry.getInputStream();
42
43 byte[] b = new byte[256];
44 int cnt;
45 while ((cnt = in.read(b)) != -1) {
46 out.write(b, 0, cnt);
47 }
48 file.setLastModified(entry.getTime());
49 } finally {
50 if (in != null) {
51 in.close();
52 }
53 if (out != null) {
54 out.close();
55 }
56 }
57 }
58
59 public void close() {
60
61 }
62
63 }