Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

caching downloaded classes

Gen.JavaSep 30 2014 — edited Oct 21 2014

Hi all,

Does the following code, which gets a class from a remote server, caches the class on the client machine?

URL u = new URL("http://1.2.3.4:80/JavaClasses/MainClass.class");

InputStream input = u.openStream();

DataInputStream data = new DataInputStream(input);

byte classBytes[] = downloadByteCodesFromURL(data);

Class c = defineClass("MainClass", classBytes, 0, classBytes.length);

//////////////////////////

public static byte[] downloadByteCodesFromURL( DataInputStream in) {

  ByteArrayOutputStream outStream = new ByteArrayOutputStream();

  while (true) {

         try {

               outStream.write(in.readByte());

         }

         catch (IOException e) {

                break;

         }

  }

  return outStream.toByteArray();

}

Thank you

This post has been answered by baftos on Oct 9 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2014
Added on Sep 30 2014
11 comments
2,318 views