1 | |
package org.jtheque.core.utils.file.jt.impl; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.core.managers.Managers; |
20 | |
import org.jtheque.core.managers.file.IFileManager; |
21 | |
import org.jtheque.core.managers.file.able.BackupWriter; |
22 | |
import org.jtheque.core.managers.file.able.BasicDataSource; |
23 | |
import org.jtheque.core.utils.file.jt.JTFileWriter; |
24 | |
import org.jtheque.utils.bean.IntDate; |
25 | |
import org.jtheque.utils.collections.CollectionUtils; |
26 | |
import org.jtheque.utils.io.FileException; |
27 | |
import org.jtheque.utils.io.FileUtils; |
28 | |
|
29 | |
import java.io.DataOutputStream; |
30 | |
import java.io.IOException; |
31 | |
import java.util.Collection; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public final class JTDFileWriter extends JTFileWriter { |
39 | |
private final Collection<BackupWriter> writers; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public JTDFileWriter(Collection<BackupWriter> writers) { |
47 | 0 | this.writers = CollectionUtils.copyOf(writers); |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public void writeFile(DataOutputStream stream, BasicDataSource source) throws FileException { |
52 | |
try { |
53 | |
|
54 | 0 | stream.writeUTF(Managers.getManager(IFileManager.class).formatUTFToWrite(FileUtils.encryptKey(IFileManager.JT_KEY))); |
55 | 0 | stream.writeUTF(Managers.getManager(IFileManager.class).formatUTFToWrite(source.getVersion().getVersion())); |
56 | 0 | stream.writeInt(source.getFileVersion()); |
57 | 0 | stream.writeInt(IntDate.today().intValue()); |
58 | |
|
59 | 0 | stream.writeLong(IFileManager.JT_CATEGORY_SEPARATOR); |
60 | |
|
61 | 0 | for (BackupWriter writer : writers) { |
62 | 0 | writer.write(stream); |
63 | |
} |
64 | 0 | } catch (IOException e) { |
65 | 0 | throw new FileException(e); |
66 | |
} finally { |
67 | 0 | FileUtils.close(stream); |
68 | 0 | } |
69 | 0 | } |
70 | |
} |