2017-01-09 17:00:05 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, tobias
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
package sesim;
|
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.RandomAccessFile;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLClassLoader;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.channels.FileChannel;
|
|
|
|
import java.security.ProtectionDomain;
|
|
|
|
import java.util.ArrayList;
|
2017-01-16 07:19:37 +01:00
|
|
|
import java.util.SortedMap;
|
|
|
|
import java.util.TreeMap;
|
2017-01-24 02:28:00 +01:00
|
|
|
import java.lang.ClassLoader.*;
|
2017-01-16 07:19:37 +01:00
|
|
|
|
2017-01-09 17:00:05 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author tobias
|
|
|
|
*/
|
|
|
|
public class Test {
|
2017-01-22 07:03:16 +01:00
|
|
|
|
|
|
|
static void tube() {
|
|
|
|
try {
|
|
|
|
System.out.printf("Hello %s\n", "args");
|
|
|
|
if (0 == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
System.out.printf("Always %s\n", "the end");
|
|
|
|
}
|
|
|
|
System.out.print("haha\n");
|
|
|
|
}
|
2017-01-10 19:27:11 +01:00
|
|
|
|
|
|
|
static void print_account(AccountData ad) {
|
|
|
|
System.out.print(
|
|
|
|
"Account ID:"
|
|
|
|
+ ad.id
|
|
|
|
+ " Ballance:"
|
|
|
|
+ ad.money
|
|
|
|
+ " Shares:"
|
|
|
|
+ ad.shares
|
|
|
|
+ "\n"
|
|
|
|
);
|
|
|
|
}
|
2017-01-24 02:28:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static public String getFullClassName(String classFileName) throws IOException {
|
|
|
|
File file = new File(classFileName);
|
|
|
|
|
|
|
|
FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();
|
|
|
|
ByteBuffer bb = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size());
|
|
|
|
|
|
|
|
String x = new String();
|
|
|
|
|
|
|
|
//x.getClass().getClassLoader().loadClass(x);
|
|
|
|
//Class<?> clazz = defineClass((String)null, bb, (ProtectionDomain)null);
|
|
|
|
//return clazz.getName();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-10 19:27:11 +01:00
|
|
|
|
2017-01-09 17:00:05 +01:00
|
|
|
/**
|
|
|
|
* @param args the command line arguments
|
|
|
|
*/
|
2017-01-24 02:28:00 +01:00
|
|
|
public static void main(String[] args) throws InterruptedException, MalformedURLException, InstantiationException, IllegalAccessException, IOException {
|
2017-01-26 01:52:03 +01:00
|
|
|
AutoTraderLoader tl = new AutoTraderLoader();
|
2017-01-23 18:56:09 +01:00
|
|
|
|
|
|
|
|
2017-01-26 01:52:03 +01:00
|
|
|
tl.getTraders();
|
2017-01-23 18:56:09 +01:00
|
|
|
System.exit(0);
|
|
|
|
|
2017-01-16 07:19:37 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
|
2017-01-22 07:03:16 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
ArrayList<File> sl = tl.getTraders("./target/classes/traders");
|
2017-01-22 07:03:16 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
File file = sl.get(0);
|
2017-01-22 07:03:16 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
System.out.printf("Filename %s\n", file.getName());
|
2017-01-22 07:03:16 +01:00
|
|
|
|
|
|
|
try {
|
2017-01-24 02:28:00 +01:00
|
|
|
// Convert File to a URL
|
|
|
|
URL url = file.toURL(); // file:/c:/myclasses/
|
|
|
|
|
|
|
|
URL[] urls = new URL[]{url};
|
2017-01-16 19:12:49 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
// Create a new class loader with the directory
|
|
|
|
ClassLoader cl = new URLClassLoader(urls);
|
|
|
|
|
|
|
|
|
|
|
|
Class cls = cl.loadClass("traders.RandomTraderConfig");
|
|
|
|
|
|
|
|
System.out.printf("Loaded Class: %s\n",cls.getClass().getName());
|
|
|
|
|
|
|
|
sesim.AutoTraderConfig at = (AutoTraderConfig )cls.newInstance();
|
|
|
|
|
2017-01-22 07:03:16 +01:00
|
|
|
|
2017-01-24 02:28:00 +01:00
|
|
|
String cp = System.getProperty("java.class.path");
|
|
|
|
System.out.printf("CP: %s\n", cp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load in the class; MyClass.class should be located in
|
|
|
|
// the directory file:/c:/myclasses/com/mycompany
|
|
|
|
//Class cls = cl.loadClass("com.mycompany.MyClass");
|
|
|
|
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
System.out.printf("hahahah %s\n", e.getClass().getName());
|
|
|
|
System.out.print("\nException was thrown\n");
|
|
|
|
System.out.print(e.getMessage());
|
|
|
|
System.out.print("\n;;;;a\n");
|
2017-01-22 07:03:16 +01:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:00:05 +01:00
|
|
|
}
|
2017-01-10 19:27:11 +01:00
|
|
|
|
2017-01-09 17:00:05 +01:00
|
|
|
}
|