Salome HOME
SIMAN Eclipse workspace first version
[tools/siman.git] / Workspace / Siman / src / org / splat / launcher / FileTransfer.java
1 package org.splat.launcher;
2
3 import java.io.BufferedOutputStream;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8 import java.net.URL;
9 import java.net.URLConnection;
10
11
12 public class FileTransfer {
13
14     final static int size = 1024;
15
16     public static void Download (String path, String filename, String destination) {
17 //  ------------------------------------------------------------------------------
18       URLConnection conx = null;   // Communication link between the application and a URL.
19       InputStream   is   = null;
20       OutputStream  os   = null;
21       try {
22         URL    url;
23         byte[] buf;
24         int    ByteRead    = 0;
25 //      int    ByteWritten = 0;
26
27         url  = new URL(path);
28         os   = new BufferedOutputStream( new FileOutputStream(destination + "/" + filename) );
29 //      The URLConnection object is created by invoking the openConnection method on a URL.
30
31         conx = url.openConnection();
32         is   = conx.getInputStream();
33         buf  = new byte[size];
34         while ((ByteRead = is.read(buf)) != -1) {
35           os.write(buf, 0, ByteRead);
36 //        ByteWritten += ByteRead;
37         }
38 //      System.out.println("File \"" + filename + "\" successfully downloaded");
39       }
40       catch (Exception e) {
41         e.printStackTrace();
42       }
43       finally {
44         try {
45           is.close();
46           os.close();
47         }
48         catch (IOException e) {
49           e.printStackTrace();
50         }
51       }
52     }
53 }