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
Constructors Constructor Description ChunkableContent(String contentId, InputStream largeStream, long contentSize, long maxChunkSize)ChunkableContent(String contentId, String contentMimetype, InputStream largeStream, long contentSize, long maxChunkSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intcalculateBufferSize(long maxChunkSize)This method finds the maximum 1-KB divisor of arg maxChunkSize that is less than 8-KB.ChunksManifestfinalizeManifest()ChunksManifestgetManifest()longgetMaxChunkSize()booleanhasNext()This method indicates if there are any more chunks.Iterator<ChunkInputStream>iterator()ChunkInputStreamnext()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, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
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 Detail
-
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
public ChunkInputStream 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
public Iterator<ChunkInputStream> iterator()
- Specified by:
iteratorin interfaceIterable<ChunkInputStream>
-
setPreserveChunkMD5s
public void setPreserveChunkMD5s(boolean preserveChunkMD5s)
-
getMaxChunkSize
public long getMaxChunkSize()
-
getManifest
public ChunksManifest getManifest()
-
finalizeManifest
public ChunksManifest finalizeManifest()
-
-