public ByteBuffer encode() throws IOException { // TODO: an implementation that can use more than one chunk
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		try (DataOutputStream os = new DataOutputStream(bout)) {
			/* add the data for each entry */
			for (ByteBuffer entry : entries) {
				/* copy to temp buffer */
				byte[] temp = new byte[entry.limit()];
				entry.position(0);
				entry.get(temp);
				entry.position(0);
				/* copy to output stream */
				os.write(temp);
			}
			/* write the chunk lengths */
			int prev = 0;
			for (ByteBuffer entry : entries) {
				/* 
				 * since each file is stored in the only chunk, just write the
				 * delta-encoded file size
				 */
				int chunkSize = entry.limit();
				os.writeInt(chunkSize - prev);
				prev = chunkSize;
			}
			/* we only used one chunk due to a limitation of the implementation */
			bout.write(1);
			/* wrap the bytes from the stream in a buffer */
			byte[] bytes = bout.toByteArray();
			return ByteBuffer.wrap(bytes);
		}
	}
public ByteBuffer encode() throws IOException { 		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		try (DataOutputStream os = new DataOutputStream(bout)) {
		
			for (ByteBuffer entry : entries) {
			
				byte[] temp = new byte[entry.limit()];
				entry.position(0);
				entry.get(temp);
				entry.position(0);
			
				os.write(temp);
			}
		
			int prev = 0;
			for (ByteBuffer entry : entries) {
			
				int chunkSize = entry.limit();
				os.writeInt(chunkSize - prev);
				prev = chunkSize;
			}
		
			bout.write(1);
		
			byte[] bytes = bout.toByteArray();
			return ByteBuffer.wrap(bytes);
		}
	}
public bytebuffer encode() throws ioexception { bytearrayoutputstream bout = new bytearrayoutputstream(); try (dataoutputstream os = new dataoutputstream(bout)) { for (bytebuffer entry : entries) { byte[] temp = new byte[entry.limit()]; entry.position(0); entry.get(temp); entry.position(0); os.write(temp); } int prev = 0; for (bytebuffer entry : entries) { int chunksize = entry.limit(); os.writeint(chunksize - prev); prev = chunksize; } bout.write(1); byte[] bytes = bout.tobytearray(); return bytebuffer.wrap(bytes); } }