Package org.mage.plugins.card.dl.DownloadJob

Examples of org.mage.plugins.card.dl.DownloadJob.Destination


                if(job.getState() != State.NEW) return;
                job.setState(State.WORKING);
            }
            try {
                Source src = job.getSource();
                Destination dst = job.getDestination();
                BoundedRangeModel progress = job.getProgress();
               
                if(dst.exists()) {
                    progress.setMaximum(1);
                    progress.setValue(1);
                } else {
                    progress.setMaximum(src.length());
                    InputStream is = new BufferedInputStream(src.open());
                    try {
                        OutputStream os = new BufferedOutputStream(dst.open());
                        try {
                            byte[] buf = new byte[8 * 1024];
                            int total = 0;
                            for(int len; (len = is.read(buf)) != -1;) {
                                if(job.getState() == State.ABORTED) throw new IOException("Job was aborted");
                                progress.setValue(total += len);
                                os.write(buf, 0, len);
                            }
                        } catch(IOException ex) {
                            try {
                                dst.delete();
                            } catch(IOException ex1) {
                                log.warn("While deleting", ex1);
                            }
                            throw ex;
                        } finally {
View Full Code Here


                }
                job.setState(State.WORKING);
            }
            try {
                Source src = job.getSource();
                Destination dst = job.getDestination();
                BoundedRangeModel progress = job.getProgress();

                if(dst.exists()) {
                    progress.setMaximum(1);
                    progress.setValue(1);
                } else {
                    progress.setMaximum(src.length());
                    InputStream is = new BufferedInputStream(src.open());
                    try {
                        OutputStream os = new BufferedOutputStream(dst.open());
                        try {
                            byte[] buf = new byte[8 * 1024];
                            int total = 0;
                            for(int len; (len = is.read(buf)) != -1;) {
                                if(job.getState() == State.ABORTED) {
                                    throw new IOException("Job was aborted");
                                }
                                progress.setValue(total += len);
                                os.write(buf, 0, len);
                            }
                        } catch(IOException ex) {
                            try {
                                dst.delete();
                            } catch(IOException ex1) {
                                logger.warn("While deleting", ex1);
                            }
                            throw ex;
                        } finally {
View Full Code Here

TOP

Related Classes of org.mage.plugins.card.dl.DownloadJob.Destination

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.