error "out of memory" in method readDebug at file, should return the 'is' InputStream in the parameter method.

private InputStream readDebug(InputStream is, int contentLength, File outputFile) throws IOException {
	        OutputStream bos;
	        if (outputFile != null) {
	            bos = new FileOutputStream(outputFile);
	        } else {
	            // If known use the size if not use default value
	            bos = new ByteArrayOutputStream( (contentLength > 0 ) ? contentLength : 256*1024);
	        }

	        byte[] buf = new byte[256];

	        while (true) {
	            int rd = is.read(buf, 0, 256);
	            if (rd == -1) {
	                break;
	            }
	            bos.write(buf, 0, rd);
	        }
	        
	        bos.flush();
	        
	        responseDump = bos.toString();
	        
	       /* if (bos instanceof ByteArrayOutputStream) {
	            buf = ((ByteArrayOutputStream) bos).toByteArray();
	        }
	        
	        bos = null;
	        responseDump = new String(buf);*/
	        if (outputFile != null) {
	            return new FileInputStream(outputFile);
	        } else {
	        	return is;
	        }
	        /*
	        is.close();
	        
	        if (outputFile != null) {
	            return new FileInputStream(outputFile);
	        } else {
	        	
	            return new ByteArrayInputStream(buf);
	        }*/
	   }