Moved the HashCalculator to the utils package rather than have it in a package of it's own

Keep the StorageEntry content in the byte[] format it was originally in rather than constantly changing it to a string
This commit is contained in:
Joshua Kissoon 2014-05-11 15:15:26 +05:30
parent 428cab774b
commit 7b95d03d96
5 changed files with 13 additions and 8 deletions

View File

@ -9,7 +9,7 @@ package kademlia.dht;
public class StorageEntry public class StorageEntry
{ {
private final String content; private final byte[] content;
private final StorageEntryMetadata metadata; private final StorageEntryMetadata metadata;
public StorageEntry(KadContent content) public StorageEntry(KadContent content)
@ -19,15 +19,20 @@ public class StorageEntry
public StorageEntry(KadContent content, StorageEntryMetadata metadata) public StorageEntry(KadContent content, StorageEntryMetadata metadata)
{ {
this.content = new String(content.toBytes()); this.content = content.toBytes();
this.metadata = metadata; this.metadata = metadata;
} }
public String getContent() public byte[] getContent()
{ {
return this.content; return this.content;
} }
public String getContentString()
{
return new String(this.content);
}
public StorageEntryMetadata getContentMetadata() public StorageEntryMetadata getContentMetadata()
{ {
return this.metadata; return this.metadata;

View File

@ -41,7 +41,7 @@ public class ContentSendingTest
gp.setOwnerId(c.getOwnerId()); gp.setOwnerId(c.getOwnerId());
System.out.println("Get Parameter: " + gp); System.out.println("Get Parameter: " + gp);
StorageEntry conte = kad2.get(gp); StorageEntry conte = kad2.get(gp);
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
System.out.println("Content Metadata: " + conte.getContentMetadata()); System.out.println("Content Metadata: " + conte.getContentMetadata());
} }

View File

@ -37,7 +37,7 @@ public class ContentUpdatingTest
System.out.println("Get Parameter: " + gp); System.out.println("Get Parameter: " + gp);
StorageEntry conte = kad2.get(gp); StorageEntry conte = kad2.get(gp);
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
System.out.println("Content Metadata: " + conte.getContentMetadata()); System.out.println("Content Metadata: " + conte.getContentMetadata());
/* Lets update the content and put it again */ /* Lets update the content and put it again */
@ -47,7 +47,7 @@ public class ContentUpdatingTest
/* Lets retrieve the content */ /* Lets retrieve the content */
System.out.println("Retrieving Content Again"); System.out.println("Retrieving Content Again");
conte = kad2.get(gp); conte = kad2.get(gp);
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContentString().getBytes()));
System.out.println("Content Metadata: " + conte.getContentMetadata()); System.out.println("Content Metadata: " + conte.getContentMetadata());
} }

View File

@ -53,7 +53,7 @@ public class SaveStateTest2
/* Trying to get a content stored on the restored node */ /* Trying to get a content stored on the restored node */
GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType()); GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType());
StorageEntry content = kad2.get(gp); StorageEntry content = kad2.get(gp);
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent().getBytes()); DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContentString().getBytes());
System.out.println("Content received: " + cc); System.out.println("Content received: " + cc);
} }

View File

@ -1,4 +1,4 @@
package kademlia.util.hashing; package kademlia.util;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;