Revision 32420 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/test/java/org/gvsig/installer/lib/impl/InstallerServiceTest.java
InstallerServiceTest.java | ||
---|---|---|
27 | 27 |
|
28 | 28 |
package org.gvsig.installer.lib.impl; |
29 | 29 |
|
30 |
import java.io.BufferedReader; |
|
30 |
import java.io.BufferedOutputStream; |
|
31 |
import java.io.DataOutputStream; |
|
31 | 32 |
import java.io.File; |
32 | 33 |
import java.io.FileInputStream; |
33 | 34 |
import java.io.FileOutputStream; |
34 |
import java.io.FileReader; |
|
35 | 35 |
import java.io.IOException; |
36 | 36 |
import java.io.InputStream; |
37 | 37 |
import java.io.OutputStream; |
... | ... | |
42 | 42 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
43 | 43 |
*/ |
44 | 44 |
public abstract class InstallerServiceTest extends AbstractLibraryAutoInitTestCase{ |
45 |
private boolean isCopied = false; |
|
46 | 45 |
|
47 |
|
|
48 | 46 |
public File getApplicationDirectory() throws IOException{ |
49 | 47 |
File templateFile = new File(getClass().getClassLoader().getResource("application").getFile()); |
50 | 48 |
File applicationDirectory = new File(System.getProperty("java.io.tmpdir") + File.separator + "tmp_gvsig_installer"); |
51 | 49 |
|
52 |
if (!isCopied){ |
|
53 |
if (applicationDirectory.exists()){ |
|
54 |
deleteDir(applicationDirectory); |
|
55 |
} |
|
56 |
copy(templateFile, applicationDirectory); |
|
57 |
isCopied = true; |
|
50 |
if (applicationDirectory.exists()){ |
|
51 |
deleteDir(applicationDirectory); |
|
58 | 52 |
} |
59 |
|
|
53 |
copy(templateFile, applicationDirectory); |
|
54 |
|
|
60 | 55 |
return applicationDirectory; |
61 | 56 |
} |
57 |
|
|
58 |
public File getTemporalFile(){ |
|
59 |
return new File(System.getProperty("java.io.tmpdir") + File.separator + "installer" + Math.random()); |
|
60 |
} |
|
62 | 61 |
|
63 | 62 |
public File getPluginsDirectory() throws IOException{ |
64 | 63 |
File applicationDirectory = getApplicationDirectory(); |
... | ... | |
106 | 105 |
} |
107 | 106 |
} |
108 | 107 |
|
108 |
public void writeToFile(InputStream is, File file) { |
|
109 |
try { |
|
110 |
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); |
|
111 |
InputStream is2 = is; |
|
112 |
boolean again = true; |
|
113 |
while(again) { |
|
114 |
if(is2.read() > -1) { |
|
115 |
out.writeByte(is.read()); |
|
116 |
} |
|
117 |
else again = false; |
|
118 |
} |
|
119 |
is.close(); |
|
120 |
out.close(); |
|
121 |
} |
|
122 |
catch(IOException e) { |
|
123 |
System.err.println("Error Writing/Reading Streams."); |
|
124 |
} |
|
125 |
} |
|
109 | 126 |
|
127 |
|
|
110 | 128 |
} |
111 | 129 |
|
Also available in: Unified diff