View Javadoc
1   /*
2    *    Copyright 2009-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.io;
17  
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.FileNotFoundException;
21  import java.io.FileOutputStream;
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.util.Properties;
25  
26  import org.apache.ibatis.logging.Log;
27  import org.apache.ibatis.logging.LogFactory;
28  
29  /**
30   * @author Clinton Begin
31   */
32  @Deprecated
33  public class ExternalResources {
34  
35    private static final Log log = LogFactory.getLog(ExternalResources.class);
36  
37    private ExternalResources() {
38      // do nothing
39    }
40  
41    public static void copyExternalResource(File sourceFile, File destFile) throws IOException {
42      if (!destFile.exists()) {
43        destFile.createNewFile();
44      }
45  
46      try (FileInputStream source = new FileInputStream(sourceFile);
47          FileOutputStream destination = new FileOutputStream(destFile)) {
48        destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
49      }
50  
51    }
52  
53    public static String getConfiguredTemplate(String templatePath, String templateProperty)
54        throws FileNotFoundException {
55      String templateName = "";
56      Properties migrationProperties = new Properties();
57  
58      try (InputStream is = new FileInputStream(templatePath)) {
59        migrationProperties.load(is);
60        templateName = migrationProperties.getProperty(templateProperty);
61      } catch (FileNotFoundException e) {
62        throw e;
63      } catch (Exception e) {
64        log.error("", e);
65      }
66  
67      return templateName;
68    }
69  
70  }