ExternalResources.java

  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. import java.io.File;
  18. import java.io.FileInputStream;
  19. import java.io.FileNotFoundException;
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.util.Properties;

  24. import org.apache.ibatis.logging.Log;
  25. import org.apache.ibatis.logging.LogFactory;

  26. /**
  27.  * @author Clinton Begin
  28.  */
  29. @Deprecated
  30. public class ExternalResources {

  31.   private static final Log log = LogFactory.getLog(ExternalResources.class);

  32.   private ExternalResources() {
  33.     // do nothing
  34.   }

  35.   public static void copyExternalResource(File sourceFile, File destFile) throws IOException {
  36.     if (!destFile.exists()) {
  37.       destFile.createNewFile();
  38.     }

  39.     try (FileInputStream source = new FileInputStream(sourceFile);
  40.         FileOutputStream destination = new FileOutputStream(destFile)) {
  41.       destination.getChannel().transferFrom(source.getChannel(), 0, source.getChannel().size());
  42.     }

  43.   }

  44.   public static String getConfiguredTemplate(String templatePath, String templateProperty)
  45.       throws FileNotFoundException {
  46.     String templateName = "";
  47.     Properties migrationProperties = new Properties();

  48.     try (InputStream is = new FileInputStream(templatePath)) {
  49.       migrationProperties.load(is);
  50.       templateName = migrationProperties.getProperty(templateProperty);
  51.     } catch (FileNotFoundException e) {
  52.       throw e;
  53.     } catch (Exception e) {
  54.       log.error("", e);
  55.     }

  56.     return templateName;
  57.   }

  58. }