Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/CacheManagement/src/tests/sharedclasses/CopyResources.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2010, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
package tests.sharedclasses;
24
25
import java.io.*;
26
27
/**
28
* Supplied an input and output folder, will copy any resources (ignoring .java and .class files) from input to output.
29
*/
30
public class CopyResources {
31
32
public static void main(String[] args) throws Exception {
33
34
if (args==null || args.length!=2) {
35
throw new IllegalArgumentException("CopyResources <inputfolder> <outputfolder>");
36
}
37
38
File fIn = new File(args[0]);
39
File fOut = new File(args[1]);
40
41
if (!fIn.exists() || !fIn.isDirectory()) {
42
throw new IllegalArgumentException("inputfolder must be an existing directory");
43
}
44
if (!fOut.exists()) {
45
fOut.mkdir();
46
} else if (!fOut.isDirectory()) {
47
throw new IllegalArgumentException("outputfolder specifies an already existing file, when it should specify a directory");
48
}
49
50
copyStuff(fIn,fOut);
51
}
52
53
private static void copyStuff(File from,File to) throws Exception {
54
String[] files = from.list(new StripNonResourcesFilter());
55
if (files!=null) {
56
for (int i = 0; i < files.length; i++) {
57
File fFrom = new File(from,files[i]);
58
File fTo = new File(to,files[i]);
59
if (fFrom.isFile()) {
60
copyFile(fFrom,fTo);
61
} else if (fFrom.isDirectory()) {
62
fTo.mkdir();
63
copyStuff(fFrom,fTo);
64
} else {
65
System.out.println("how to handle? "+fFrom);
66
}
67
}
68
}
69
}
70
71
static class StripNonResourcesFilter implements FilenameFilter {
72
public boolean accept(File dir, String name) {
73
if (name.endsWith(".java")) return false;
74
if (name.indexOf("CVS")!=-1) return false;
75
return true;
76
}
77
}
78
79
private static void copyFile(File from,File to) throws Exception {
80
System.out.println("Copying '"+from+"' to '"+to+"'");
81
int i =0;
82
byte[] buff = new byte[1000];
83
FileInputStream fis = new FileInputStream(from);
84
FileOutputStream fos = new FileOutputStream(to);
85
int read=1;
86
while (true && read>0) {
87
read = fis.read(buff);
88
i+=read;
89
if (read>-1) fos.write(buff,0,read);
90
}
91
fos.flush();
92
fos.close();
93
fis.close();
94
}
95
96
}
97
98