org.apache.stanbol.enhancer.servicesapi.helper
Class InMemoryBlob

java.lang.Object
  extended by org.apache.stanbol.enhancer.servicesapi.helper.InMemoryBlob
All Implemented Interfaces:
Blob

public class InMemoryBlob
extends java.lang.Object
implements Blob

Holds the parsed data in an byte array. Parsed byte[] are NOT copied, Strings are encoded as UTF-8 and InputStream are copied by using IOUtils.toByteArray(InputStream).

The default mime-types (if null is parsed as mimeType) are for Strings "text/plain" and in all other cases "application/octet-stream".


Field Summary
static java.lang.String DEFAULT_BINARY_MIMETYPE
           
static java.lang.String DEFAULT_TEXT_MIMETYPE
           
protected  java.lang.String mimeType
           
protected  java.util.Map<java.lang.String,java.lang.String> parameters
           
 
Constructor Summary
  InMemoryBlob(byte[] data, java.lang.String mimeType)
          Creates an instance for the parsed byte array.
protected InMemoryBlob(byte[] data, java.lang.String mimeType, java.util.Map<java.lang.String,java.lang.String> parsedParameters)
          Internally used constructor that allows to parse additional parameters as required to ensure setting the 'charset' in case initialisation was done by parsing a string
  InMemoryBlob(java.io.InputStream in, java.lang.String mimeType)
          Creates an instance for the parsed InputStream.
  InMemoryBlob(java.lang.String text, java.lang.String mimeType)
          Creates an InMemoryBlob for the parsed String.
 
Method Summary
 long getContentLength()
          The size of the Content in bytes or a negative value if not known
 java.lang.String getMimeType()
          Getter for the mime-type of the content.
 java.util.Map<java.lang.String,java.lang.String> getParameter()
          Additional parameters parsed with the mime-type.
 java.io.InputStream getStream()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TEXT_MIMETYPE

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

DEFAULT_BINARY_MIMETYPE

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

mimeType

protected final java.lang.String mimeType

parameters

protected final java.util.Map<java.lang.String,java.lang.String> parameters
Constructor Detail

InMemoryBlob

public InMemoryBlob(java.lang.String text,
                    java.lang.String mimeType)
Creates an InMemoryBlob for the parsed String. If a "charset" parameter is present for the parsed mimeType it is replaced with "UTF-8" used to encode the Sting as byte[].

Parameters:
text - the text
mimeType - the mimeType. If null "text/plain" is used as default

InMemoryBlob

public InMemoryBlob(java.io.InputStream in,
                    java.lang.String mimeType)
             throws java.io.IOException
Creates an instance for the parsed InputStream. Data are copied to a byte array. The parsed stream is closed after copying the data.

Parameters:
in - the InputStream. MUST NOT be null
mimeType - the mime-type. If null "application/octet-stream" is used as default.
Throws:
java.io.IOException - indicates an error while reading from the parsed stream

InMemoryBlob

public InMemoryBlob(byte[] data,
                    java.lang.String mimeType)
Creates an instance for the parsed byte array. The array is NOT copied therefore changes within that array will be reflected to components reading the data from this Blob.

Parameters:
data - the data. MIST NOT be null
mimeType - the mime-type. If null "application/octet-stream" is used as default.

InMemoryBlob

protected InMemoryBlob(byte[] data,
                       java.lang.String mimeType,
                       java.util.Map<java.lang.String,java.lang.String> parsedParameters)
Internally used constructor that allows to parse additional parameters as required to ensure setting the 'charset' in case initialisation was done by parsing a string

Parameters:
data -
mimeType -
parsedParameters -
Method Detail

getStream

public final java.io.InputStream getStream()
Specified by:
getStream in interface Blob
Returns:
a stream of the data of this blog

getContentLength

public final long getContentLength()
Description copied from interface: Blob
The size of the Content in bytes or a negative value if not known

Specified by:
getContentLength in interface Blob

getMimeType

public final java.lang.String getMimeType()
Description copied from interface: Blob
Getter for the mime-type of the content. The returned string MUST only contain the "{type}/{sub-type}". No wildcards MUST BE used.

Specified by:
getMimeType in interface Blob
Returns:
the mime-type of his blog

getParameter

public final java.util.Map<java.lang.String,java.lang.String> getParameter()
Description copied from interface: Blob
Additional parameters parsed with the mime-type. Typically the 'charset' used to encode text is parsed as a parameter.

Specified by:
getParameter in interface Blob
Returns:
read only map with additional parameter for the used mime-type.


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.