1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.job.history.internal

File DefaultExtensionJobHistorySerializer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

0
13
7
1
104
64
11
0.85
1.86
7
1.57

Classes

Class Line # Actions
DefaultExtensionJobHistorySerializer 49 13 0% 11 13
0.3535%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.job.history.internal;
21   
22    import java.io.BufferedWriter;
23    import java.io.File;
24    import java.io.FileReader;
25    import java.io.FileWriter;
26    import java.io.IOException;
27    import java.io.Reader;
28    import java.io.StringReader;
29    import java.io.Writer;
30    import java.util.List;
31   
32    import javax.inject.Singleton;
33   
34    import org.xwiki.component.annotation.Component;
35    import org.xwiki.extension.job.history.ExtensionJobHistoryRecord;
36    import org.xwiki.extension.job.history.ExtensionJobHistorySerializer;
37    import org.xwiki.job.internal.xstream.SafeXStream;
38   
39    import com.thoughtworks.xstream.XStream;
40   
41    /**
42    * Default implementation of {@link ExtensionJobHistorySerializer}.
43    *
44    * @version $Id: 8807081b5f7dd2de89ffecf6d761908ed89818e6 $
45    * @since 7.1RC1
46    */
47    @Component
48    @Singleton
 
49    public class DefaultExtensionJobHistorySerializer implements ExtensionJobHistorySerializer
50    {
51    /**
52    * Used to serialize and deserialize extension job history records.
53    */
54    private XStream xstream = new SafeXStream();
55   
 
56  0 toggle @Override
57    public String serialize(ExtensionJobHistoryRecord record)
58    {
59  0 return this.xstream.toXML(record);
60    }
61   
 
62  42 toggle @Override
63    public void write(ExtensionJobHistoryRecord record, Writer writer)
64    {
65  42 this.xstream.toXML(record, writer);
66    }
67   
 
68  42 toggle @Override
69    public void append(ExtensionJobHistoryRecord record, File historyFile) throws IOException
70    {
71  42 historyFile.getParentFile().mkdirs();
72  42 try (BufferedWriter writer = new BufferedWriter(new FileWriter(historyFile, true))) {
73  42 write(record, writer);
74    }
75    }
76   
 
77  0 toggle @Override
78    public List<ExtensionJobHistoryRecord> deserialize(String serializedRecords)
79    {
80  0 return this.read(new StringReader(serializedRecords));
81    }
82   
 
83  0 toggle @SuppressWarnings("unchecked")
84    @Override
85    public List<ExtensionJobHistoryRecord> read(Reader reader)
86    {
87  0 Reader listReader = new CompositeReader(new StringReader("<list>"), reader, new StringReader("</list>"));
88  0 return (List<ExtensionJobHistoryRecord>) this.xstream.fromXML(listReader);
89    }
90   
 
91  0 toggle @Override
92    public List<ExtensionJobHistoryRecord> read(File historyFile) throws IOException
93    {
94  0 try (FileReader reader = new FileReader(historyFile)) {
95  0 return read(reader);
96    }
97    }
98   
 
99  0 toggle @Override
100    public List<ExtensionJobHistoryRecord> clone(List<ExtensionJobHistoryRecord> records)
101    {
102  0 return deserialize(this.xstream.toXML(records));
103    }
104    }