]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/launcher/FileTransfer.java
Salome HOME
Run salome from KERNEL/bin/salome/ directory. Hibernate logging configuration is...
[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 public class FileTransfer {
12
13         private final static int SIZE = 1024;
14
15         public static void download(final String path, final String filename,
16                         final String destination) {
17                 URLConnection conx = null; // Communication link between the application and a URL.
18                 InputStream is = null;
19                 OutputStream os = null;
20                 try {
21                         URL url;
22                         byte[] buf;
23                         // int ByteWritten = 0;
24
25                         url = new URL(path);
26                         os = new BufferedOutputStream(new FileOutputStream(destination
27                                         + "/" + filename));
28                         // The URLConnection object is created by invoking the openConnection method on a URL.
29
30                         conx = url.openConnection();
31                         is = conx.getInputStream();
32                         buf = new byte[SIZE];
33                         int ByteRead = is.read(buf);
34                         while (ByteRead != -1) {
35                                 os.write(buf, 0, ByteRead);
36                                 ByteRead = is.read(buf);
37                         }
38                         // System.out.println("File \"" + filename + "\" successfully downloaded");
39                 } catch (Exception e) {
40                         e.printStackTrace(); // RKV: NOPMD: TODO: try to use logger
41                 } finally {
42                         try {
43                                 is.close();
44                                 os.close();
45                         } catch (IOException e) {
46                                 e.printStackTrace(); // RKV: NOPMD: TODO: try to use logger
47                         }
48                 }
49         }
50 }