Add documentation
diff --git a/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java b/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java
index 4bf67e0..ce607cf 100644
--- a/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java
+++ b/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java
@@ -16,7 +16,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -25,6 +24,7 @@
import net.named_data.jndn.util.Blob;
/**
+ * Helper for segmenting an input stream into a list of Data packets.
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
@@ -62,17 +62,17 @@
int numPackets = (int) Math.ceil((double) numBytes / segmentSize);
ByteBuffer buffer = ByteBuffer.wrap(buffer_, 0, numBytes);
Name.Component lastSegment = Name.Component.fromNumberWithMarker(numPackets - 1, 0x00);
-
+
for (int i = 0; i < numPackets; i++) {
Data segment = new Data(template);
segment.getName().appendSegment(i);
segment.getMetaInfo().setFinalBlockId(lastSegment);
byte[] content = new byte[Math.min(segmentSize, buffer.remaining())];
buffer.get(content);
- segment.setContent(new Blob(content));
+ segment.setContent(new Blob(content));
segments.add(segment);
}
-
+
return segments;
}
diff --git a/src/test/java/com/intel/jndn/utils/server/SegmentedServerHelperTest.java b/src/test/java/com/intel/jndn/utils/server/SegmentedServerHelperTest.java
index ff21d77..db4a8eb 100644
--- a/src/test/java/com/intel/jndn/utils/server/SegmentedServerHelperTest.java
+++ b/src/test/java/com/intel/jndn/utils/server/SegmentedServerHelperTest.java
@@ -22,6 +22,7 @@
import static org.junit.Assert.*;
/**
+ * Test the SegmentedServerHelper
*
* @author Andrew Brown <andrew.brown@intel.com>
*/
@@ -50,22 +51,27 @@
assertEquals("9", segments.get(9).getContent().toString());
}
+ /**
+ * Test of segment method, of class SegmentedServerHelper.
+ *
+ * @throws java.lang.Exception
+ */
@Test
public void testSegmentationDifferentSizes() throws Exception {
final Data template = new Data(new Name("/segmented/data"));
-
+
// size 2
final InputStream content2 = new ByteArrayInputStream("0123456789".getBytes());
List<Data> segments2 = SegmentedServerHelper.segment(template, content2, 2);
assertEquals(5, segments2.size());
assertEquals("89", segments2.get(4).getContent().toString());
-
+
// size 3
final InputStream content3 = new ByteArrayInputStream("0123456789".getBytes());
List<Data> segments3 = SegmentedServerHelper.segment(template, content3, 3);
assertEquals(4, segments3.size());
assertEquals("9", segments3.get(3).getContent().toString());
-
+
// size 4
final InputStream content4 = new ByteArrayInputStream("0123456789".getBytes());
List<Data> segments4 = SegmentedServerHelper.segment(template, content4, 4);