View Javadoc
1   /*
2    *    Copyright 2009-2025 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.FileNotFoundException;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.nio.file.Files;
24  import java.nio.file.Path;
25  import java.util.Properties;
26  
27  import org.apache.ibatis.logging.Log;
28  import org.apache.ibatis.logging.LogFactory;
29  
30  /**
31   * @author Clinton Begin
32   */
33  @Deprecated
34  public class ExternalResources {
35  
36    private static final Log log = LogFactory.getLog(ExternalResources.class);
37  
38    private ExternalResources() {
39      // do nothing
40    }
41  
42    public static void copyExternalResource(File sourceFile, File destFile) throws IOException {
43      if (!destFile.exists()) {
44        destFile.createNewFile();
45      }
46  
47      try (InputStream source = Files.newInputStream(sourceFile.toPath());
48          OutputStream destination = Files.newOutputStream(destFile.toPath())) {
49        source.transferTo(destination);
50      }
51  
52    }
53  
54    public static String getConfiguredTemplate(String templatePath, String templateProperty)
55        throws FileNotFoundException {
56      String templateName = "";
57      Properties migrationProperties = new Properties();
58  
59      try (InputStream is = Files.newInputStream(Path.of(templatePath))) {
60        migrationProperties.load(is);
61        templateName = migrationProperties.getProperty(templateProperty);
62      } catch (FileNotFoundException e) {
63        throw e;
64      } catch (Exception e) {
65        log.error("", e);
66      }
67  
68      return templateName;
69    }
70  
71  }