/* copy to output stream */
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);
		}
	}
entry.get(temp);
entry.position(0);
/* copy to output stream */
os.write(temp);
}
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();
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);
}
}