fixed bugs

This commit is contained in:
Michael Scholz 2013-02-10 21:39:48 +01:00
parent 31dec13fc3
commit d0880f7038
4 changed files with 25 additions and 23 deletions

View File

@ -434,6 +434,8 @@ public class Node {
public void storeFile(File file) {
files.add(file);
LOGGER.log(Level.INFO, "Stored FILE [{0}])",
new Object[] { file.getPath()});
}
@ -446,12 +448,12 @@ public class Node {
boolean eof = false;
int NUMBER_OF_CHUNKS = 0;
int NUMBER_OF_CHUNKS = -1;
byte[] temp = null;
int totalBytesRead = 0;
Identifier fileID = new Identifier(10, file.getName().getBytes());
Identifier fileID = new Identifier(8, file.getName().getBytes());
try {
InputStream inStream = new BufferedInputStream(new FileInputStream(
@ -476,10 +478,10 @@ public class Node {
String data = "";
if (eof) {
data = fileID.toString() + "|" + NUMBER_OF_CHUNKS + "-"
data = fileID.toString() + "-" + NUMBER_OF_CHUNKS + "-"
+ temp.toString() + "!";
} else {
data = fileID.toString() + "|" + NUMBER_OF_CHUNKS + "-"
data = fileID.toString() + "-" + NUMBER_OF_CHUNKS + "-"
+ temp.toString();
}

View File

@ -6,6 +6,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -22,7 +23,7 @@ public class UDPHandler implements Runnable {
private Node node;
private String[] tempData;
private ArrayList<String> tempData = new ArrayList<String>();
public UDPHandler(Node node) {
this.node = node;
@ -223,24 +224,24 @@ public class UDPHandler implements Runnable {
private void receiveData(NodeIdentifier fromID, Identifier rpcID) {
StringBuilder sb = new StringBuilder();
while (buffer.hasRemaining()) {
sb.append(buffer.get());
}
String data = sb.toString();
String data = new String(buffer.array());
String parts[] = data.split("-");
String fileAndChunk[] = parts[0].split("|");
String fileID = parts[0];
int chunkID = Integer.parseInt(parts[1]);
String fileID = fileAndChunk[0];
int chunkID = Integer.parseInt(fileAndChunk[1]);
String chunkContent = parts[2];
data = parts[1];
if (data.charAt(data.length()) == '!') { // last chunk
tempData.add(chunkContent);
if (chunkContent.charAt(chunkContent.length()-1) == '!' || true) { // last chunk
// store file in node
//TODO: how to store chunks as FILE?
//tempData);
@ -251,8 +252,9 @@ public class UDPHandler implements Runnable {
File file = File.createTempFile(fileID, ".tmp");
bw = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < tempData.length; i++) {
bw.write(tempData[i]);}
for (int i = 0; i < tempData.size(); i++) {
bw.write(tempData.get(i));
}
bw.close();
node.storeFile(file);
@ -260,8 +262,6 @@ public class UDPHandler implements Runnable {
ex.printStackTrace();
}
} else {
tempData[chunkID] = data;
}
// This should be the answer to a prior FIND_NODE -> mark this RPC ID as

View File

@ -1 +1 @@
ichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfiles
ichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfiles

View File