Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mk.ukim.finki.os.filemanagement.exam14march;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.util.List;
- import mk.ukim.finki.os.filemanagement.exam.ExamSolution;
- import mk.ukim.finki.os.filemanagement.exam.IExamIO;
- import mk.ukim.finki.os.filemanagement.exam.TestExam;
- public class ExamIO implements IExamIO {
- @Override
- public void copyLargeTxtFiles(String from, String to, long size)
- throws IOException {
- File from1 = new File(from);
- File to1 = new File(to);
- File[] lista = from1.listFiles();
- if(!from1.exists()){
- System.out.println("Ne postoi");
- }
- else{
- if(!to1.exists()){
- to1.mkdirs();
- }
- for(int i = 0; i < lista.length; i++){
- if(lista[i].toString().contains(".txt")){
- if(lista[i].length() > size)
- lista[i].renameTo(new File(to1, lista[i].getName()));
- }
- }
- }
- }
- @Override
- public void serializeData(String destination, List<byte[]> data)
- throws IOException {
- FileOutputStream d1 = new FileOutputStream(destination);
- for(int i = 0; i < data.size(); i++){
- d1.write(data.get(i));
- }
- d1.close();
- }
- @Override
- public byte[] deserializeDataAtPosition(String source, long position, int elementLength)
- throws IOException {
- RandomAccessFile f1 = new RandomAccessFile(source, "r");
- String s = "";
- f1.seek(position*elementLength);
- for(int i = 0; i < elementLength; i++){
- s += (char)f1.read();
- }
- f1.close();
- return s.getBytes();
- }
- public static void main(String[] args) throws IOException {
- ExamIO examIO = new ExamIO();
- ExamSolution ex = new ExamSolution();
- TestExam.testCopy(examIO);
- TestExam.testSerialize(examIO);
- TestExam.testDeserializeDataAtPosition(examIO);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement