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

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

public class BlobStoreFileItem
extends 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, IBlobStoreService), Serialized Form

Field Summary
static String JSON_KEY_FILE_BLOB_ID
           
static String JSON_KEY_FILE_CONTENT_TYPE
           
static String JSON_KEY_FILE_METADATA_BLOB_ID
           
static String JSON_KEY_FILE_NAME
           
static String JSON_KEY_FILE_SIZE
           
 
Constructor Summary
BlobStoreFileItem(String strBlobId, IBlobStoreService blobstoreService)
          Builds a fileItem from blobstore. get() method is lazy.
 
Method Summary
static String buildFileMetadata(String strFileName, long lSize, String strFileBlobId, String strContentType)
          Builds the json value of a file metadata.
 void delete()
          Deletes both blobs : metadata AND content.
 byte[] get()
          
 String getBlobId()
          Gets the metadata blob id
 String getContentType()
          
 String getFieldName()
          Not supported
 String getFileBlobId()
          Gets the file blob id
 InputStream getInputStream()
          
 String getName()
          
 OutputStream getOutputStream()
          Not supported - throws UnsupportedOperationException exception
 long getSize()
          
 String getString()
          
 String getString(String encoding)
          
 boolean isFormField()
          Not supported
 boolean isInMemory()
          Always false.
 void setFieldName(String name)
          Not supported
 void setFormField(boolean state)
          Not supported
 String toString()
          
 void write(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 String JSON_KEY_FILE_SIZE
See Also:
Constant Field Values

JSON_KEY_FILE_NAME

public static final String JSON_KEY_FILE_NAME
See Also:
Constant Field Values

JSON_KEY_FILE_CONTENT_TYPE

public static final String JSON_KEY_FILE_CONTENT_TYPE
See Also:
Constant Field Values

JSON_KEY_FILE_BLOB_ID

public static final String JSON_KEY_FILE_BLOB_ID
See Also:
Constant Field Values

JSON_KEY_FILE_METADATA_BLOB_ID

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

BlobStoreFileItem

public BlobStoreFileItem(String strBlobId,
                         IBlobStoreService blobstoreService)
                  throws NoSuchBlobException
Builds a fileItem from blobstore. get() method is lazy. The IBlobStoreService 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 String getBlobId()
Gets the metadata blob id

Returns:
the metadata blob id

getFileBlobId

public 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 String getContentType()

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

getFieldName

public String getFieldName()
Not supported

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

getInputStream

public InputStream getInputStream()
                           throws IOException

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

getName

public String getName()

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

getOutputStream

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

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

getSize

public long getSize()

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

getString

public String getString()

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

getString

public String getString(String encoding)
                 throws UnsupportedEncodingException

Specified by:
getString in interface org.apache.commons.fileupload.FileItem
Throws:
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(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(File file)
           throws Exception
Not supported

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

toString

public String toString()

Overrides:
toString in class Object

buildFileMetadata

public static final String buildFileMetadata(String strFileName,
                                             long lSize,
                                             String strFileBlobId,
                                             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 © 2014 Mairie de Paris. All Rights Reserved.