Package org.duracloud.chunk
Class ChunkableContent
java.lang.Object
org.duracloud.chunk.ChunkableContent
- All Implemented Interfaces:
Iterable<ChunkInputStream>,Iterator<ChunkInputStream>
public class ChunkableContent
extends Object
implements Iterable<ChunkInputStream>, Iterator<ChunkInputStream>
This class manages the provided content stream by breaking it chunks of the
size specified by maxChunkSize.
- Author:
- Andrew Woods Date: Feb 2, 2010
-
Constructor Summary
ConstructorsConstructorDescriptionChunkableContent(String contentId, InputStream largeStream, long contentSize, long maxChunkSize) ChunkableContent(String contentId, String contentMimetype, InputStream largeStream, long contentSize, long maxChunkSize) -
Method Summary
Modifier and TypeMethodDescriptionprotected intcalculateBufferSize(long maxChunkSize) This method finds the maximum 1-KB divisor of arg maxChunkSize that is less than 8-KB.longbooleanhasNext()This method indicates if there are any more chunks.iterator()next()This method returns the next chunk of the wrapped InputStream.voidremove()voidsetPreserveChunkMD5s(boolean preserveChunkMD5s) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
ChunkableContent
public ChunkableContent(String contentId, InputStream largeStream, long contentSize, long maxChunkSize) -
ChunkableContent
public ChunkableContent(String contentId, String contentMimetype, InputStream largeStream, long contentSize, long maxChunkSize)
-
-
Method Details
-
calculateBufferSize
protected int calculateBufferSize(long maxChunkSize) This method finds the maximum 1-KB divisor of arg maxChunkSize that is less than 8-KB. It also ensures that arg maxChunkSize is a multiple of 1-KB, otherwise the stream buffering would lose bytes if the maxChunkSize was not divisible by the buffer size. Additionally, by making the buffer multiples of 1-KB ensures efficient block-writing.- Parameters:
maxChunkSize- of chunk stream- Returns:
- efficient buffer size for given arg chunk-size
-
hasNext
public boolean hasNext()This method indicates if there are any more chunks.- Specified by:
hasNextin interfaceIterator<ChunkInputStream>- Returns:
- true if more chunks are available.
-
next
This method returns the next chunk of the wrapped InputStream. Throws a runtime exception if next() is called before previous stream was fully read.- Specified by:
nextin interfaceIterator<ChunkInputStream>- Returns:
- next chunk as InputStream
-
remove
public void remove()- Specified by:
removein interfaceIterator<ChunkInputStream>
-
iterator
- Specified by:
iteratorin interfaceIterable<ChunkInputStream>
-
setPreserveChunkMD5s
public void setPreserveChunkMD5s(boolean preserveChunkMD5s) -
getMaxChunkSize
public long getMaxChunkSize() -
getManifest
-
finalizeManifest
-