| 24 | import java.util.concurrent.atomic.AtomicBoolean; |
| 25 | |
| 26 | public class Uploader extends AsyncTask<UploadParams, int[], UploadResult> { |
| 27 | private UploadParams mParams; |
| 28 | private UploadResult res; |
| 29 | private AtomicBoolean mAbort = new AtomicBoolean(false); |
| 30 | |
| 31 | @Override |
| 32 | protected UploadResult doInBackground(UploadParams... uploadParams) { |
| 33 | mParams = uploadParams[0]; |
| 34 | res = new UploadResult(); |
| 35 | new Thread(new Runnable() { |
| 36 | @Override |
| 37 | public void run() { |
| 38 | try { |
| 39 | upload(mParams, res); |
| 40 | mParams.onUploadComplete.onUploadComplete(res); |
| 41 | } catch (Exception e) { |
| 42 | res.exception = e; |
| 43 | mParams.onUploadComplete.onUploadComplete(res); |
| 44 | } |
| 45 | } |
| 46 | }).start(); |
| 47 | return res; |
| 48 | } |
| 49 | |
| 50 | private void upload(UploadParams params, UploadResult result) throws Exception { |
| 51 | HttpURLConnection connection = null; |
| 52 | DataOutputStream request = null; |
| 53 | String crlf = "\r\n"; |
| 54 | String twoHyphens = "--"; |
| 55 | String boundary = "*****"; |
| 56 | String tail = crlf + twoHyphens + boundary + twoHyphens + crlf; |
| 57 | String metaData = "", stringData = ""; |
| 58 | String[] fileHeader; |
| 59 | int statusCode, byteSentTotal; |
| 60 | int fileCount = 0; |
| 61 | long totalFileLength = 0; |
| 62 | BufferedInputStream responseStream = null; |
| 63 | BufferedReader responseStreamReader = null; |
| 64 | String name, filename, filetype; |
| 65 | try { |
| 66 | Object[] files = params.files.toArray(); |
| 67 | boolean binaryStreamOnly = params.binaryStreamOnly; |
| 68 | |
| 69 | connection = (HttpURLConnection) params.src.openConnection(); |
| 70 | connection.setDoOutput(true); |
| 71 | ReadableMapKeySetIterator headerIterator = params.headers.keySetIterator(); |
| 72 | connection.setRequestMethod(params.method); |
| 73 | if (!binaryStreamOnly) { |
| 74 | connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); |
| 75 | } |
| 76 | while (headerIterator.hasNextKey()) { |
| 77 | String key = headerIterator.nextKey(); |
| 78 | String value = params.headers.getString(key); |
| 79 | connection.setRequestProperty(key, value); |
| 80 | } |
| 81 | |
| 82 | ReadableMapKeySetIterator fieldsIterator = params.fields.keySetIterator(); |
| 83 |
nothing calls this directly
no outgoing calls
no test coverage detected