*/
private File mergeChunks(final Node parentNode,
final InputStream lastChunkStream) throws PersistenceException,
RepositoryException {
OutputStream out = null;
SequenceInputStream mergeStrm = null;
File file = null;
try {
file = File.createTempFile("tmp-", "-mergechunk");
out = new FileOutputStream(file);
String startPattern = SlingPostConstants.CHUNK_NODE_NAME + "_"
+ "0_*";
NodeIterator nodeItr = parentNode.getNodes(startPattern);
InputStream ins = null;
int i = 0;
Set<InputStream> inpStrmSet = new LinkedHashSet<InputStream>();
while (nodeItr.hasNext()) {
if (nodeItr.getSize() > 1) {
throw new RepositoryException(
"more than one node found for pattern: " + startPattern);
}
Node rangeNode = nodeItr.nextNode();
inpStrmSet.add(rangeNode.getProperty(
javax.jcr.Property.JCR_DATA).getBinary().getStream());
log.debug("added chunk {} to merge stream", rangeNode.getName());
String[] indexBounds = rangeNode.getName().substring(
(SlingPostConstants.CHUNK_NODE_NAME + "_").length()).split(
"_");
startPattern = SlingPostConstants.CHUNK_NODE_NAME + "_"
+ String.valueOf(Long.valueOf(indexBounds[1]) + 1) + "_*";
nodeItr = parentNode.getNodes(startPattern);
}
inpStrmSet.add(lastChunkStream);
mergeStrm = new SequenceInputStream(
Collections.enumeration(inpStrmSet));
IOUtils.copyLarge(mergeStrm, out);
} catch (IOException e) {
throw new PersistenceException("excepiton occured", e);
} finally {