69 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
70 |
|
|
71 |
boolean isFirst = true; |
boolean isFirst = true; |
72 |
for (String key : params.keySet()) { |
for (Map.Entry<String,String> entry : params.entrySet()) { |
73 |
if (isFirst) { |
if (isFirst) { |
74 |
isFirst = false; |
isFirst = false; |
75 |
} else { |
} else { |
76 |
sb.append("&"); |
sb.append("&"); |
77 |
} |
} |
78 |
|
|
79 |
String val = params.get(key); |
|
80 |
sb.append(key); |
sb.append( entry.getKey() ); |
81 |
sb.append("="); |
sb.append("="); |
82 |
sb.append( encode(val) ); |
sb.append( encode( entry.getValue() ) ); |
83 |
|
|
84 |
|
|
85 |
} |
} |
114 |
URLConnection connection = url.openConnection(); |
URLConnection connection = url.openConnection(); |
115 |
|
|
116 |
connection.setConnectTimeout(timeout); |
connection.setConnectTimeout(timeout); |
117 |
|
connection.setReadTimeout(timeout); |
118 |
InputStream is = connection.getInputStream(); |
InputStream is = connection.getInputStream(); |
119 |
|
|
120 |
return readInputStream(is); |
return readInputStream(is); |
138 |
|
|
139 |
static byte[] readInputStream(InputStream is) throws IOException{ |
static byte[] readInputStream(InputStream is) throws IOException{ |
140 |
byte buffer[] = new byte[1024]; |
byte buffer[] = new byte[1024]; |
141 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
//try /; //start buffer size - instead of default 32bytes |
142 |
try { |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(32768)) { |
143 |
int count; |
int count; |
144 |
|
|
145 |
while ( (count = is.read(buffer)) != -1) { |
while ( (count = is.read(buffer)) != -1) { |
146 |
baos.write(buffer, 0, count); |
baos.write(buffer, 0, count); |
147 |
} |
} |
148 |
} finally { |
is.close(); |
149 |
try { |
return baos.toByteArray(); |
150 |
is.close(); |
} |
|
baos.close(); |
|
|
} catch (Exception e) {} //never mind if close throws an exception |
|
|
} |
|
|
|
|
|
return baos.toByteArray(); |
|
151 |
} |
} |
152 |
|
|
153 |
} |
} |