Coverage Report - org.jtheque.core.utils.file.jt.impl.JTDFileWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
JTDFileWriter
0 %
0/15
0 %
0/2
2.5
 
 1  
 package org.jtheque.core.utils.file.jt.impl;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque 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
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 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  
  * A writer implementation for JTD File.
 35  
  *
 36  
  * @author Baptiste Wicht
 37  
  */
 38  
 public final class JTDFileWriter extends JTFileWriter {
 39  
     private final Collection<BackupWriter> writers;
 40  
 
 41  
     /**
 42  
      * Construct a new JTDFileWriter.
 43  
      *
 44  
      * @param writers The writers.
 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  
             //Header
 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  
 }