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 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:
      hasNext in interface Iterator<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:
      next in interface Iterator<ChunkInputStream>
      Returns:
      next chunk as InputStream
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<ChunkInputStream>
    • iterator

      public Iterator<ChunkInputStream> iterator()
      Specified by:
      iterator in interface Iterable<ChunkInputStream>
    • setPreserveChunkMD5s

      public void setPreserveChunkMD5s(boolean preserveChunkMD5s)
    • getMaxChunkSize

      public long getMaxChunkSize()
    • getManifest

      public ChunksManifest getManifest()
    • finalizeManifest

      public ChunksManifest finalizeManifest()