/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.empire.db.codegen.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * File utilities * TODO would be better to let these methods throw IOExceptions! * */ public class FileUtils { private static final Log log = LogFactory.getLog(FileUtils.class); public static final String SEPARATOR = System.getProperty("file.separator"); private FileUtils() { // Utility class } /** * Creates a directory structure due to a java package name within the specified folder. * @param target, the target folder * @param pack, the java package name */ public static File getFileFromPackage(File target, String pack) { StringBuilder sb = new StringBuilder(); sb.append(target.getAbsolutePath()).append(SEPARATOR); sb.append(pack.replace(".", SEPARATOR)); File f = new File(sb.toString()); if (!f.exists()) { f.mkdirs(); } return f; } /** * Recursively cleans (removes) all files under the given * directory. Note that this removes all sub-directories * but not the parent directory. * @param directory */ public static void cleanDirectory(File directory) { boolean success; if (directory.isDirectory()) { String[] children = directory.list(); for (int i=0; i