gov.nih.nci.caarray.domain
Class MultiPartBlob

java.lang.Object
  extended by gov.nih.nci.caarray.domain.MultiPartBlob
All Implemented Interfaces:
com.fiveamsolutions.nci.commons.data.persistent.PersistentObject, java.io.Serializable

public class MultiPartBlob
extends java.lang.Object
implements com.fiveamsolutions.nci.commons.data.persistent.PersistentObject

This class is used to get around a mysql issue where the mysql server uses memory extremely poorly on a connection where a blob is being used. In order to get around this memory issue we are breaking a single blob up in to many smaller blobs.

Author:
Scott Miller
See Also:
Serialized Form

Constructor Summary
MultiPartBlob()
           
 
Method Summary
 void addBlob(java.sql.Blob blob)
          Add a blob part.
 java.util.List<BlobHolder> getBlobParts()
          The blobParts as stored by hibernate.
 long getCompressedSize()
           
 java.util.Date getCreationTimestamp()
           
 java.lang.Long getId()
          Returns the id.
 long getUncompressedSize()
           
 java.io.InputStream readCompressedContents()
          Returns an input stream to access the contents of this MultiPartBlob.
 java.io.InputStream readUncompressedContents()
          Returns an input stream to access the contents of this MultiPartBlob.
 void setCompressedSize(long compressedSize)
          This method should generally not be called directly, as file size is calculated when data is written to the file.
 void setCreationTimestamp(java.util.Date timestamp)
           
 void setId(java.lang.Long id)
          Deprecated. should only be used by castor and hibernate
 void setUncompressedSize(long uncompressedSize)
          This method should generally not be called directly, as file size is calculated when data is written to the file.
 void writeData(java.io.InputStream data, boolean compress, int blobPartSize)
          Method that takes an input stream and breaks it up in to multiple blobs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiPartBlob

public MultiPartBlob()
Method Detail

getId

public java.lang.Long getId()
Returns the id.

Specified by:
getId in interface com.fiveamsolutions.nci.commons.data.persistent.PersistentObject
Returns:
the id

setId

@Deprecated
public void setId(java.lang.Long id)
Deprecated. should only be used by castor and hibernate

Sets the id.

Parameters:
id - the id to set

getBlobParts

public java.util.List<BlobHolder> getBlobParts()
The blobParts as stored by hibernate.

Returns:
the blobParts the blobParts.

writeData

public void writeData(java.io.InputStream data,
                      boolean compress,
                      int blobPartSize)
               throws java.io.IOException
Method that takes an input stream and breaks it up in to multiple blobs. Note that this method loads each chunk in to a byte[], while this is not ideal, this will be done by the mysql driver anyway, so we are not adding a new inefficiency.

Parameters:
data - the input stream to store.
compress - true to compress the data, false to leave it uncompressed
blobPartSize - the maximum size of a single blob
Throws:
java.io.IOException - on error reading from the stream.

addBlob

public void addBlob(java.sql.Blob blob)
Add a blob part.

Parameters:
blob - blob data

readCompressedContents

public java.io.InputStream readCompressedContents()
                                           throws java.io.IOException
Returns an input stream to access the contents of this MultiPartBlob. The contents will not be uncompressed when read.

Returns:
the raw (gzip) input stream to read.
Throws:
java.io.IOException - if the contents couldn't be accessed.

readUncompressedContents

public java.io.InputStream readUncompressedContents()
                                             throws java.io.IOException
Returns an input stream to access the contents of this MultiPartBlob. The contents will be uncompressed when read.

Returns:
the inflated input stream to read.
Throws:
java.io.IOException - if the contents couldn't be accessed.

getCreationTimestamp

@NotNull
public java.util.Date getCreationTimestamp()
Returns:
the timestamp

setCreationTimestamp

public void setCreationTimestamp(java.util.Date timestamp)
Parameters:
timestamp - the timestamp to set

getUncompressedSize

public long getUncompressedSize()
Returns:
the uncompressed size, in bytes

setUncompressedSize

public void setUncompressedSize(long uncompressedSize)
This method should generally not be called directly, as file size is calculated when data is written to the file. It is left public to support use in query by example and tooling relying on JavaBean property conventions

Parameters:
uncompressedSize - the uncompressed size of the file, in bytes

getCompressedSize

public long getCompressedSize()
Returns:
the compressed size, in bytes

setCompressedSize

public void setCompressedSize(long compressedSize)
This method should generally not be called directly, as file size is calculated when data is written to the file. It is left public to support use in query by example and tooling relying on JavaBean property conventions

Parameters:
compressedSize - the compressed size of the file, in bytes