Code example for ByteArrayOutputStream

Methods: closetoByteArray

0
                HttpGet get = new HttpGet(url);
                request = get;
            } else if (method.equals("POST")) {
                HttpPost post = new HttpPost(url);
                byte[] data = null;
                bos = new ByteArrayOutputStream(1024 * 50);
                if (!TextUtils.isEmpty(file)) {
                    Utility.paramToUpload(bos, params);
                    post.setHeader("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY);
                    Bitmap bf = BitmapFactory.decodeFile(file);
 
                    Utility.imageContentToUpload(bos, bf);
 
                } else { 
                    post.setHeader("Content-Type", "application/x-www-form-urlencoded");
                    String postParam = encodeParameters(params);
                    data = postParam.getBytes("UTF-8");
                    bos.write(data);
                } 
                data = bos.toByteArray();
                bos.close();
                // UrlEncodedFormEntity entity = getPostParamters(params); 
                ByteArrayEntity formEntity = new ByteArrayEntity(data);
                post.setEntity(formEntity);
                request = post;
            } else if (method.equals("DELETE")) {