private boolean getTaskFileInfo(Task task) { URL url = null; try { url = new URL(task.url); urlConnection = (HttpURLConnection) url.openConnection(); if (urlConnection == null) { // MyExtension.AS3_CONTEXT.dispatchStatusEventAsync( // DispatchEcode.EXCEPTION, DispatchElevel.OPEN_CONNECTION); Log.d(DispatchEcode.EXCEPTION, DispatchElevel.OPEN_CONNECTION); return false; } } catch (MalformedURLException e) { e.printStackTrace(); // MyExtension.AS3_CONTEXT.dispatchStatusEventAsync( // DispatchEcode.EXCEPTION, DispatchElevel.URL_INVALID); Log.d(DispatchEcode.EXCEPTION, DispatchElevel.URL_INVALID); return false; } catch (IOException e) { e.printStackTrace(); // MyExtension.AS3_CONTEXT.dispatchStatusEventAsync( // DispatchEcode.EXCEPTION, DispatchElevel.OPEN_CONNECTION); Log.d(DispatchEcode.EXCEPTION, DispatchElevel.OPEN_CONNECTION); return false; } if (urlConnection != null) { task.size = urlConnection.getContentLength(); task.extension = MimeTypeMap.getFileExtensionFromUrl(task.url); } else { // MyExtension.AS3_CONTEXT.dispatchStatusEventAsync( // DispatchEcode.EXCEPTION, DispatchElevel.CONNECTION_ERROR); Log.d(DispatchEcode.EXCEPTION, DispatchElevel.CONNECTION_ERROR); return false; } // Log.d("-------", "anything goes right"); return true; }
private void convertTaskToChunks(Task task) { if (task.size == 0) { // it's NOT resumable!! // one chunk task.resumable = false; task.chunks = 1; } else { // resumable // depend on file size assign number of chunks; up to Maximum user task.resumable = true; int MaximumUserCHUNKS = task.chunks / 2; task.chunks = 1; for (int f = 1; f <= MaximumUserCHUNKS; f++) if (task.size > MegaByte * f) task.chunks = f * 2; } // Change Task State int firstChunkID = chunksDataSource.insertChunks(task); makeFileForChunks(firstChunkID, task); task.state = TaskStates.READY; tasksDataSource.update(task); }