List of usage examples for java.util Map toString
public String toString()
From source file:com.swcguild.springmvcwebapp.controller.InterCalcController.java
@RequestMapping(value = "/intercalc", method = RequestMethod.POST) public String doPost(HttpServletRequest request, Model model) { try {/* w w w . j a v a2s . c om*/ originalBalance = Double.parseDouble(request.getParameter("myAnswer")); startingBalance = originalBalance; intRate = Double.parseDouble(request.getParameter("myRate")); numYears = Double.parseDouble(request.getParameter("myYears")); numPeriods = Double.parseDouble(request.getParameter("myPeriods")); message = ""; //totalInterest; //newBalance; //List<Map> annualInterest = new ArrayList<>(); Map yearMap = new HashMap<>(); DecimalFormat df = new DecimalFormat("#.00"); int yearCount = 0; do { newBalance = originalBalance * (Math.pow(1 + ((intRate * .01) / numPeriods), (numPeriods))); yearCount++; double interestPerYear = newBalance - originalBalance; String interestPerYearString = df.format(interestPerYear); yearMap.put(yearCount, interestPerYearString); originalBalance = newBalance; } while (yearCount <= (numYears - 1)); totalInterest = newBalance - startingBalance; //annualInterest.add(yearMap); String annualInterestString = yearMap.toString().replace("{", "").replace("}", "").trim(); model.addAttribute("originalBalance", df.format(startingBalance)); model.addAttribute("newBalance", df.format(newBalance)); model.addAttribute("interestRate", intRate); model.addAttribute("interestEarned", df.format(totalInterest)); model.addAttribute("years", df.format(numYears)); model.addAttribute("periods", df.format(numPeriods)); model.addAttribute("annualInterest", yearMap); } catch (NumberFormatException e) { } return "intercalcResponse"; //<td><c:out value="${current.id}" /><td> }
From source file:com.prey.net.PreyRestHttpClient.java
public PreyHttpResponse put(String url, Map<String, String> params, PreyConfig preyConfig) throws IOException { HttpPut method = new HttpPut(url); method.setHeader("Accept", "*/*"); method.setEntity(new UrlEncodedFormEntity(getHttpParamsFromMap(params), HTTP.UTF_8)); // method.setParams(getHttpParamsFromMap(params)); PreyLogger.d("Sending using 'PUT' - URI: " + url + " - parameters: " + params.toString()); HttpResponse httpResponse = httpclient.execute(method); PreyHttpResponse response = new PreyHttpResponse(httpResponse); //PreyLogger.d("Response from server: " + response.toString()); return response; }
From source file:com.motorola.motoask.gcm.server.Sender.java
/** * Sends a message without retrying in case of service unavailability. See * {@link #send(Message, List, int)} for more info. * * @return multicast results if the message was sent successfully, * {@literal null} if it failed but could be retried. * * @throws IllegalArgumentException if registrationIds is {@literal null} or * empty.//w ww. ja v a 2s . com * @throws InvalidRequestException if GCM didn't returned a 200 status. * @throws IOException if there was a JSON parsing error */ public MulticastResult sendNoRetry(Message message, List<String> registrationIds) throws IOException { logger.info("sendNoRetry()"); if (nonNull(registrationIds).isEmpty()) { throw new IllegalArgumentException("registrationIds cannot be empty"); } Map<Object, Object> jsonRequest = new HashMap<Object, Object>(); //setJsonField(jsonRequest, PARAM_TIME_TO_LIVE, message.getTimeToLive()); setJsonField(jsonRequest, PARAM_COLLAPSE_KEY, message.getCollapseKey()); //setJsonField(jsonRequest, PARAM_RESTRICTED_PACKAGE_NAME, message.getRestrictedPackageName()); setJsonField(jsonRequest, PARAM_DELAY_WHILE_IDLE, message.isDelayWhileIdle()); //setJsonField(jsonRequest, PARAM_DRY_RUN, message.isDryRun()); jsonRequest.put(JSON_REGISTRATION_IDS, registrationIds); Map<String, String> payload = message.getData(); if (!payload.isEmpty()) { logger.info("payload is ok" + payload.toString()); jsonRequest.put(JSON_PAYLOAD, payload); } else { logger.info("payload is fucking empty!!"); } String requestBody = JSONValue.toJSONString(jsonRequest); logger.info("JSON request: " + requestBody); HttpURLConnection conn; int status; try { conn = post(GCM_SEND_ENDPOINT, "application/json", requestBody); status = conn.getResponseCode(); logger.info("status is " + status); } catch (IOException e) { logger.log(Level.SEVERE, "IOException posting to GCM", e); return null; } String responseBody; if (status != 200) { try { responseBody = getAndClose(conn.getErrorStream()); logger.info("JSON error response: " + responseBody); } catch (IOException e) { // ignore the exception since it will thrown an InvalidRequestException // anyways responseBody = "N/A"; logger.log(Level.INFO, "Exception reading response: ", e); } throw new InvalidRequestException(status, responseBody); } try { responseBody = getAndClose(conn.getInputStream()); } catch (IOException e) { logger.log(Level.WARNING, "IOException reading response", e); return null; } logger.info("JSON response: " + responseBody); JSONParser parser = new JSONParser(); JSONObject jsonResponse; try { jsonResponse = (JSONObject) parser.parse(responseBody); int success = getNumber(jsonResponse, JSON_SUCCESS).intValue(); int failure = getNumber(jsonResponse, JSON_FAILURE).intValue(); int canonicalIds = getNumber(jsonResponse, JSON_CANONICAL_IDS).intValue(); long multicastId = getNumber(jsonResponse, JSON_MULTICAST_ID).longValue(); MulticastResult.Builder builder = new MulticastResult.Builder(success, failure, canonicalIds, multicastId); @SuppressWarnings("unchecked") List<Map<String, Object>> results = (List<Map<String, Object>>) jsonResponse.get(JSON_RESULTS); if (results != null) { for (Map<String, Object> jsonResult : results) { String messageId = (String) jsonResult.get(JSON_MESSAGE_ID); String canonicalRegId = (String) jsonResult.get(TOKEN_CANONICAL_REG_ID); String error = (String) jsonResult.get(JSON_ERROR); Result result = new Result.Builder().messageId(messageId) .canonicalRegistrationId(canonicalRegId).errorCode(error).build(); builder.addResult(result); } } MulticastResult multicastResult = builder.build(); return multicastResult; } catch (ParseException e) { throw newIoException(responseBody, e); } catch (CustomParserException e) { throw newIoException(responseBody, e); } }
From source file:be.solidx.hot.rest.RestController.java
protected ResponseEntity<byte[]> buildResponse(Map content, Map headers, Integer httpStatus, Charset requestedEncoding) { try {/* w w w. j av a 2 s.c o m*/ HttpHeaders httpHeaders = buildHttpHeaders(headers); List<String> contentType = httpHeaders.get(com.google.common.net.HttpHeaders.CONTENT_TYPE); if (contentType != null && contentType.size() > 0 && contentType.contains(MediaType.APPLICATION_JSON_VALUE)) { return new ResponseEntity<byte[]>(objectMapper.writeValueAsBytes(content), httpHeaders, HttpStatus.valueOf(httpStatus)); } else { return new ResponseEntity<byte[]>(content.toString().getBytes(requestedEncoding), httpHeaders, HttpStatus.valueOf(httpStatus)); } } catch (Exception e) { logger.error("", e); return new ResponseEntity<byte[]>(e.getMessage().toString().getBytes(requestedEncoding), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:net.di2e.ecdr.source.rest.AbstractCDRSource.java
public void setSortMap(String sortMapStr) { Map<String, String> convertedMap = SearchUtils.convertToMap(sortMapStr); LOGGER.debug("Updating sortMap with new entries: {}", convertedMap.toString()); sortMap = convertedMap;/* ww w .j a va 2 s. c o m*/ }
From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java
/** * ?? ??./* w ww . j a va2 s. com*/ * * @param request * * @param response * ? * @throws Exception * */ protected void view(HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO; fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); }
From source file:monasca.persister.pipeline.event.MetricHandler.java
private int processEnvelope(MetricEnvelope metricEnvelope) { int metricCount = 0; Metric metric = metricEnvelope.metric; Map<String, Object> meta = metricEnvelope.meta; logger.debug("ordinal: {}", ordinal); logger.debug("metric: {}", metric); logger.debug("meta: {}", meta); String tenantId = ""; if (meta.containsKey(TENANT_ID)) { tenantId = (String) meta.get(TENANT_ID); } else {// ww w . jav a2 s. c o m logger.warn( "Failed to find tenantId in message envelope meta data. Metric message may be malformed. Setting tenantId to empty string."); logger.warn("metric: {}", metric.toString()); logger.warn("meta: {}", meta.toString()); } String region = ""; if (meta.containsKey(REGION)) { region = (String) meta.get(REGION); } else { logger.warn( "Failed to find region in message envelope meta data. Metric message may be malformed. Setting region to empty string."); logger.warn("metric: {}", metric.toString()); logger.warn("meta: {}", meta.toString()); } // Add the definition to the batch. StringBuilder definitionIdStringToHash = new StringBuilder(trunc(metric.getName(), MAX_COLUMN_LENGTH)); definitionIdStringToHash.append(trunc(tenantId, MAX_COLUMN_LENGTH)); definitionIdStringToHash.append(trunc(region, MAX_COLUMN_LENGTH)); byte[] definitionIdSha1Hash = DigestUtils.sha(definitionIdStringToHash.toString()); Sha1HashId definitionSha1HashId = new Sha1HashId((definitionIdSha1Hash)); verticaMetricRepository.addDefinitionToBatch(definitionSha1HashId, trunc(metric.getName(), MAX_COLUMN_LENGTH), trunc(tenantId, MAX_COLUMN_LENGTH), trunc(region, MAX_COLUMN_LENGTH)); definitionCounter.inc(); // Calculate dimensions sha1 hash id. StringBuilder dimensionIdStringToHash = new StringBuilder(); Map<String, String> preppedDimMap = prepDimensions(metric.getDimensions()); for (Map.Entry<String, String> entry : preppedDimMap.entrySet()) { dimensionIdStringToHash.append(entry.getKey()); dimensionIdStringToHash.append(entry.getValue()); } byte[] dimensionIdSha1Hash = DigestUtils.sha(dimensionIdStringToHash.toString()); Sha1HashId dimensionsSha1HashId = new Sha1HashId(dimensionIdSha1Hash); // Add the dimension name/values to the batch. for (Map.Entry<String, String> entry : preppedDimMap.entrySet()) { verticaMetricRepository.addDimensionToBatch(dimensionsSha1HashId, entry.getKey(), entry.getValue()); dimensionCounter.inc(); } // Add the definition dimensions to the batch. StringBuilder definitionDimensionsIdStringToHash = new StringBuilder(definitionSha1HashId.toHexString()); definitionDimensionsIdStringToHash.append(dimensionsSha1HashId.toHexString()); byte[] definitionDimensionsIdSha1Hash = DigestUtils.sha(definitionDimensionsIdStringToHash.toString()); Sha1HashId definitionDimensionsSha1HashId = new Sha1HashId(definitionDimensionsIdSha1Hash); verticaMetricRepository.addDefinitionDimensionToBatch(definitionDimensionsSha1HashId, definitionSha1HashId, dimensionsSha1HashId); definitionDimensionsCounter.inc(); // Add the measurements to the batch. if (metric.getTimeValues() != null) { for (double[] timeValuePairs : metric.getTimeValues()) { String timeStamp = simpleDateFormat.format(new Date((long) (timeValuePairs[0] * 1000))); double value = timeValuePairs[1]; verticaMetricRepository.addMetricToBatch(definitionDimensionsSha1HashId, timeStamp, value); metricCounter.inc(); metricCount++; } } else { String timeStamp = simpleDateFormat.format(new Date(metric.getTimestamp() * 1000)); String value = metric.getValue(); verticaMetricRepository.addMetricToBatch(definitionDimensionsSha1HashId, timeStamp, value); metricCounter.inc(); metricCount++; } return metricCount; }
From source file:com.trigger_context.Main_Service.java
private void takeAction(String mac, InetAddress ip) { noti("comes to ", mac); SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); Main_Service.main_Service.noti(cond_map.toString(), ""); if (key_set.contains("SmsAction")) { String number = conditions.getString("SmsActionNumber", null); String message = conditions.getString("SmsActionMessage", null); try {/*w ww. java 2s. c o m*/ SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, message, null, null); noti("Sms Sent To : ", "" + number); } catch (Exception e) { noti("Sms Sending To ", number + "Failed"); } } if (key_set.contains("OpenWebsiteAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Open_Url.class); dialogIntent.putExtra("urlAction", (String) cond_map.get("urlAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("ToggleAction")) { if (key_set.contains("bluetoothAction") && conditions.getBoolean("bluetoothAction", false)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.enable(); } else if (key_set.contains("bluetoothAction")) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } if (key_set.contains("wifiAction") && conditions.getBoolean("wifiAction", false)) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } else if (key_set.contains("wifiAction")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(false); } } if (key_set.contains("TweetAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Post_Tweet.class); dialogIntent.putExtra("tweetTextAction", (String) cond_map.get("tweetTextAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("EmailAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Email_Client.class); dialogIntent.putExtra("toAction", (String) cond_map.get("toAction")); dialogIntent.putExtra("subjectAction", (String) cond_map.get("subjectAction")); dialogIntent.putExtra("emailMessageAction", (String) cond_map.get("emailMessageAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("RemoteServerCmd")) { String text = conditions.getString("cmd", null); new Thread(new SendData("224.0.0.1", 9876, text)).start(); } // network activities from here. // in all network actions send username first if (key_set.contains("FileTransferAction")) { String path = conditions.getString("filePath", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 1 try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(1); sendFile(out, path); noti("Sent " + path + " file to :", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("ccfMsgAction")) { String msg = conditions.getString("ccfMsg", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 2 is msg try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(2); out.writeUTF(msg); noti("Sent msg : '" + msg + "'", "to : " + getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("sync")) { SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 3 is sync try { Socket socket = new Socket(ip, COMM_PORT); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(3); senderSync(in, out, Environment.getExternalStorageDirectory().getPath() + "/TriggerSync/"); noti("Synced with:", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java
/** * ?? .</br> ? ? ?? ? , (: ?) ? mapId . ? * ?? ? repositoryType , ?/*from ww w . ja v a 2 s . co m*/ * org.codelabor.system.file.RepositoryType . * * @param request * * @param response * ? * @throws Exception * */ @SuppressWarnings("unchecked") protected void upload(HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); boolean isMultipart = ServletFileUpload.isMultipartContent(request); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String mapId = (String) paramMap.get("mapId"); RepositoryType acceptedRepositoryType = repositoryType; String requestedRepositoryType = (String) paramMap.get("repositoryType"); if (StringUtils.isNotEmpty(requestedRepositoryType)) { acceptedRepositoryType = RepositoryType.valueOf(requestedRepositoryType); } if (isMultipart) { DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(sizeThreshold); factory.setRepository(new File(tempRepositoryPath)); factory.setFileCleaningTracker(FileCleanerCleanup.getFileCleaningTracker(this.getServletContext())); ServletFileUpload upload = new ServletFileUpload(factory); upload.setFileSizeMax(fileSizeMax); upload.setSizeMax(requestSizeMax); upload.setHeaderEncoding(characterEncoding); upload.setProgressListener(new FileUploadProgressListener()); try { List<FileItem> fileItemList = upload.parseRequest(request); Iterator<FileItem> iter = fileItemList.iterator(); while (iter.hasNext()) { FileItem fileItem = iter.next(); logger.debug("fileItem: {}", fileItem.toString()); FileDTO fileDTO = null; if (fileItem.isFormField()) { paramMap.put(fileItem.getFieldName(), fileItem.getString(characterEncoding)); } else { if (fileItem.getName() == null || fileItem.getName().length() == 0) continue; // set DTO fileDTO = new FileDTO(); fileDTO.setMapId(mapId); fileDTO.setRealFilename(FilenameUtils.getName(fileItem.getName())); if (acceptedRepositoryType == RepositoryType.FILE_SYSTEM) { fileDTO.setUniqueFilename(getUniqueFilename()); } fileDTO.setContentType(fileItem.getContentType()); fileDTO.setRepositoryPath(realRepositoryPath); logger.debug("fileDTO: {}", fileDTO.toString()); UploadUtils.processFile(acceptedRepositoryType, fileItem.getInputStream(), fileDTO); } if (fileDTO != null) fileManager.insertFile(fileDTO); } } catch (FileUploadException e) { e.printStackTrace(); logger.error(e.getMessage()); throw e; } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); throw e; } } else { paramMap = RequestUtils.getParameterMap(request); } try { processParameters(paramMap); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); throw e; } dispatch(request, response, forwardPathUpload); }
From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java
/** * ?? ./* ww w .j a v a 2 s . co m*/ * * @param request * * @param response * ? * @throws Exception * */ protected void download(HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO; fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); response.setContentType(org.codelabor.system.file.FileConstants.CONTENT_TYPE); sb.setLength(0); if (request.getHeader(HttpRequestHeaderConstants.USER_AGENT).indexOf("MSIE5.5") > -1) { sb.append("filename="); } else { sb.append("attachment; filename="); } sb.append(encodedRealFilename); response.setHeader(HttpResponseHeaderConstants.CONTENT_DISPOSITION, sb.toString()); logger.debug("header: {}", sb.toString()); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); }