Changed StorageEntry to store content in String format since it's smaller

This commit is contained in:
Joshua Kissoon 2014-05-11 18:59:35 +05:30
parent b49e8170f5
commit b7c75c4e38
4 changed files with 8 additions and 13 deletions

View File

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

@ -48,7 +48,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.getContentString().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().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.getContentString().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().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.getContentString().getBytes())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().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.getContentString().getBytes()); DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent().getBytes());
System.out.println("Content received: " + cc); System.out.println("Content received: " + cc);
} }