fixed bugs
This commit is contained in:
parent
31dec13fc3
commit
d0880f7038
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1 +1 @@
|
||||
ichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfiles
|
||||
ichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfilesichbininhalteinesfiles
|
||||
0
ws2012/P2P/uebungen/11/testfile2.txt
Normal file
0
ws2012/P2P/uebungen/11/testfile2.txt
Normal file
Loading…
x
Reference in New Issue
Block a user