public class MainClass {
public static void main
(String args
[]) { String name =
"http://urlWithClassName";
try {
if (!name.endsWith(".class")) {
System.
err.
println("That doesn't look like a byte code file!");
return;
}
// parse out the name of the class from the URL
String classname = s.
substring(s.
lastIndexOf('/'), s.
lastIndexOf(".class"));
Class AppletClass = ucl.
loadClass(classname,
true);
f.setSize(200, 200);
f.add("Center", apl);
apl.init();
apl.start();
f.setVisible(true);
}
}
}
this.url = u;
}
if (cls == null) {
try {
cls = findSystemClass(name);
}
}
if (cls == null) {
byte classData[] = loadClassData(name);
cls = defineClass(classData, 0, classData.length);
cache.put(name, cls);
}
if (resolve) {
resolveClass(cls);
}
return cls;
}
byte[] buffer;
int bufferLength = 128;
try {
URL classURL =
new URL(url, name +
".class");
uc.setAllowUserInteraction(false);
try {
theClassInputStream = uc.getInputStream();
}
int contentLength = uc.getContentLength();
// A lot of web servers don't send content-lengths
// for .class files
if (contentLength == -1) {
buffer = new byte[bufferLength * 16];
} else {
buffer = new byte[contentLength];
}
int bytesRead = 0;
int offset = 0;
while (bytesRead >= 0) {
bytesRead = theClassInputStream.read(buffer, offset, bufferLength);
if (bytesRead == -1)
break;
offset += bytesRead;
if (contentLength == -1 && offset == buffer.length) { // grow the array
byte temp[] = new byte[offset * 2];
System.
arraycopy(buffer,
0, temp,
0, offset
);
buffer = temp;
} else if (offset > buffer.length) {
}
}
if (offset < buffer.length) { // shrink the array
byte temp[] = new byte[offset];
System.
arraycopy(buffer,
0, temp,
0, offset
);
buffer = temp;
}
// Make sure all the bytes were received
if (contentLength != -1 && offset != contentLength) {
+ "\n Expected " + contentLength + " bytes");
}
} finally {
try {
if (theClassInputStream != null)
theClassInputStream.close();
}
}
return buffer;
}
}