Coverage Report - org.jtheque.core.utils.file.jt.impl.JTDFileReader
 
Classes in this File Line Coverage Branch Coverage Complexity
JTDFileReader
0 %
0/18
0 %
0/4
3
 
 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.BackupReader;
 22  
 import org.jtheque.core.utils.file.jt.AbstractJTFileHeader;
 23  
 import org.jtheque.core.utils.file.jt.JTFileReader;
 24  
 import org.jtheque.core.utils.file.jt.able.JTFile;
 25  
 import org.jtheque.core.utils.file.jt.able.JTNotZippedFile;
 26  
 import org.jtheque.utils.bean.Version;
 27  
 import org.jtheque.utils.collections.CollectionUtils;
 28  
 import org.jtheque.utils.io.FileException;
 29  
 import org.jtheque.utils.io.FileUtils;
 30  
 
 31  
 import java.io.DataInputStream;
 32  
 import java.io.IOException;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
  * A JTD File's header.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  
 public final class JTDFileReader extends JTFileReader {
 41  
     private final Collection<BackupReader> readers;
 42  
 
 43  
     /**
 44  
      * Construct a new JTD file reader.
 45  
      *
 46  
      * @param readers The readers.
 47  
      */
 48  0
     public JTDFileReader(Collection<BackupReader> readers) {
 49  0
         this.readers = CollectionUtils.copyOf(readers);
 50  0
     }
 51  
 
 52  
     @Override
 53  
     public JTFile readFile(DataInputStream stream) throws FileException {
 54  0
         JTNotZippedFile file = new JTDFile();
 55  
 
 56  
         try {
 57  0
             AbstractJTFileHeader header = file.getHeader();
 58  
 
 59  0
             header.setKey(Managers.getManager(IFileManager.class).formatUTFToRead(stream.readUTF()));
 60  0
             header.setVersionJTheque(new Version(Managers.getManager(IFileManager.class).formatUTFToRead(stream.readUTF())));
 61  0
             header.setFileVersion(stream.readInt());
 62  0
             header.setDate(stream.readInt());
 63  
 
 64  0
             if (stream.readLong() != IFileManager.JT_CATEGORY_SEPARATOR) {
 65  0
                 file.setCorrectSeparators(false);
 66  
             }
 67  
 
 68  0
             for (BackupReader reader : readers) {
 69  0
                 reader.readBackup(stream);
 70  
             }
 71  0
         } catch (IOException e) {
 72  0
             throw new FileException("File corrupted", e);
 73  
         } finally {
 74  0
             FileUtils.close(stream);
 75  0
         }
 76  
 
 77  0
         return file;
 78  
     }
 79  
 }