/[projects]/dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/HttpUtil.java
ViewVC logotype

Diff of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/HttpUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

dao/DaoAdresseService/src/dk/daoas/daoadresseservice/util/HttpUtil.java revision 2321 by torben, Tue Feb 17 09:06:42 2015 UTC dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/HttpUtil.java revision 2531 by torben, Fri May 8 20:25:12 2015 UTC
# Line 69  public class HttpUtil { Line 69  public class HttpUtil {
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                  }                  }
# Line 114  public class HttpUtil { Line 114  public class HttpUtil {
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);
# Line 137  public class HttpUtil { Line 138  public class HttpUtil {
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  }  }

Legend:
Removed from v.2321  
changed lines
  Added in v.2531

  ViewVC Help
Powered by ViewVC 1.1.20