org.ccnx.ccn.io.CCNOutputStream Class Reference

Basic output stream class which generates segmented content under a given name prefix. More...

Inheritance diagram for org.ccnx.ccn.io.CCNOutputStream:

org.ccnx.ccn.io.CCNAbstractOutputStream org.ccnx.ccn.io.CCNVersionedOutputStream org.ccnx.ccn.io.RepositoryOutputStream org.ccnx.ccn.test.repo.RepoPerformanceTester org.ccnx.ccn.io.CCNFileOutputStream org.ccnx.ccn.io.RepositoryVersionedOutputStream org.ccnx.ccn.test.repo.RepoSingleFileTester org.ccnx.ccn.io.RepositoryFileOutputStream

List of all members.

Public Member Functions

 CCNOutputStream (ContentName baseName, CCNHandle handle) throws IOException
 Constructor for a simple CCN output stream.
 CCNOutputStream (ContentName baseName, PublisherPublicKeyDigest publisher, CCNHandle handle) throws IOException
 Constructor for a simple CCN output stream.
 CCNOutputStream (ContentName baseName, ContentKeys keys, CCNHandle handle) throws IOException
 Constructor for a simple CCN output stream.
 CCNOutputStream (ContentName baseName, KeyLocator locator, PublisherPublicKeyDigest publisher, ContentKeys keys, CCNHandle handle) throws IOException
 Constructor for a simple CCN output stream.
 CCNOutputStream (ContentName baseName, KeyLocator locator, PublisherPublicKeyDigest publisher, ContentType type, ContentKeys keys, CCNHandle handle) throws IOException
 Constructor for a simple CCN output stream.
 CCNOutputStream (ContentName baseName, KeyLocator locator, PublisherPublicKeyDigest publisher, ContentType type, ContentKeys keys, CCNFlowControl flowControl) throws IOException
 Low-level constructor used by clients that need to specify flow control behavior.
synchronized void setBlockSize (int blockSize) throws IOException
 Set the segmentation block size to use.
int getBlockSize ()
 Get segmentation block size.
void setFreshnessSeconds (Integer freshnessSeconds)
void close () throws IOException
void flush () throws IOException
void write (byte[] b, int off, int len) throws IOException

Static Public Attributes

static final int BLOCK_BUF_COUNT = 128
 Amount of data we keep around prior to forced flush to segmenter, in terms of segmenter blocks.

Protected Member Functions

 CCNOutputStream ()
 Special purpose constructor.
 CCNOutputStream (ContentName baseName, KeyLocator locator, PublisherPublicKeyDigest publisher, ContentType type, ContentKeys keys, CCNSegmenter segmenter) throws IOException
 Low-level constructor used by subclasses that need to specify segmenter behavior.
void startWrite () throws IOException
 Override in subclasses that need to do something special with start writes (see CCNFlowControl.startWrite(ContentName, Shape)).
void flush (boolean flushLastBlock) throws IOException
 Internal flush.
synchronized void writeToNetwork (byte[] buf, long offset, long len) throws IOException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, InvalidAlgorithmParameterException
 Actually write bytes to the network.
void closeNetworkData () throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, IOException, InterruptedException
 Flush partial hanging block if we have one.
synchronized void flushToNetwork (boolean flushLastBlock) throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, InterruptedException, IOException, InvalidAlgorithmParameterException
long lengthWritten ()

Protected Attributes

long _totalLength = 0
 elapsed length written
int _blockOffset = 0
 write pointer - offset into the current write buffer at which to write
int _blockIndex = 0
 write pointer - current write buffer at which to write
byte[][] _buffers = null
 write buffers
long _baseNameIndex
 base name index of the current set of data to output; incremented according to the segmentation profile.
CCNTime _timestamp
 // timestamp we use for writing, set to time first segment is written
Integer _freshnessSeconds
CCNDigestHelper _dh
boolean _nameSpaceAdded = false
boolean _flushed = false
boolean _FCIsOurs = false


Detailed Description

Basic output stream class which generates segmented content under a given name prefix.

Segment naming is generated according to the SegmentationProfile; by default names are sequentially numbered. Name prefixes are taken as specified (no versions or other information is added by this class). Segments are fixed length (see CCNBlockOutputStream for non fixed-length segments).


Constructor & Destructor Documentation

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
CCNHandle  handle 
) throws IOException

Constructor for a simple CCN output stream.

Parameters:
baseName name prefix under which to write content segments
handle if null, new handle created with CCNHandle.open()
Exceptions:
IOException if stream setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
PublisherPublicKeyDigest  publisher,
CCNHandle  handle 
) throws IOException

Constructor for a simple CCN output stream.

Parameters:
baseName name prefix under which to write content segments
publisher key to use to sign the segments, if null, default for user is used.
handle if null, new handle created with CCNHandle.open()
Exceptions:
IOException if stream setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
ContentKeys  keys,
CCNHandle  handle 
) throws IOException

Constructor for a simple CCN output stream.

Parameters:
baseName name prefix under which to write content segments
keys keys with which to encrypt content, if null content either unencrypted or keys retrieved according to local policy
handle if null, new handle created with CCNHandle.open()
Exceptions:
IOException if stream setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
KeyLocator  locator,
PublisherPublicKeyDigest  publisher,
ContentKeys  keys,
CCNHandle  handle 
) throws IOException

Constructor for a simple CCN output stream.

Parameters:
baseName name prefix under which to write content segments
locator key locator to use, if null, default for key is used.
publisher key to use to sign the segments, if null, default for user is used.
keys keys with which to encrypt content, if null content either unencrypted or keys retrieved according to local policy
handle if null, new handle created with CCNHandle.open()
Exceptions:
IOException if stream setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
KeyLocator  locator,
PublisherPublicKeyDigest  publisher,
ContentType  type,
ContentKeys  keys,
CCNHandle  handle 
) throws IOException

Constructor for a simple CCN output stream.

Parameters:
baseName name prefix under which to write content segments
locator key locator to use, if null, default for key is used.
publisher key to use to sign the segments, if null, default for user is used.
type type to mark content (see ContentType), if null, DATA is used; if content encrypted, ENCR is used.
keys keys with which to encrypt content, if null content either unencrypted or keys retrieved according to local policy
handle if null, new handle created with CCNHandle.open()
Exceptions:
IOException if stream setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
KeyLocator  locator,
PublisherPublicKeyDigest  publisher,
ContentType  type,
ContentKeys  keys,
CCNFlowControl  flowControl 
) throws IOException

Low-level constructor used by clients that need to specify flow control behavior.

Parameters:
baseName name prefix under which to write content segments
locator key locator to use, if null, default for key is used.
publisher key to use to sign the segments, if null, default for user is used.
type type to mark content (see ContentType), if null, DATA is used; if content encrypted, ENCR is used.
keys keys with which to encrypt content, if null content either unencrypted or keys retrieved according to local policy
flowControl flow controller used to buffer output content
Exceptions:
IOException if flow controller setup fails

org.ccnx.ccn.io.CCNOutputStream.CCNOutputStream ( ContentName  baseName,
KeyLocator  locator,
PublisherPublicKeyDigest  publisher,
ContentType  type,
ContentKeys  keys,
CCNSegmenter  segmenter 
) throws IOException [protected]

Low-level constructor used by subclasses that need to specify segmenter behavior.

Parameters:
baseName name prefix under which to write content segments
locator key locator to use, if null, default for key is used.
publisher key to use to sign the segments, if null, default for user is used.
type type to mark content (see ContentType), if null, DATA is used; if content encrypted, ENCR is used.
keys the ContentKeys to use to encrypt, or null if unencrypted or access controlled (keys automatically retrieved)
segmenter segmenter used to segment and sign content
Exceptions:
IOException if flow controller setup fails


Member Function Documentation

void org.ccnx.ccn.io.CCNOutputStream.startWrite (  )  throws IOException [protected]

Override in subclasses that need to do something special with start writes (see CCNFlowControl.startWrite(ContentName, Shape)).

They should call this superclass method, though, to initialize keys (may need to move this later).

Exceptions:
IOException 

Reimplemented from org.ccnx.ccn.io.CCNAbstractOutputStream.

synchronized void org.ccnx.ccn.io.CCNOutputStream.setBlockSize ( int  blockSize  )  throws IOException

Set the segmentation block size to use.

Constraints: needs to be a multiple of the likely encryption block size (which is, conservatively, 32 bytes). Default is 4096.

Parameters:
blockSize in bytes

int org.ccnx.ccn.io.CCNOutputStream.getBlockSize (  ) 

Get segmentation block size.

Returns:
block size in bytes

void org.ccnx.ccn.io.CCNOutputStream.flush ( boolean  flushLastBlock  )  throws IOException [protected]

Internal flush.

Parameters:
flushLastBlock Should we flush the last (partial) block, or hold it back for it to be filled.
Exceptions:
IOException on a variety of types of error.

synchronized void org.ccnx.ccn.io.CCNOutputStream.writeToNetwork ( byte[]  buf,
long  offset,
long  len 
) throws IOException, InvalidKeyException, SignatureException, NoSuchAlgorithmException, InvalidAlgorithmParameterException [protected]

Actually write bytes to the network.

Parameters:
buf as in write(byte[], int, int)
offset as in write(byte[], int, int)
len as in write(byte[])
Exceptions:
IOException on network errors
InvalidKeyException if we cannot encrypt content as specified
SignatureException if we cannot sign content
NoSuchAlgorithmException if encryption requests invalid algorithm
InvalidAlgorithmParameterException 

void org.ccnx.ccn.io.CCNOutputStream.closeNetworkData (  )  throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, IOException, InterruptedException [protected]

Flush partial hanging block if we have one.

Exceptions:
InvalidKeyException 
SignatureException 
NoSuchAlgorithmException 
IOException 
InterruptedException 

Reimplemented in org.ccnx.ccn.io.CCNFileOutputStream.

synchronized void org.ccnx.ccn.io.CCNOutputStream.flushToNetwork ( boolean  flushLastBlock  )  throws InvalidKeyException, SignatureException, NoSuchAlgorithmException, InterruptedException, IOException, InvalidAlgorithmParameterException [protected]

Parameters:
flushLastBlock Do we flush a partially-filled last block in the current set of blocks? Not normally, we want to fill blocks. So if a user calls a manual flush(), we want to flush all full blocks, but not a last partial -- readers of this block-fragmented content (other streams make other sorts of fragments, this one is designed for files of same block size) expect all fragments but the last to be the same size. The only time we flush a last partial is on close(), when it is the last block of the data. This flag, passed in only by internal methods, tells us it's time to do that.
Exceptions:
InvalidKeyException 
SignatureException 
NoSuchAlgorithmException 
InterruptedException 
IOException 
InvalidAlgorithmParameterException 

XXX - Can the blockbuffers have holes? DKS: no. The blockCount argument to putMerkleTree is intended to tell it how many of the blockBuffers array it should touch (are non-null). If there are holes, there is a bigger problem.

Partial last block handling. If we are in the middle of writing a file, we only flush complete blocks; up to _blockOffset % blockSize. The only time we emit a 0-length block is if we've been told to flush the last block (i.e. we're closing the file) without having written anything at all. So for 0-length files we emit a single block with 0-length content (which has a Content element, but no contained BLOB).

long org.ccnx.ccn.io.CCNOutputStream.lengthWritten (  )  [protected]

Returns:
number of bytes that have been written on this stream.


Member Data Documentation

Amount of data we keep around prior to forced flush to segmenter, in terms of segmenter blocks.

We write to a limit lower than the maximum, to allow for expansion due to encryption. We believe we want a low number here to allow for effective interleaving of threading in read/write/repo running within the same JVM. We have to have at least one extra block to allow for holding back data for final block writing etc (see notes about this below). In practice most flushing to the segmenter will result in in creating BLOCK_BUF_COUNT - 1 ContentObjects in the segmenter.


The documentation for this class was generated from the following file:

Generated on Thu Feb 16 00:45:01 2012 for Content-Centric Networking in Java by  doxygen 1.5.6