package org.devilry.clientapi;

import java.util.Iterator;
import java.util.List;

import javax.naming.NamingException;

import org.devilry.core.daointerfaces.FileDataBlockCommon;


public class DevilryInputStream extends AbstractDevilryFileStream {

	FileDataBlockCommon fileDataBlock;
	
	DevilryInputStream(long fileMetaId, DevilryConnection connection) {
		super(fileMetaId, connection);
	}

	private FileDataBlockCommon getFileDataBlockBean() throws NamingException {
		return fileDataBlock == null ? fileDataBlock = connection.getFileDataBlock() : fileDataBlock;
	}
		
	
	Iterator<Long> fileBlockIterator = null;
	
	Iterator<Long> getFileBlockIterator() throws NamingException {
		
		if (fileBlockIterator != null)
			return fileBlockIterator;
				
		List<Long> ids = getFileMetaBean().getFileDataBlocks(fileMetaId);
		return fileBlockIterator = ids.iterator();
	}
	
	public byte [] read() throws NamingException {
		
		if (!getFileBlockIterator().hasNext())
			return null;

		long fileDataBlockId = getFileBlockIterator().next();
		
		return getFileDataBlockBean().getFileData(fileDataBlockId);
	}
}

@@ -348,19 +348,42 @@
 nection)
+ throws NamingException
  %7B%0A
-
 %09%09super(
@@ -588,18 +588,17 @@
 ck;%0A%09%7D%0A%09
-%09
 %0A
+
 %09%0A%09Itera
@@ -632,24 +632,32 @@
  = null;%0A%09%0A%09
+private 
 Iterator%3CLon
@@ -986,16 +986,47 @@
 sNext())
+ %7B%0A%09%09%09fileBlockIterator = null;
 %0A%09%09%09retu
@@ -1033,16 +1033,20 @@
 rn null;
+%0A%09%09%7D
 %0A%0A%09%09long

Throw Exception