Store content in string so saved file is easily readable.

This commit is contained in:
Joshua Kissoon 2014-04-06 17:01:27 +05:30
parent 1a5991404d
commit eaeffeb0ba
5 changed files with 8 additions and 7 deletions

View File

@ -96,6 +96,7 @@ public class DHT
/* We have this content, but not the latest version, lets delete it so the new version will be added below */ /* We have this content, but not the latest version, lets delete it so the new version will be added below */
try try
{ {
System.out.println("Removing older content to update it");
this.remove(content.getContentMetadata()); this.remove(content.getContentMetadata());
} }
catch (ContentNotFoundException ex) catch (ContentNotFoundException ex)

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,11 +19,11 @@ 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;
} }

View File

@ -43,7 +43,7 @@ public class ContentSendingTest
List<StorageEntry> conte = kad2.get(gp, 4); List<StorageEntry> conte = kad2.get(gp, 4);
for (StorageEntry cc : conte) for (StorageEntry cc : conte)
{ {
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent().getBytes()));
System.out.println("Content Metadata: " + cc.getContentMetadata()); System.out.println("Content Metadata: " + cc.getContentMetadata());
} }

View File

@ -38,7 +38,7 @@ public class ContentUpdatingTest
List<StorageEntry> conte = kad2.get(gp, 4); List<StorageEntry> conte = kad2.get(gp, 4);
for (StorageEntry cc : conte) for (StorageEntry cc : conte)
{ {
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent().getBytes()));
System.out.println("Content Metadata: " + cc.getContentMetadata()); System.out.println("Content Metadata: " + cc.getContentMetadata());
} }
@ -51,7 +51,7 @@ public class ContentUpdatingTest
conte = kad2.get(gp, 4); conte = kad2.get(gp, 4);
for (StorageEntry cc : conte) for (StorageEntry cc : conte)
{ {
System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent())); System.out.println("Content Found: " + new DHTContentImpl().fromBytes(cc.getContent().getBytes()));
System.out.println("Content Metadata: " + cc.getContentMetadata()); System.out.println("Content Metadata: " + cc.getContentMetadata());
} }

View File

@ -57,7 +57,7 @@ public class SaveStateTest2
if (!content.isEmpty()) if (!content.isEmpty())
{ {
DHTContentImpl cc = new DHTContentImpl().fromBytes(content.get(0).getContent()); DHTContentImpl cc = new DHTContentImpl().fromBytes(content.get(0).getContent().getBytes());
System.out.println("Content received: " + cc); System.out.println("Content received: " + cc);
} }
else else