Manage content in byte format since strings may have encoding problems! especially for compression, etc

This commit is contained in:
Joshua Kissoon 2014-05-12 15:15:59 +05:30
parent 66321280e6
commit cc0cdc42b5
4 changed files with 9 additions and 8 deletions

View File

@ -9,7 +9,7 @@ package kademlia.dht;
public class StorageEntry
{
private String content;
private byte[] content;
private final StorageEntryMetadata metadata;
public StorageEntry(KadContent content)
@ -19,16 +19,16 @@ public class StorageEntry
public StorageEntry(KadContent content, StorageEntryMetadata metadata)
{
this.content = new String(content.toBytes());
this.content = content.toBytes();
this.metadata = metadata;
}
public void setContent(String data)
public void setContent(byte[] data)
{
this.content = data;
}
public String getContent()
public byte[] getContent()
{
return this.content;
}
@ -38,6 +38,7 @@ public class StorageEntry
return this.metadata;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder("[StorageEntry: ");

View File

@ -48,7 +48,7 @@ public class ContentSendingTest
gp.setOwnerId(c.getOwnerId());
System.out.println("Get Parameter: " + 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.getContent()));
System.out.println("Content Metadata: " + conte.getContentMetadata());
}

View File

@ -37,7 +37,7 @@ public class ContentUpdatingTest
System.out.println("Get Parameter: " + 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.getContent()));
System.out.println("Content Metadata: " + conte.getContentMetadata());
/* Lets update the content and put it again */
@ -47,7 +47,7 @@ public class ContentUpdatingTest
/* Lets retrieve the content */
System.out.println("Retrieving Content Again");
conte = kad2.get(gp);
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent().getBytes()));
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(conte.getContent()));
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 */
GetParameter gp = new GetParameter(c.getKey(), kad2.getOwnerId(), c.getType());
StorageEntry content = kad2.get(gp);
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent().getBytes());
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.getContent());
System.out.println("Content received: " + cc);
}