fr.paris.lutece.portal.service.blobstore
Class BlobStoreFileItem

java.lang.Object
  extended by fr.paris.lutece.portal.service.blobstore.BlobStoreFileItem
All Implemented Interfaces:
java.io.Serializable, org.apache.commons.fileupload.FileItem

public class BlobStoreFileItem
extends java.lang.Object
implements org.apache.commons.fileupload.FileItem

Builds a fileItem from blobstore implementing FileItem.
Metadata is stored in one blob, and content in another one. get() method is lazy preventing blob to be stored in-memory. Use #buildFileMetadata(String, long, String) to build the FileMetadata.

See Also:
#buildFileMetadata(String, long, String), BlobStoreFileItem(String, BlobStoreService), Serialized Form

Field Summary
static java.lang.String JSON_KEY_FILE_BLOB_ID
           
static java.lang.String JSON_KEY_FILE_CONTENT_TYPE
           
static java.lang.String JSON_KEY_FILE_METADATA_BLOB_ID
           
static java.lang.String JSON_KEY_FILE_NAME
           
static java.lang.String JSON_KEY_FILE_SIZE
           
 
Constructor Summary
BlobStoreFileItem(java.lang.String strBlobId, BlobStoreService blobstoreService)
          Builds a fileItem from blobstore. get() method is lazy.
 
Method Summary
static java.lang.String buildFileMetadata(java.lang.String strFileName, long lSize, java.lang.String strFileBlobId, java.lang.String strContentType)
          Builds the json value of a file metadata.
 void delete()
          Deletes both blobs : metadata AND content.
 byte[] get()
          
 java.lang.String getBlobId()
          Gets the metadata blob id
 java.lang.String getContentType()
          
 java.lang.String getFieldName()
          Not supported
 java.lang.String getFileBlobId()
          Gets the file blob id
 java.io.InputStream getInputStream()
          
 java.lang.String getName()
          
 java.io.OutputStream getOutputStream()
          Not supported - throws UnsupportedOperationException exception
 long getSize()
          
 java.lang.String getString()
          
 java.lang.String getString(java.lang.String encoding)
          
 boolean isFormField()
          Not supported
 boolean isInMemory()
          Always false.
 void setFieldName(java.lang.String name)
          Not supported
 void setFormField(boolean state)
          Not supported
 java.lang.String toString()
          
 void write(java.io.File file)
          Not supported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JSON_KEY_FILE_SIZE

public static final java.lang.String JSON_KEY_FILE_SIZE
See Also:
Constant Field Values

JSON_KEY_FILE_NAME

public static final java.lang.String JSON_KEY_FILE_NAME
See Also:
Constant Field Values

JSON_KEY_FILE_CONTENT_TYPE

public static final java.lang.String JSON_KEY_FILE_CONTENT_TYPE
See Also:
Constant Field Values

JSON_KEY_FILE_BLOB_ID

public static final java.lang.String JSON_KEY_FILE_BLOB_ID
See Also:
Constant Field Values

JSON_KEY_FILE_METADATA_BLOB_ID

public static final java.lang.String JSON_KEY_FILE_METADATA_BLOB_ID
See Also:
Constant Field Values
Constructor Detail

BlobStoreFileItem

public BlobStoreFileItem(java.lang.String strBlobId,
                         BlobStoreService blobstoreService)
                  throws NoSuchBlobException
Builds a fileItem from blobstore. get() method is lazy. The BlobStoreService is here to prevent specific usage for the fileItem so it can be used as any other FileItem.

Parameters:
strBlobId - the blob id
blobstoreService - the blob service
Throws:
NoSuchBlobException - if blob cannot be parsed
Method Detail

getBlobId

public java.lang.String getBlobId()
Gets the metadata blob id

Returns:
the metadata blob id

getFileBlobId

public java.lang.String getFileBlobId()
Gets the file blob id

Returns:
the file blob id

delete

public void delete()
Deletes both blobs : metadata AND content.

Specified by:
delete in interface org.apache.commons.fileupload.FileItem

get

public byte[] get()

Specified by:
get in interface org.apache.commons.fileupload.FileItem

getContentType

public java.lang.String getContentType()

Specified by:
getContentType in interface org.apache.commons.fileupload.FileItem

getFieldName

public java.lang.String getFieldName()
Not supported

Specified by:
getFieldName in interface org.apache.commons.fileupload.FileItem
Returns:
null

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException

Specified by:
getInputStream in interface org.apache.commons.fileupload.FileItem
Throws:
java.io.IOException - ioexception

getName

public java.lang.String getName()

Specified by:
getName in interface org.apache.commons.fileupload.FileItem

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Not supported - throws UnsupportedOperationException exception

Specified by:
getOutputStream in interface org.apache.commons.fileupload.FileItem
Returns:
nothing
Throws:
java.io.IOException - ioe

getSize

public long getSize()

Specified by:
getSize in interface org.apache.commons.fileupload.FileItem

getString

public java.lang.String getString()

Specified by:
getString in interface org.apache.commons.fileupload.FileItem

getString

public java.lang.String getString(java.lang.String encoding)
                           throws java.io.UnsupportedEncodingException

Specified by:
getString in interface org.apache.commons.fileupload.FileItem
Throws:
java.io.UnsupportedEncodingException

isFormField

public boolean isFormField()
Not supported

Specified by:
isFormField in interface org.apache.commons.fileupload.FileItem
Returns:
false

isInMemory

public boolean isInMemory()
Always false.

Specified by:
isInMemory in interface org.apache.commons.fileupload.FileItem
Returns:
false

setFieldName

public void setFieldName(java.lang.String name)
Not supported

Specified by:
setFieldName in interface org.apache.commons.fileupload.FileItem
Parameters:
name - -

setFormField

public void setFormField(boolean state)
Not supported

Specified by:
setFormField in interface org.apache.commons.fileupload.FileItem
Parameters:
state - -

write

public void write(java.io.File file)
           throws java.lang.Exception
Not supported

Specified by:
write in interface org.apache.commons.fileupload.FileItem
Parameters:
file - -
Throws:
java.lang.Exception - ex

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

buildFileMetadata

public static final java.lang.String buildFileMetadata(java.lang.String strFileName,
                                                       long lSize,
                                                       java.lang.String strFileBlobId,
                                                       java.lang.String strContentType)
Builds the json value of a file metadata.

Parameters:
strFileName - filename
lSize - size
strFileBlobId - the blob id
strContentType - the content type
Returns:
the json of the fileMetadata to store in BlobStore


Copyright © 2012 Mairie de Paris. All Rights Reserved.