|
1 |
| package com.agical.rdoc.util; |
|
2 |
| |
|
3 |
| import java.io.FileNotFoundException; |
|
4 |
| import java.io.FileOutputStream; |
|
5 |
| import java.io.IOException; |
|
6 |
| |
|
7 |
| import com.agical.rdoc.core.resourcemanager.impl.BasedirProvider; |
|
8 |
| import com.agical.rmock.core.util.StringUtils; |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| public class Write { |
|
16 |
| |
|
17 |
0
| public static void write( Class clazz, String fileName, byte[] content ) throws IOException {
|
|
18 |
0
| String root = clazz.getResource( "" ).getFile();
|
|
19 |
0
| root = StringUtils.replace( root, "%20", " " );
|
|
20 |
0
| write(fileName, content, root);
|
|
21 |
| } |
|
22 |
| |
|
23 |
0
| public static void write( BasedirProvider basedirProvider, String fileName, byte[] content ) throws IOException {
|
|
24 |
0
| write(fileName, content, basedirProvider.getBasedir().getCanonicalPath());
|
|
25 |
| } |
|
26 |
| |
|
27 |
0
| public static void writeInRoot( Class clazz, String fileName, byte[] content ) throws IOException {
|
|
28 |
0
| String root = clazz.getResource( "/" ).getFile();
|
|
29 |
0
| root = StringUtils.replace( root, "%20", " " );
|
|
30 |
0
| write(fileName, content, root);
|
|
31 |
| } |
|
32 |
| |
|
33 |
0
| private static void write(String fileName, byte[] content, String root) throws FileNotFoundException, IOException {
|
|
34 |
0
| FileOutputStream fileOutputStream = null;
|
|
35 |
0
| try {
|
|
36 |
0
| fileOutputStream = new FileOutputStream( root + "/" + fileName );
|
|
37 |
0
| fileOutputStream.write( content );
|
|
38 |
| } finally { |
|
39 |
0
| if( fileOutputStream != null ) {
|
|
40 |
0
| fileOutputStream.close();
|
|
41 |
| } |
|
42 |
| } |
|
43 |
| } |
|
44 |
| } |