1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.verifier.tests;
18
19 import java.io.File;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.io.OutputStream;
23 import java.net.URISyntaxException;
24
25 import org.apache.bcel.classfile.JavaClass;
26 import org.apache.bcel.classfile.Utility;
27
28 public abstract class TestCreator {
29
30
31 protected static final String TEST_PACKAGE = TestCreator.class.getPackage().getName();
32
33 public void create() throws IOException {
34 final File classFile = new File(getPackageFolder(), getClassName());
35 try (FileOutputStream out = new FileOutputStream(classFile)) {
36 create(out);
37 }
38 }
39
40 public abstract void create(OutputStream out) throws IOException;
41
42 private File getClassesFolder() throws IOException {
43 try {
44 return new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
45 } catch (final URISyntaxException e) {
46 throw new IOException(e);
47 }
48 }
49
50 private String getClassName() {
51 final String name = getClass().getName();
52 return name.substring(name.lastIndexOf('.') + 1).replace("Creator", JavaClass.EXTENSION);
53 }
54
55 private File getPackageFolder() throws IOException {
56 return new File(getClassesFolder(), getPackageName());
57 }
58
59 protected String getPackageName() {
60 return Utility.packageToPath(getClass().getPackage().getName());
61 }
62 }