Commit bea45b57 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

replace SynchronizableFile by SynchronizableFileInfo

parent 95ca38c5
......@@ -10,7 +10,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.URI;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -19,28 +18,38 @@ import java.security.NoSuchAlgorithmException;
* Class for local file. Its goal is to implement ISynchronizableContent.
*
*/
public class SynchronizableFile extends File implements ISynchronizableContent {
public static String TAG = SynchronizableFile.class.getSimpleName();
public class SynchronizableFileInfo implements ISynchronizableContent {
public static String TAG = SynchronizableFileInfo.class.getSimpleName();
public SynchronizableFile(@NonNull String pathname) {
super(pathname);
}
private String hash;
private String localPath;
private long lastModified;
private boolean isFolder;
public SynchronizableFile(String parent, @NonNull String child) {
super(parent, child);
}
public SynchronizableFileInfo(@NonNull File file) {
public SynchronizableFile(File parent, @NonNull String child) {
super(parent, child);
try {
this.hash = calcHash(file);
this.localPath = file.getCanonicalPath();
this.isFolder = file.isDirectory();
this.lastModified = file.lastModified();
}catch (Exception e){
Log.e(TAG, e.toString());
//@TODO: dunno what to do here...
}
}
public SynchronizableFile(@NonNull URI uri) {
super(uri);
public SynchronizableFileInfo(String hash, String localPath, long lastModified, boolean isFolder){
this.hash = hash;
this.localPath = localPath;
this.isFolder = isFolder;
this.lastModified = lastModified;
}
@Override
public long getLastModified() {
return super.lastModified();
return this.lastModified;
}
/**
......@@ -49,23 +58,26 @@ public class SynchronizableFile extends File implements ISynchronizableContent {
*/
@Override
public String getPath(){
try {
return this.getCanonicalPath();
}catch (Exception e){
return "";
}
return this.localPath;
}
@Override
public boolean isDir(){
return isDirectory();
return isFolder;
}
@Override
public String getHash(){
return hash;
}
/**
* Can throw RuntimeException
* @return
*/
@Override
public String getHash() {
public String calcHash(File file) {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
......@@ -76,7 +88,7 @@ public class SynchronizableFile extends File implements ISynchronizableContent {
InputStream is;
try {
is = new FileInputStream(this);
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
Log.e(TAG, "Exception while getting FileInputStream", e);
return null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment