1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.io;
17
18 import java.io.Closeable;
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.FileNotFoundException;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.nio.channels.FileChannel;
25 import java.util.Properties;
26
27
28
29
30 public class ExternalResources {
31
32 private ExternalResources() {
33
34 }
35
36 public static void copyExternalResource(File sourceFile, File destFile) throws IOException {
37 if (!destFile.exists()) {
38 destFile.createNewFile();
39 }
40
41 FileChannel source = null;
42 FileChannel destination = null;
43 try {
44 source = new FileInputStream(sourceFile).getChannel();
45 destination = new FileOutputStream(destFile).getChannel();
46 destination.transferFrom(source, 0, source.size());
47 } finally {
48 closeQuietly(source);
49 closeQuietly(destination);
50 }
51
52 }
53
54 private static void closeQuietly(Closeable closeable) {
55 if (closeable != null) {
56 try {
57 closeable.close();
58 } catch (IOException e) {
59
60 }
61 }
62 }
63
64 public static String getConfiguredTemplate(String templatePath, String templateProperty) throws FileNotFoundException {
65 String templateName = "";
66 Properties migrationProperties = new Properties();
67
68 try {
69 migrationProperties.load(new FileInputStream(templatePath));
70 templateName = migrationProperties.getProperty(templateProperty);
71 } catch (FileNotFoundException e) {
72 throw e;
73 } catch (Exception e) {
74 e.printStackTrace();
75 }
76
77 return templateName;
78 }
79
80 }