equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Sun designates this |
7 * published by the Free Software Foundation. Sun designates this |
42 import java.lang.reflect.AccessibleObject; |
42 import java.lang.reflect.AccessibleObject; |
43 import java.lang.reflect.Modifier; |
43 import java.lang.reflect.Modifier; |
44 import java.util.Collection; |
44 import java.util.Collection; |
45 import java.util.HashMap; |
45 import java.util.HashMap; |
46 import java.util.Map; |
46 import java.util.Map; |
|
47 import sun.misc.IOUtils; |
47 import sun.net.www.ParseUtil; |
48 import sun.net.www.ParseUtil; |
48 import sun.security.util.SecurityConstants; |
49 import sun.security.util.SecurityConstants; |
49 |
50 |
50 |
51 |
51 class Trampoline { |
52 class Trampoline { |
371 int len = uc.getContentLength(); |
372 int len = uc.getContentLength(); |
372 InputStream in = new BufferedInputStream(uc.getInputStream()); |
373 InputStream in = new BufferedInputStream(uc.getInputStream()); |
373 |
374 |
374 byte[] b; |
375 byte[] b; |
375 try { |
376 try { |
376 if (len != -1) { |
377 b = IOUtils.readFully(in, len, true); |
377 // Read exactly len bytes from the input stream |
|
378 b = new byte[len]; |
|
379 while (len > 0) { |
|
380 int n = in.read(b, b.length - len, len); |
|
381 if (n == -1) { |
|
382 throw new IOException("unexpected EOF"); |
|
383 } |
|
384 len -= n; |
|
385 } |
|
386 } else { |
|
387 b = new byte[8192]; |
|
388 int total = 0; |
|
389 while ((len = in.read(b, total, b.length - total)) != -1) { |
|
390 total += len; |
|
391 if (total >= b.length) { |
|
392 byte[] tmp = new byte[total * 2]; |
|
393 System.arraycopy(b, 0, tmp, 0, total); |
|
394 b = tmp; |
|
395 } |
|
396 } |
|
397 // Trim array to correct size, if necessary |
|
398 if (total != b.length) { |
|
399 byte[] tmp = new byte[total]; |
|
400 System.arraycopy(b, 0, tmp, 0, total); |
|
401 b = tmp; |
|
402 } |
|
403 } |
|
404 } finally { |
378 } finally { |
405 in.close(); |
379 in.close(); |
406 } |
380 } |
407 return b; |
381 return b; |
408 } |
382 } |