summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-19 17:17:33 +0200
committerSimon Rettberg2015-08-19 17:17:33 +0200
commit247cd98da8dfb981e0ad1cdc12b086503088209d (patch)
tree539e7058b46788c42fd46c16e68927e0c5a20b76 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
parent[client] Layout code cleanup. (diff)
downloadtutor-module-247cd98da8dfb981e0ad1cdc12b086503088209d.tar.gz
tutor-module-247cd98da8dfb981e0ad1cdc12b086503088209d.tar.xz
tutor-module-247cd98da8dfb981e0ad1cdc12b086503088209d.zip
Adapt to master-sync-shared changes
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java40
1 files changed, 36 insertions, 4 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
index 01cd072d..f03c06f3 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
@@ -4,7 +4,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -115,7 +114,7 @@ public class ActiveUpload implements HashCheckCallback {
}
public ActiveUpload(String uploadId, UserInfo owner, ImageDetailsRead image, File destinationFile,
- long fileSize, List<ByteBuffer> sha1Sums, byte[] machineDescription) throws FileNotFoundException {
+ long fileSize, List<byte[]> sha1Sums, byte[] machineDescription) throws FileNotFoundException {
this.destinationFile = destinationFile;
this.outFile = new RandomAccessFile(destinationFile, "rw");
this.chunks = new ChunkList(fileSize, sha1Sums);
@@ -326,7 +325,7 @@ public class ActiveUpload implements HashCheckCallback {
@Override
public FileRange get() {
if (currentChunk != null) {
- if (currentChunk.hasSha1Sum() && hashChecker != null) {
+ if (hashChecker != null && currentChunk.getSha1Sum() != null) {
try {
hashChecker.queue(currentChunk, buffer, activeUpload);
} catch (InterruptedException e) {
@@ -365,7 +364,8 @@ public class ActiveUpload implements HashCheckCallback {
public void hashCheckDone(HashResult result, byte[] data, FileChunk chunk) {
switch (result) {
case FAILURE:
- LOGGER.warn("Hash check of chunk " + chunk.toString() + " failed. Assuming valid.");
+ LOGGER.warn("Hash check of chunk " + chunk.toString()
+ + " could not be executed. Assuming valid :-(");
// Fall through
case VALID:
writeFileData(chunk.range.startOffset, chunk.range.getLength(), data);
@@ -376,6 +376,38 @@ public class ActiveUpload implements HashCheckCallback {
}
}
+ private byte[] loadChunkFromFile(FileChunk chunk) {
+ synchronized (outFile) {
+ try {
+ outFile.seek(chunk.range.startOffset);
+ byte[] buffer = new byte[chunk.range.getLength()];
+ outFile.readFully(buffer);
+ return buffer;
+ } catch (IOException e) {
+ LOGGER.error(
+ "Could not read chunk " + chunk.getChunkIndex() + " of File "
+ + destinationFile.toString(), e);
+ return null;
+ }
+ }
+ }
+
+ public void updateBlockHashList(List<byte[]> hashList) {
+ if (hashChecker == null)
+ return;
+ chunks.updateSha1Sums(hashList);
+ for (FileChunk chunk = chunks.getUnhashedComplete(); chunk != null;) {
+ byte[] data = loadChunkFromFile(chunk);
+ try {
+ hashChecker.queue(chunk, data, this);
+ } catch (InterruptedException e) {
+ LOGGER.warn("Got interrupted while queueing block for hash check", e);
+ Thread.currentThread().interrupt();
+ return;
+ }
+ }
+ }
+
// TODO: Clean up old stale uploads
}