work in progress

This commit is contained in:
madwasp79 2019-02-08 18:28:20 +02:00
parent 29cc7faf57
commit bc1dc403b2
2 changed files with 39 additions and 37 deletions

View file

@ -1972,36 +1972,33 @@ public class OsmandAidlApi {
IndexConstants.TEMP_DIR + filePart.getCopyStartTime() + "/" + filePart.getFilename()),
IndexConstants.TILES_INDEX_DIR);
}
return false;
}
private boolean copyFileImpl(CopyFileParams filePart, File file, String destination){
private boolean copyFileImpl(CopyFileParams fileParams, File file, String destination){
LOG.debug(fileParams.toString());
FileOutputStream fos;
String key = filePart.getFilename()+filePart.getCopyStartTime();
String key = fileParams.getFilename() + fileParams.getCopyStartTime();
try {
if (copyFilesCache.containsKey(key)) {
fos = copyFilesCache.get(key);
if (file.length() == filePart.getSize()) {
if (fileParams.isTransmitComplete()) {
copyFilesCache.remove(key);
fos.close();
file.renameTo(app.getAppPath(destination + filePart.getFilename()));
file.renameTo(app.getAppPath(destination + fileParams.getFilename()));
return true;
} else if (file.length() == filePart.getSentSize()) {
fos.write(filePart.getFilePartData());
} else if (file.length() == fileParams.getSentSize()) {
fos.write(fileParams.getFilePartData());
return true;
}
return false;
} else {
file.getParentFile().mkdirs();
fos = new FileOutputStream(file, true);
fos.write(filePart.getFilePartData());
if (file.length()==filePart.getSize()) {
fos.close();
file.renameTo(app.getAppPath(destination + filePart.getFilename()));
} else {
copyFilesCache.put(key, fos);
}
fos.write(fileParams.getFilePartData());
copyFilesCache.put(key, fos);
return true;
}
} catch (IOException e) {

View file

@ -5,28 +5,23 @@ import android.os.Parcelable;
public class CopyFileParams implements Parcelable {
private String filename;
private long size;
private long sentSize;
private byte[] filePartData;
private long copyStartTime;
private boolean isTransmitComplete;
public CopyFileParams(String filename, long size, long sentSize, byte[] filePartData, long copyStartTime) {
public CopyFileParams(String filename, long sentSize, byte[] filePartData, long copyStartTime, boolean isTransmitComplete) {
this.filename = filename;
this.size = size;
this.sentSize = sentSize;
this.filePartData = filePartData;
this.copyStartTime = copyStartTime;
this.isTransmitComplete = isTransmitComplete;
}
public String getFilename() {
return filename;
}
public long getSize() {
return size;
}
public long getSentSize() {
return sentSize;
}
@ -39,26 +34,15 @@ public class CopyFileParams implements Parcelable {
return copyStartTime;
}
public boolean isTransmitComplete() {return isTransmitComplete; }
protected CopyFileParams(Parcel in) {
filename = in.readString();
size = in.readLong();
sentSize = in.readLong();
filePartData = in.createByteArray();
copyStartTime = in.readLong();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(filename);
dest.writeLong(size);
dest.writeLong(sentSize);
dest.writeByteArray(filePartData);
dest.writeLong(copyStartTime);
}
@Override
public int describeContents() {
return 0;
isTransmitComplete = in.readByte() != 0;
}
public static final Creator<CopyFileParams> CREATOR = new Creator<CopyFileParams>() {
@ -72,4 +56,25 @@ public class CopyFileParams implements Parcelable {
return new CopyFileParams[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(filename);
dest.writeLong(sentSize);
dest.writeByteArray(filePartData);
dest.writeLong(copyStartTime);
dest.writeByte((byte) (isTransmitComplete ? 1 : 0));
}
@Override
public String toString() {
return "Filename: " + filename + ", sentSize = " + sentSize + ", filePartData size = " +
filePartData.length + ", startTime: " + copyStartTime + ", isTransmitComplete: "+ isTransmitComplete;
}
}