Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mike Amling Newsgroups: comp.lang.java.programmer Subject: Re: dealing with ClassLoaders... Date: Mon, 04 Aug 2014 19:53:44 -0500 Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net E0QGfS78P9/XTzMUYayZxwE1qvRJcbpvYEeHAR8JgiJbdZkK8w Cancel-Lock: sha1:CkiruhhppGiUfoiOcpNh0Eud6s8= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:29562 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. InputStream source=getSystemResource(name.replace('.', '/') + ".class").openConnection().getInputStream(); ByteArrayOutputStream buffer=new ByteArrayOutputStream(); try { for (int input; (input=source.read())>=0; ) { buffer.write(input); } } catch (IOException i) { Whatever } byte[] classData=buffer.toByteArray(); > This appears to work (from watching the debugger pass through it), > although it is obviously quick'n'dirty. Most obviously, I'd like > to get rid of the 10M-sized array, but I don't think I can ask the > URL or the Stream about the exact size beforehand. --Mike Amling T25lIHJlYWQgZnJvbSBVUkwub3BlbkNvbm5lY3 Rpb24uZ2V0SW5wdXRTdHJlYW0gaXMgbm90IG5l Y2Vzc2FyaWx5IHN1ZmZpY2llbnQu