下面列出了怎么用java.lang.ClassNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
loader.defineClass("BadParams", BadParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
/**
* RunList
* suitesToRun: a Vector of suites from RunSuite
* outDir: The output directory for the suite(s)
* pwOut: The output for writing suite and test results
* suiteProperties: From RunSuite for the top suite
* (individual suites in the vector may have their own
* properties which must also be located and applied)
*/
public RunList(Vector suitesToRun,
File runDir, File outDir, PrintWriter pwOut,
Properties suiteProperties,
Properties specialProperties,
String topParentSuite)
throws ClassNotFoundException, IOException, Exception
{
this.runDir = runDir;
this.outDir = outDir;
this.pwOut = pwOut;
this.suiteProperties = suiteProperties; // usual suite props
this.specialProperties = specialProperties; // for special test Flags
this.topSuiteName = suiteProperties.getProperty("suitename");
//System.out.println("----------------------------------------");
//System.out.println("RunList topSuiteName= " + topSuiteName);
this.topParentSuite = topParentSuite;
//System.out.println("topParentSuite= " + topParentSuite);
// Run the suites
runSuites(suitesToRun);
}
static void verifyTestType()
throws ClassNotFoundException, FileNotFoundException, IOException
{
//java requires '/' as separator to look into jar, irrespective of OS
InputStream is =
loadTestResource("harness/testtypes.properties");
Properties p = new Properties();
p.load(is);
String testtypes = p.getProperty("testtypes");
StringTokenizer st = new StringTokenizer(testtypes,",");
String ttype = "";
while (st.hasMoreTokens())
{
ttype = st.nextToken();
if ( testType.equals(ttype) )
return;
}
// Not a known test type
System.out.println("Unknown test type: " + testType);
System.exit(1);
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
/**
* RunList
* suitesToRun: a Vector of suites from RunSuite
* outDir: The output directory for the suite(s)
* pwOut: The output for writing suite and test results
* suiteProperties: From RunSuite for the top suite
* (individual suites in the vector may have their own
* properties which must also be located and applied)
*/
public RunList(Vector suitesToRun,
File runDir, File outDir, PrintWriter pwOut,
Properties suiteProperties,
Properties specialProperties,
String topParentSuite)
throws ClassNotFoundException, IOException, Exception
{
this.runDir = runDir;
this.outDir = outDir;
this.pwOut = pwOut;
this.suiteProperties = suiteProperties; // usual suite props
this.specialProperties = specialProperties; // for special test Flags
this.topSuiteName = suiteProperties.getProperty("suitename");
//System.out.println("----------------------------------------");
//System.out.println("RunList topSuiteName= " + topSuiteName);
this.topParentSuite = topParentSuite;
//System.out.println("topParentSuite= " + topParentSuite);
// Run the suites
runSuites(suitesToRun);
}
static void verifyTestType()
throws ClassNotFoundException, FileNotFoundException, IOException
{
//java requires '/' as separator to look into jar, irrespective of OS
InputStream is =
loadTestResource("harness/testtypes.properties");
Properties p = new Properties();
p.load(is);
String testtypes = p.getProperty("testtypes");
StringTokenizer st = new StringTokenizer(testtypes,",");
String ttype = "";
while (st.hasMoreTokens())
{
ttype = st.nextToken();
if ( testType.equals(ttype) )
return;
}
// Not a known test type
System.out.println("Unknown test type: " + testType);
System.exit(1);
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
private BadClassFiles() throws ClassNotFoundException {
classes = new Class<?>[] {
loader.defineClass("EmptyName", EmptyName_bytes),
loader.defineClass("BadModifiers", BadModifiers_bytes),
loader.defineClass("BadNameIndex", BadNameIndex_bytes),
loader.defineClass("NameIndexOutOfBounds", NameIndexOutOfBounds_bytes),
loader.defineClass("ExtraParams", ExtraParams_bytes),
// Name with .
loader.defineClass("BadName1", BadName1_bytes),
// Name with [
loader.defineClass("BadName2", BadName2_bytes),
// Name with ;
loader.defineClass("BadName3", BadName3_bytes),
// Name with /
loader.defineClass("BadName4", BadName4_bytes)
};
}
/**
* RunList
* suitesToRun: a Vector of suites from RunSuite
* outDir: The output directory for the suite(s)
* pwOut: The output for writing suite and test results
* suiteProperties: From RunSuite for the top suite
* (individual suites in the vector may have their own
* properties which must also be located and applied)
*/
public RunList(Vector suitesToRun,
File runDir, File outDir, PrintWriter pwOut,
Properties suiteProperties,
Properties specialProperties,
String topParentSuite)
throws ClassNotFoundException, IOException, Exception
{
this.runDir = runDir;
this.outDir = outDir;
this.pwOut = pwOut;
this.suiteProperties = suiteProperties; // usual suite props
this.specialProperties = specialProperties; // for special test Flags
this.topSuiteName = suiteProperties.getProperty("suitename");
//System.out.println("----------------------------------------");
//System.out.println("RunList topSuiteName= " + topSuiteName);
this.topParentSuite = topParentSuite;
//System.out.println("topParentSuite= " + topParentSuite);
// Run the suites
runSuites(suitesToRun);
}
static void BuildSuitesVector(String parent, String subsuites)
throws ClassNotFoundException, IOException
{
Properties p;
StringTokenizer st = new StringTokenizer(subsuites);
String child = "";
while (st.hasMoreTokens())
{
child = st.nextToken();
if (child.equals(parent))
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
p = getSuiteProperties(child, false);
if ( p.getProperty("suites") == null )
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
String moresuites = p.getProperty("suites");
BuildSuitesVector(child, moresuites);
}
}
}
}
/**
* Reads the contents of this message from the given input.
*/
public void fromData(DataInput in) throws IOException, ClassNotFoundException
{
this.regionPath = DataSerializer.readString(in);
this.callbackArgument = DataSerializer.readObject(in);
this.op = Operation.fromOrdinal(in.readByte());
this.originRemote = in.readBoolean();
this.distributedMember = DSFIDFactory.readInternalDistributedMember(in);
this.diskException = DataSerializer.readObject(in);
}
public static void main(String args[]) throws IOException, ClassNotFoundException{
//create the socket server object
server = new ServerSocket(port);
//keep listens indefinitely until receives 'exit' call or program terminates
while(true){
System.out.println("Waiting for client request");
//creating socket and waiting for client connection
Socket socket = server.accept();
//read from socket to ObjectInputStream object
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
//convert ObjectInputStream object to String
String message = (String) ois.readObject();
System.out.println("Message Received: " + message);
//create ObjectOutputStream object
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
//write object to Socket
oos.writeObject("Hi Client "+message);
//close resources
ois.close();
oos.close();
socket.close();
//terminate the server if client sends exit request
if(message.equalsIgnoreCase("exit")) break;
}
System.out.println("Shutting down Socket server!!");
//close the ServerSocket object
server.close();
}
static void BuildSuitesVector(String parent, String subsuites)
throws ClassNotFoundException, IOException
{
Properties p;
StringTokenizer st = new StringTokenizer(subsuites);
String child = "";
while (st.hasMoreTokens())
{
child = st.nextToken();
if (child.equals(parent))
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
p = getSuiteProperties(child, false);
if ( p.getProperty("suites") == null )
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
String moresuites = p.getProperty("suites");
BuildSuitesVector(child, moresuites);
}
}
}
}
/**
* Reads the contents of this message from the given input.
*/
public void fromData(DataInput in) throws IOException, ClassNotFoundException
{
this.regionPath = DataSerializer.readString(in);
this.callbackArgument = DataSerializer.readObject(in);
this.op = Operation.fromOrdinal(in.readByte());
this.originRemote = in.readBoolean();
this.distributedMember = DSFIDFactory.readInternalDistributedMember(in);
this.diskException = DataSerializer.readObject(in);
}
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
ClassNotFoundException object1 = new ClassNotFoundException();
harness.check(object1 != null);
harness.check(object1.toString(), "java.lang.ClassNotFoundException");
ClassNotFoundException object2 = new ClassNotFoundException("nothing happens");
harness.check(object2 != null);
harness.check(object2.toString(), "java.lang.ClassNotFoundException: nothing happens");
ClassNotFoundException object3 = new ClassNotFoundException(null);
harness.check(object3 != null);
harness.check(object3.toString(), "java.lang.ClassNotFoundException");
}
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// flag that is set when exception is caught
boolean caught = false;
try {
throw new ClassNotFoundException("ClassNotFoundException");
}
catch (ClassNotFoundException e) {
// correct exception was caught
caught = true;
}
harness.check(caught);
}
static void BuildSuitesVector(String parent, String subsuites)
throws ClassNotFoundException, IOException
{
Properties p;
StringTokenizer st = new StringTokenizer(subsuites);
String child = "";
while (st.hasMoreTokens())
{
child = st.nextToken();
if (child.equals(parent))
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
p = getSuiteProperties(child, false);
if ( p.getProperty("suites") == null )
{
suitesToRun.addElement(parent+":"+child);
//System.out.println("Add this: " + parent+":"+child);
}
else
{
String moresuites = p.getProperty("suites");
BuildSuitesVector(child, moresuites);
}
}
}
}
public static void main(String... args)
throws NoSuchMethodException, IOException, ClassNotFoundException {
new BadClassFiles().run();
}
public static void main(String... args)
throws NoSuchMethodException, IOException, ClassNotFoundException {
new BadClassFiles().run();
}
public static void main(String... args)
throws NoSuchMethodException, IOException, ClassNotFoundException {
new BadClassFiles().run();
}