Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion group16/2562124714/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

740 changes: 350 additions & 390 deletions group16/2562124714/.idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion group16/2562124714/src/Test/TestRunner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Test;

import com.coding.basic.linklist.LRUPageFrameTest;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.Failure;

Expand All @@ -10,7 +11,7 @@
*/
public class TestRunner {
public static void main(String[] args) {
org.junit.runner.Result result = JUnitCore.runClasses(StrutsTest.class);
org.junit.runner.Result result = JUnitCore.runClasses(LRUPageFrameTest.class);
for (Failure failure:result.getFailures()) {
System.out.println(failure.toString());
}
Expand Down
115 changes: 115 additions & 0 deletions group16/2562124714/src/com/coderising/jvm/loader/ClassFileLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.coderising.jvm.loader;

import java.io.*;
import java.util.ArrayList;
import java.util.List;



public class ClassFileLoader {

private List<String> clzPaths = new ArrayList<String>();

public byte[] readBinaryCode(String className) {
//找到文件的具体路径
if(clzPaths.size() == 0 || className == "")
{
return null;
}

String []path = className.split("\\.");
String MainPath = "";
String FileName = "\\";

for (int i = 0; i < path.length - 1; i++)
{
FileName += path[i] + "\\";
}
FileName += path[path.length - 1] + ".class";
System.out.println(FileName);

for (String item: clzPaths
) {
if (new File(item + FileName).exists())
{
MainPath += item;
break;
}
}

if (MainPath == "")
{
return null;
}

File file = new File(MainPath + FileName);
InputStream is = null;
byte[] buffer = new byte[(int)file.length()];
try
{
System.out.println(MainPath + FileName);
is = new FileInputStream(MainPath + FileName);
// read stream data into buffer
is.read(buffer);

return buffer;



}
catch(Exception e) {

// if any I/O error occurs
e.printStackTrace();
return null;
} finally {

// releases system resources associated with this stream
if(is!=null)
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

private byte[] loadClassFile(String clzFileName) {

return null;
}



public void addClassPath(String path) {
clzPaths.add(path);

}

public String getClassPath_V1(){

return null;
}

public String getClassPath(){
if (clzPaths.size() == 0)
{
return "";
}

String ClassPath = "";
for (String item:
clzPaths) {
ClassPath += item + ";";
}
ClassPath = ClassPath.substring(0, ClassPath.length() - 1); //干掉最后一个 ;

return ClassPath;
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.coderising.jvm.test;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.coderising.jvm.loader.ClassFileLoader;





public class ClassFileloaderTest {


static String path1 = "C:\\Users\\cs\\Desktop\\javacoding2017\\coding2017\\group16\\2562124714\\out\\production\\2562124714";
static String path2 = "C:\\temp";



@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void testClassPath(){

ClassFileLoader loader = new ClassFileLoader();
loader.addClassPath(path1);
loader.addClassPath(path2);

String clzPath = loader.getClassPath();

Assert.assertEquals(path1+";"+path2,clzPath);

}

@Test
public void testClassFileLength() {

ClassFileLoader loader = new ClassFileLoader();
loader.addClassPath(path1);

String className = "com.coderising.jvm.test.EmployeeV1";

byte[] byteCodes = loader.readBinaryCode(className);

// 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大
Assert.assertEquals(1056, byteCodes.length);

}


@Test
public void testMagicNumber(){
ClassFileLoader loader = new ClassFileLoader();
loader.addClassPath(path1);
String className = "com.coderising.jvm.test.EmployeeV1";
byte[] byteCodes = loader.readBinaryCode(className);
byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]};


String acctualValue = this.byteToHexString(codes);

Assert.assertEquals("cafebabe", acctualValue);
}






private String byteToHexString(byte[] codes ){
StringBuffer buffer = new StringBuffer();
for(int i=0;i<codes.length;i++){
byte b = codes[i];
int value = b & 0xFF;
String strHex = Integer.toHexString(value);
if(strHex.length()< 2){
strHex = "0" + strHex;
}
buffer.append(strHex);
}
return buffer.toString();
}

}
28 changes: 28 additions & 0 deletions group16/2562124714/src/com/coderising/jvm/test/EmployeeV1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.coderising.jvm.test;

public class EmployeeV1 {


private String name;
private int age;

public EmployeeV1(String name, int age) {
this.name = name;
this.age = age;
}

public void setName(String name) {
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public void sayHello() {
System.out.println("Hello , this is class Employee ");
}
public static void main(String[] args){
EmployeeV1 p = new EmployeeV1("Andy",29);
p.sayHello();

}
}
23 changes: 23 additions & 0 deletions group16/2562124714/src/com/coding/basic/LinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,35 @@ public Object get(int index){
Node node;
int i = 0;

if (index > this.size())
{
return null;
}

for (i = 1, node = head; i < index ; i++, node = node.next) {
}

return node.data;
// return null;
}

public void set(int index, Object o)
{
if (o == null || index > this.size())
{
return;
}

Node node;
int i;
for (i = 1, node = head; i < index ; i++, node = node.next)
{
}

node.data = o;

}

public Object remove(int index){
Node node;
int i = 0;
Expand Down
Loading