Source:
<code>public static void getFileFromServer(String path, Bundle params, String filePath) { byte[] bf = new byte[FILE_BUFFER_SIZE]; int current = 0; InputStream is = null; HttpURLConnection connect = null; BufferedInputStream bis = null; OutputStream fos = null; try { fos = new FileOutputStream(filePath); String completePath = null; if (params != null) { StringBuilder sb = new StringBuilder(); sb.append(path).append('?'); boolean first = true; for (String key : params.keySet()) { if (!first) { sb.append('&'); } else { first = false; } sb.append(URLEncoder.encode(key)) .append('=') .append(URLEncoder.encode(params.getString(key))); } completePath = sb.toString(); } <START> <END> URL url = new URL(completePath); connect = (HttpURLConnection) url.openConnection(); connect.setDoInput(true); connect.setConnectTimeout(CONNECTION_TIME_OUT); connect.setReadTimeout(SOCKET_TIME_OUT); int code = connect.getResponseCode(); if (code == HttpURLConnection.HTTP_OK) { is = connect.getInputStream(); bis = new BufferedInputStream(is); while ((current = bis.read(bf)) != FILE_END) { fos.write(bf, 0, current); } } } catch (MalformedURLException e) { LogUtils.logD(e.getMessage()); } catch (IOException e) { LogUtils.logD(e.getMessage()); } catch (Exception e) { LogUtils.logD(e.getMessage()); } finally { try { if (bis != null) { bis.close(); } if (is != null) { is.close(); } if (fos != null) { fos.close(); } if (connect != null) { connect.disconnect(); } } catch (IOException e) { LogUtils.logD(e.getMessage()); } } }</code><technical_language>If params is null, completePath null. If params is empty, completePath "path?" cases right</technical_language>

Target:
public static boolean getFileFromServer(String path, Bundle params, String filePath) { byte[] bf = new byte[FILE_BUFFER_SIZE]; int current = 0; InputStream is = null; HttpURLConnection connect = null; BufferedInputStream bis = null; OutputStream fos = null; try { fos = new FileOutputStream(filePath); String completePath = path; if(params != null && !params.isEmpty()){ StringBuilder sb = new StringBuilder(); sb.append(path).append('?'); boolean first = true; for (String key : params.keySet()) { if (!first) { sb.append('&'); } else { first = false; } sb.append(URLEncoder.encode(key)) .append('=') .append(URLEncoder.encode(params.getString(key))); } completePath = sb.toString(); } URL url = new URL(completePath); connect = (HttpURLConnection) url.openConnection(); connect.setDoInput(true); connect.setConnectTimeout(CONNECTION_TIME_OUT); connect.setReadTimeout(SOCKET_TIME_OUT); int code = connect.getResponseCode(); if (code == HttpURLConnection.HTTP_OK) { is = connect.getInputStream(); bis = new BufferedInputStream(is); while ((current = bis.read(bf)) != FILE_END) { fos.write(bf, 0, current); } } return true; } catch (MalformedURLException e) { LogUtils.logE(e.getMessage()); return false; } catch (IOException e) { LogUtils.logE(e.getMessage()); return false; } catch (Exception e) { LogUtils.logE(e.getMessage()); return false; } finally { try { if (bis != null) { bis.close(); } if (is != null) { is.close(); } if (fos != null) { fos.close(); } if (connect != null) { connect.disconnect(); } } catch (IOException e) { LogUtils.logE(e.getMessage()); } } }