Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package mk.ukim.finki.os.filemanagement.exam14march;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.RandomAccessFile;
  8. import java.util.List;
  9.  
  10. import mk.ukim.finki.os.filemanagement.exam.ExamSolution;
  11. import mk.ukim.finki.os.filemanagement.exam.IExamIO;
  12. import mk.ukim.finki.os.filemanagement.exam.TestExam;
  13.  
  14. public class ExamIO implements IExamIO {
  15.  
  16.     @Override
  17.     public void copyLargeTxtFiles(String from, String to, long size)
  18.             throws IOException {
  19.         File from1 = new File(from);
  20.         File to1 = new File(to);
  21.         File[] lista = from1.listFiles();
  22.         if(!from1.exists()){
  23.             System.out.println("Ne postoi");
  24.         }
  25.         else{
  26.             if(!to1.exists()){
  27.                 to1.mkdirs();
  28.             }
  29.             for(int i = 0; i < lista.length; i++){
  30.                 if(lista[i].toString().contains(".txt")){
  31.                     if(lista[i].length() > size)
  32.                         lista[i].renameTo(new File(to1, lista[i].getName()));
  33.                 }
  34.             }
  35.         }
  36.     }
  37.  
  38.     @Override
  39.     public void serializeData(String destination, List<byte[]> data)
  40.             throws IOException {
  41.         FileOutputStream d1 = new FileOutputStream(destination);
  42.         for(int i = 0; i < data.size(); i++){
  43.             d1.write(data.get(i));
  44.         }
  45.         d1.close();
  46.     }
  47.  
  48.     @Override
  49.     public byte[] deserializeDataAtPosition(String source, long position, int elementLength)
  50.             throws IOException {
  51.         RandomAccessFile f1 = new RandomAccessFile(source, "r");
  52.         String s = "";
  53.         f1.seek(position*elementLength);
  54.         for(int i = 0; i < elementLength; i++){
  55.             s += (char)f1.read();
  56.         }
  57.         f1.close();
  58.         return s.getBytes();
  59.     }
  60.  
  61.     public static void main(String[] args) throws IOException {
  62.         ExamIO examIO = new ExamIO();
  63.  
  64.         ExamSolution ex = new ExamSolution();
  65.  
  66.         TestExam.testCopy(examIO);
  67.         TestExam.testSerialize(examIO);
  68.         TestExam.testDeserializeDataAtPosition(examIO);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement