Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29568

Re: dealing with ClassLoaders...

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Andreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject Re: dealing with ClassLoaders...
Date Tue, 5 Aug 2014 15:16:27 +0000 (UTC)
Organization A noiseless patient Spider
Lines 35
Message-ID <slrnlu1tab.fp3.avl@login.logic.tuwien.ac.at> (permalink)
References <slrnltl6t2.fp3.avl@login.logic.tuwien.ac.at> <lrg69c$6r3$1@gregory.bnet.hr> <slrnltv8mj.fp3.avl@login.logic.tuwien.ac.at> <c4ao7sF1mehU1@mid.individual.net>
Reply-To avl@logic.at
Injection-Date Tue, 5 Aug 2014 15:16:27 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="7fd0c836d94caf9f0b88d96117d7c68e"; logging-data="10524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pikY+y80dwP+V4T1rEtQk"
User-Agent slrn/pre1.0.0-18 (Linux)
Cancel-Lock sha1:f1Tu8SBGiHUVCZ/XpjyJ0Yum4F0=
Xref csiph.com comp.lang.java.programmer:29568

Show key headers only | View raw


Mike Amling <mamling@chaff.us> wrote:
> On 8/4/14 10:12 AM, Andreas Leitgeb wrote:
>>              URL url=getSystemResource(name.replace('.', '/') + ".class");
>>              byte[] classData = new byte[1024*1024*10]; int len = 0;
>>              try {
>>                 len = url.openConnection().getInputStream().read(classData);
>>              } catch (IOException e) {
>>                 e.printStackTrace();
>>              }
> You could buffer to a ByteArrayOutputStream.
>       for (int input; (input=source.read())>=0; ) {
>          buffer.write(input);
>       }

Thanks for your answer. You made me re-think my irrational
resistance against coding a loop for that task. :-)

Now, the snippet looks like this:

   byte[] chunk = new byte[1024]; int len = 0;
   URL url = getSystemResource(name.replace('.', '/') + ".class");
   try {
      InputStream is = url.openConnection().getInputStream();
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      while ((len = is.read(chunk)) > 0) { os.write(chunk,0,len); }
      chunk = os.toByteArray();
   } catch (IOException e) { chunk = null; }
   // if anything went wrong, there'll be an Exception on next line
   //   (be it NPE at chunk.length or from defineClass)
   res = defineClass(name,chunk, 0, chunk.length);

I think, that's good enough for me now. I declare my problem
as solved. :-)

Thanks again to all who participated in this thread!

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-07-31 19:40 +0000
  Re: dealing with ClassLoaders... Martin Gregorie <martin@address-in-sig.invalid> - 2014-07-31 20:44 +0000
    Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-01 14:22 +0000
      Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-01 21:10 +0000
        Re: dealing with ClassLoaders... Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-01 17:32 -0400
          Re: dealing with ClassLoaders... Joerg Meier <joergmmeier@arcor.de> - 2014-08-02 01:21 +0200
          Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-02 00:00 +0000
        Re: dealing with ClassLoaders... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-01 21:45 +0000
          Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-01 23:14 +0000
            Re: dealing with ClassLoaders... Martin Gregorie <martin@address-in-sig.invalid> - 2014-08-02 00:35 +0000
              Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-05 15:38 +0000
  Re: dealing with ClassLoaders... Silvio <silvio@internet.com> - 2014-08-01 13:31 +0200
    Re: dealing with ClassLoaders... Silvio <silvio@internet.com> - 2014-08-01 13:37 +0200
      Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-01 16:06 +0000
  Re: dealing with ClassLoaders... "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-01 13:19 +0100
    Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-01 15:51 +0000
  Re: dealing with ClassLoaders... Josip Almasi <joe@vrspace.org> - 2014-08-01 15:55 +0200
    Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-04 15:12 +0000
      Re: dealing with ClassLoaders... Mike Amling <mamling@chaff.us> - 2014-08-04 19:53 -0500
        Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-05 15:16 +0000
      Re: dealing with ClassLoaders... Josip Almasi <joe@vrspace.org> - 2014-08-08 11:53 +0200
        Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-08 18:46 +0000
          Re: dealing with ClassLoaders... Josip Almasi <joe@vrspace.org> - 2014-08-10 13:22 +0200
            Re: dealing with ClassLoaders... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-08-12 17:16 +0000

csiph-web