Coverage Report - org.jtheque.core.managers.file.impl.JTDRestorer
 
Classes in this File Line Coverage Branch Coverage Complexity
JTDRestorer
0 %
0/11
0 %
0/8
3.5
 
 1  
 package org.jtheque.core.managers.file.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.file.IFileManager.JTDVersion;
 20  
 import org.jtheque.core.managers.file.able.BackupReader;
 21  
 import org.jtheque.core.managers.file.able.FileType;
 22  
 import org.jtheque.core.managers.file.able.Restorer;
 23  
 import org.jtheque.core.utils.file.jt.JTFileReader;
 24  
 import org.jtheque.core.utils.file.jt.able.JTNotZippedFile;
 25  
 import org.jtheque.core.utils.file.jt.impl.JTDFileReader;
 26  
 import org.jtheque.utils.io.FileException;
 27  
 
 28  
 import java.io.File;
 29  
 import java.util.Collection;
 30  
 
 31  
 /**
 32  
  * A Restorer for the JTD format.
 33  
  *
 34  
  * @author Baptiste Wicht
 35  
  */
 36  0
 public final class JTDRestorer implements Restorer {
 37  
     @Override
 38  
     public void restore(File file, Collection<BackupReader> readers) throws FileException {
 39  0
         JTFileReader reader = new JTDFileReader(readers);
 40  
 
 41  0
         JTNotZippedFile jtdFile = (JTNotZippedFile) reader.readFile(file);
 42  
 
 43  0
         if (jtdFile.isValid()) {
 44  0
             for (BackupReader r : readers) {
 45  0
                 r.persistTheData();
 46  
             }
 47  0
         } else if (jtdFile.getHeader().getFileVersion() != JTDVersion.FIRST.ordinal()) {
 48  0
             throw new FileException("Unsupported version");
 49  
         } else {
 50  0
             throw new FileException("Invalid file");
 51  
         }
 52  0
     }
 53  
 
 54  
     @Override
 55  
     public boolean canImportFrom(FileType fileType) {
 56  0
         return fileType == FileType.JTD;
 57  
     }
 58  
 }