Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.main / src / test / java / org / gvsig / installer / main / DefaultLauncher.java @ 32401

History | View | Annotate | Download (2.35 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {Prodevelop}   {Task}
26
*/
27
 
28
package org.gvsig.installer.main;
29

    
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.io.FileOutputStream;
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.io.OutputStream;
36

    
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
39
 */
40
public class DefaultLauncher {
41

    
42
        public File getApplicationDirectory() throws IOException{
43
                File templateFile = new File(getClass().getClassLoader().getResource("application").getFile());
44
                File applicationDirectory = new File(System.getProperty("java.io.tmpdir") +  File.separator + "tmp_gvsig_installer");                
45
                
46
                copy(templateFile, applicationDirectory);
47
                
48
                return applicationDirectory;
49
        }
50
        
51
        public void copy(File sourceLocation , File targetLocation) throws IOException { 
52
                if (sourceLocation.isDirectory()) {
53
                        if (!targetLocation.exists()) {
54
                                targetLocation.mkdir();
55
                        }
56

    
57
                        String[] children = sourceLocation.list();
58
                        for (int i=0; i<children.length; i++) {
59
                                copy(new File(sourceLocation, children[i]),
60
                                                new File(targetLocation, children[i]));
61
                        }
62
                } else {
63
                        targetLocation.getParentFile().mkdirs();
64

    
65
                        InputStream in = new FileInputStream(sourceLocation);
66
                        OutputStream out = new FileOutputStream(targetLocation);
67

    
68
                        // Copy the bits from instream to outstream
69
                        byte[] buf = new byte[1024];
70
                        int len;
71
                        while ((len = in.read(buf)) > 0) {
72
                                out.write(buf, 0, len);
73
                        }
74
                        in.close();
75
                        out.close();
76
                }                 
77
        }
78
}
79