MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / run

Method run

CodenameOne/src/com/codename1/io/Util.java:3196–3238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3194 public void actionPerformed(NetworkEvent evt) {
3195 mergeFilesThread.run(new Runnable() {
3196 @Override
3197 public void run() {
3198 try {
3199 // We append the just saved partial download to the fileName, if it exists
3200 if (FileSystemStorage.getInstance().exists(partialDownloadPath)) {
3201 InputStream in = null; //NOPMD CloseResource
3202 try {
3203 in = FileSystemStorage.getInstance().openInputStream(partialDownloadPath);
3204 Util.copyNoClose(in, out, 8192);
3205 } finally {
3206 Util.cleanup(in);
3207 }
3208 // before deleting the file, we check and update how much data we have actually downloaded
3209 downloadedTotalBytes.set(downloadedTotalBytes.get() + FileSystemStorage.getInstance().getLength(partialDownloadPath));
3210 FileSystemStorage.getInstance().delete(partialDownloadPath);
3211 }
3212 // Is the download finished?
3213 if (downloadedTotalBytes.get() > fileSize) {
3214 throw new IllegalStateException("More content has been downloaded than the file length, check the code.");
3215 }
3216 if (fileSize <= 0 || downloadedTotalBytes.get() == fileSize) {
3217 // yes, download finished
3218 Util.cleanup(out);
3219 if (filesavedCallback != null) {
3220 CN.callSerially(new Runnable() {
3221 @Override
3222 public void run() {
3223 filesavedCallback.completed(fileName);
3224 }
3225 });
3226 }
3227 } else {
3228 // no, it's not finished, we repeat the request after updating the "Range" header
3229 cr.addRequestHeader("Range", "bytes=" + downloadedTotalBytes.get() + "-" + (Math.min(downloadedTotalBytes.get() + splittingSize, fileSize)));
3230 NetworkManager.getInstance().addToQueue(cr);
3231 }
3232
3233 } catch (IOException ex) {
3234 Log.p("Error in appending splitted file to output file", Log.ERROR);
3235 Log.e(ex);
3236 Log.sendLogAsync();
3237 }
3238 }
3239 });
3240 }
3241 });

Callers

nothing calls this directly

Calls 15

getInstanceMethod · 0.95
copyNoCloseMethod · 0.95
cleanupMethod · 0.95
callSeriallyMethod · 0.95
minMethod · 0.95
getInstanceMethod · 0.95
pMethod · 0.95
eMethod · 0.95
sendLogAsyncMethod · 0.95
addRequestHeaderMethod · 0.80
existsMethod · 0.65
openInputStreamMethod · 0.65

Tested by

no test coverage detected