Path: blob/master/test/functional/CacheManagement/src/tests/sharedclasses/CopyResources.java
6004 views
/*******************************************************************************1* Copyright (c) 2010, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122package tests.sharedclasses;2324import java.io.*;2526/**27* Supplied an input and output folder, will copy any resources (ignoring .java and .class files) from input to output.28*/29public class CopyResources {3031public static void main(String[] args) throws Exception {3233if (args==null || args.length!=2) {34throw new IllegalArgumentException("CopyResources <inputfolder> <outputfolder>");35}3637File fIn = new File(args[0]);38File fOut = new File(args[1]);3940if (!fIn.exists() || !fIn.isDirectory()) {41throw new IllegalArgumentException("inputfolder must be an existing directory");42}43if (!fOut.exists()) {44fOut.mkdir();45} else if (!fOut.isDirectory()) {46throw new IllegalArgumentException("outputfolder specifies an already existing file, when it should specify a directory");47}4849copyStuff(fIn,fOut);50}5152private static void copyStuff(File from,File to) throws Exception {53String[] files = from.list(new StripNonResourcesFilter());54if (files!=null) {55for (int i = 0; i < files.length; i++) {56File fFrom = new File(from,files[i]);57File fTo = new File(to,files[i]);58if (fFrom.isFile()) {59copyFile(fFrom,fTo);60} else if (fFrom.isDirectory()) {61fTo.mkdir();62copyStuff(fFrom,fTo);63} else {64System.out.println("how to handle? "+fFrom);65}66}67}68}6970static class StripNonResourcesFilter implements FilenameFilter {71public boolean accept(File dir, String name) {72if (name.endsWith(".java")) return false;73if (name.indexOf("CVS")!=-1) return false;74return true;75}76}7778private static void copyFile(File from,File to) throws Exception {79System.out.println("Copying '"+from+"' to '"+to+"'");80int i =0;81byte[] buff = new byte[1000];82FileInputStream fis = new FileInputStream(from);83FileOutputStream fos = new FileOutputStream(to);84int read=1;85while (true && read>0) {86read = fis.read(buff);87i+=read;88if (read>-1) fos.write(buff,0,read);89}90fos.flush();91fos.close();92fis.close();93}9495}969798