wiki:Client/Development/ReceivingResults

Receiving a result (Java)

To receive a result zip file you have two options again:

  1. Download the file in 80 kB parts with startResultDownload and continueResultDownload, which again allows aborting and showing the progress of the transfer, but transfers 1.34 times the data as the other option. Again this is probably the option preferred for user clients.
            File zipfile = null;
            FileOutputStream output = null;
            
            try {
                File resultDir = new File(resultDirName);
                if(!resultDir.exists()) resultDir.mkdirs();
                zipfile = File.createTempFile("jplagtmpresult",".zip");
                
                output = new FileOutputStream(zipfile);
                
                StartResultDownloadData srdd = stub.startResultDownload(
                    submissionID);

                int filesize = srdd.getFilesize();
                int loadedsize = srdd.getData().length;

                initProgressBar(srdd.getFilesize());
                output.write(srdd.getData());
                setProgressBarValue(loadedsize);
                
                while(loadedsize<filesize) {
                    byte[] data = stub.continueResultDownload(0);
                    output.write(data);
                    loadedsize += data.length;
                    setProgressBarValue(loadedsize);
                }
                output.close();
                
                /*
                 * Unzip result archive and delete the zip file
                 */
                
                ZipUtil.unzip(zipfile, resultDir);
                zipfile.delete();
            }
            catch(Exception e) {
                if(output != null) {
                    try { output.close(); } catch(Exception ex) {}
                }
                if(zipfile != null) zipfile.delete();
                checkException(e);
                return false;
            }            
                
            return true;
  1. Download the file in one piece with getResult without being able to abort or show progress, but with a better transfer rate, using a MimeMultipart? object. Again this should be preferred for clients without user interaction.
            File zipfile = null;
            FileOutputStream output = null;
            
            try {
                File resultDir = new File(resultDirName);
                if(!resultDir.exists()) resultDir.mkdirs();
                zipfile = File.createTempFile("jplagtmpresult",".zip");
                
                MimeMultipart resultMultipart = stub.getResult(submissionID);
                
                MimeBodyPart bdp = (MimeBodyPart) resultMultipart.getBodyPart(0);
                DataHandler dh = bdp.getDataHandler();
                output = new FileOutputStream(zipfile);
                dh.writeTo(output);
                output.close();
                
                /*
                 * Unzip result archive and delete the zip file
                 */
                
                ZipUtil.unzip(zipfile, resultDir);
                zipfile.delete();
                
                /*
                 * Result successfully downloaded and unzipped,
                 * so remove it from server now
                 */
                stub.cancelSubmission(submissionID);
            }
            catch(Exception e) {
                if(output != null) {
                    try { output.close(); } catch(Exception ex) {}
                }
                if(zipfile != null) zipfile.delete();
                checkException(e);
                return false;
            }            
                
            return true;

Note that you have to remove the result files from the server manually using this method.

Next: The example client

Last modified 5 years ago Last modified on Dec 7, 2012 11:02:56 AM