Index: chunk/.DS_Store
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: chunk/.DS_Store
===================================================================
--- chunk/.DS_Store	(nonexistent)
+++ chunk/.DS_Store	(revision 10)

Property changes on: chunk/.DS_Store
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: chunk/Chunk.java
===================================================================
--- chunk/Chunk.java	(nonexistent)
+++ chunk/Chunk.java	(revision 10)
@@ -0,0 +1,69 @@
+package chunk;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+public class Chunk implements Serializable{
+    private String fileId; //Hash256
+    private int chunkNum; //Starts with 0
+    private int repDeg; //Desired Rep degree
+    private int currentRepDeg = 0; //Actual Rep degree
+    private int chunkSize; //MAX 64000kbytes
+    private byte[] info; // chunk itself
+
+    public Chunk(int chunkNum, byte[] content, int chunkSize) throws IOException { //BACKUP CHUNKS
+
+        this.chunkNum = chunkNum;
+        this.info = content;
+        this.chunkSize = chunkSize;
+    }
+
+    public Chunk(int chunkNum, String fileId , int repDeg, int chunkSize) throws IOException { //BACKUP CHUNKS
+
+        this.chunkNum = chunkNum;
+        this.fileId = fileId;
+        this.repDeg = repDeg;
+        this.chunkSize = chunkSize;
+    }
+
+    public String getfileId() {
+        return fileId;
+    }
+
+    public int getNum() {
+        return chunkNum;
+    }
+    
+
+    public int getRepDegree() {
+        return repDeg;
+    }
+
+    public int getActualRepDegree() {
+        return currentRepDeg;
+    }
+
+    public int getchunkSize() {
+        return chunkSize;
+    }
+
+    public byte[] getContent(){
+        return info;
+    }
+    
+    public void setCurrentRepDegree(int degree){
+        this.currentRepDeg = degree;
+    }
+
+    public void setRepDegree(int degree){
+        this.repDeg = degree;
+    }
+   
+    public void setFileId(String id){
+        this.fileId = id;
+    }
+   
+    public void setContent(byte[] content){
+        this.info = content;
+    }
+}
\ No newline at end of file
Index: chunk/ChunkFile.java
===================================================================
--- chunk/ChunkFile.java	(nonexistent)
+++ chunk/ChunkFile.java	(revision 10)
@@ -0,0 +1,126 @@
+package chunk;
+
+
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.security.MessageDigest;
+import java.util.HashMap;
+import java.util.Arrays;
+import java.math.BigInteger; 
+import java.security.NoSuchAlgorithmException; 
+  
+
+
+public class ChunkFile implements Serializable {
+    private HashMap<Integer, Chunk> chunks;
+    private String fileId;
+    private String filePath;
+    private File file;
+    private int replicationDegree;
+
+    public ChunkFile(String filePath, int replicationDegree) {
+        this.chunks = new HashMap<>();
+        this.file = new File(filePath);
+        this.replicationDegree = replicationDegree;
+        generateChunks();
+        generateFileId();
+        // create FILE AND STORE IT IN MEMORY;
+    }
+
+    public String getFileId() {
+        return this.fileId;
+    }
+    
+    public int getReplicationDegree() {
+        return this.replicationDegree;
+    }
+
+    public String getPath() {
+        return this.file.toPath().toString();
+    }
+
+    public Chunk getChunk(int position) {
+        return chunks.get(position);
+    }
+
+    public void deleteChunk(int position) {
+        chunks.remove(position);
+    }
+    
+    public HashMap<Integer,Chunk> getChunks(){
+    		return this.chunks;
+    }
+    
+    public void generateFileId() {
+        String filename = this.file.getName();
+        String path = String.valueOf(this.file.toPath());
+        String owner = this.file.getParent();
+        String modifiedDate = String.valueOf(this.file.lastModified());
+        String totalSize = String.valueOf(this.file.getTotalSpace());
+        String fileID = filename + '-' + path + '-' + owner + '-' + modifiedDate + '-' + totalSize;
+        this.fileId = hashSha256(fileID);
+    }
+
+    public void generateChunks() {
+        int chunkNr = 0;
+
+        int sizeOfChunks = Global.MAX_CHUNK_SIZE;
+        byte[] buffer = new byte[sizeOfChunks];
+
+        try (FileInputStream fis = new FileInputStream(this.file);
+             BufferedInputStream bis = new BufferedInputStream(fis)) {
+
+            int bytesAmount;
+            while ((bytesAmount = bis.read(buffer)) > 0) {
+                byte[] body = Arrays.copyOf(buffer, bytesAmount);
+                Chunk chunk = new Chunk(chunkNr, body, bytesAmount);
+                this.chunks.put(chunkNr,chunk);
+                chunkNr++;
+                buffer = new byte[sizeOfChunks];
+            }
+
+            if (this.file.length() % Global.MAX_CHUNK_SIZE == 0) {
+                Chunk chunk = new Chunk(chunkNr, null, 0);
+                this.chunks.put(chunkNr,chunk);
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    public String hashSha256(String unHashed) {
+        try { 
+  
+            // Static getInstance method is called with hashing SHA 
+            MessageDigest md = MessageDigest.getInstance("SHA-256"); 
+  
+            // digest() method called 
+            // to calculate message digest of an input 
+            // and return array of byte 
+            byte[] messageDigest = md.digest(unHashed.getBytes()); 
+  
+            // Convert byte array into signum representation 
+            BigInteger no = new BigInteger(1, messageDigest); 
+  
+            // Convert message digest into hex value 
+            String hashtext = no.toString(16); 
+  
+            while (hashtext.length() < 32) { 
+                hashtext = "0" + hashtext; 
+            } 
+            return hashtext; 
+        } 
+  
+        // For specifying wrong message digest algorithms 
+        catch (NoSuchAlgorithmException e) { 
+            System.out.println("Exception thrown"
+                               + " for incorrect algorithm: " + e); 
+  
+            return null; 
+        } 
+    }
+}
\ No newline at end of file
Index: chunk/Global.java
===================================================================
--- chunk/Global.java	(nonexistent)
+++ chunk/Global.java	(revision 10)
@@ -0,0 +1,6 @@
+package chunk;
+public class Global {
+    public static int MAX_CHUNK_SIZE = 64000;
+    public static int MAX_STORAGE_SIZE = 64000000;
+    ///
+ }
\ No newline at end of file
