1
1
package ru .qatools .gridrouter .utils ;
2
2
3
+ import org .apache .commons .io .FileUtils ;
3
4
import org .apache .commons .lang3 .SerializationUtils ;
4
5
import ru .qatools .gridrouter .config .Browsers ;
5
6
6
7
import javax .xml .bind .JAXB ;
7
8
import java .io .File ;
9
+ import java .io .IOException ;
10
+ import java .io .StringWriter ;
8
11
9
12
import static java .lang .ClassLoader .getSystemResource ;
10
13
import static ru .qatools .gridrouter .utils .GridRouterRule .USER_1 ;
@@ -20,11 +23,11 @@ private QuotaUtils() {
20
23
public static final String QUOTA_FILE_PATTERN
21
24
= getSystemResource ("quota/" + USER_1 + ".xml" ).getPath ().replace (USER_1 , "%s" );
22
25
23
- public static void replacePortInQuotaFile (String user , int port ) {
26
+ public static void replacePortInQuotaFile (String user , int port ) throws IOException {
24
27
copyQuotaFile (user , user , port );
25
28
}
26
29
27
- public static void copyQuotaFile (String srcUser , String dstUser , int withHubPort ) {
30
+ public static void copyQuotaFile (String srcUser , String dstUser , int withHubPort ) throws IOException {
28
31
Browsers browsers = getQuotaFor (srcUser );
29
32
setPort (browsers , withHubPort );
30
33
writeQuotaFor (dstUser , browsers );
@@ -36,8 +39,11 @@ public static Browsers getQuotaFor(String user) {
36
39
return SerializationUtils .clone (browsersOriginal );
37
40
}
38
41
39
- public static void writeQuotaFor (String user , Browsers browsers ) {
40
- JAXB .marshal (browsers , getQuotaFile (user ));
42
+ public static void writeQuotaFor (String user , Browsers browsers ) throws IOException {
43
+ //workaround to write the whole file at once
44
+ StringWriter xml = new StringWriter ();
45
+ JAXB .marshal (browsers , xml );
46
+ FileUtils .write (getQuotaFile (user ), xml .toString ());
41
47
}
42
48
43
49
public static File getQuotaFile (String user ) {
0 commit comments