1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.impl;
20
21 import java.io.BufferedWriter;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24
25 import net.sourceforge.javadpkg.BuildException;
26 import net.sourceforge.javadpkg.GlobalConstants;
27 import net.sourceforge.javadpkg.Script;
28 import net.sourceforge.javadpkg.ScriptBuilder;
29 import net.sourceforge.javadpkg.io.DataTarget;
30
31
32
33
34
35
36
37
38
39
40 public class ScriptBuilderImpl implements ScriptBuilder, GlobalConstants {
41
42
43
44
45
46
47
48 public ScriptBuilderImpl() {
49 super();
50 }
51
52
53 @Override
54 public void buildScript(DataTarget target, Script script) throws IOException, BuildException {
55 if (target == null)
56 throw new IllegalArgumentException("Argument target is null.");
57 if (script == null)
58 throw new IllegalArgumentException("Argument script is null.");
59
60 try {
61 try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(target.getOutputStream(), UTF_8_CHARSET))) {
62 writer.write(script.getText());
63 }
64 } catch (IOException e) {
65 throw new IOException("Couldn't build script |" + target.getName() + "|: " + e.getMessage(), e);
66 }
67 }
68
69
70 }