public class FileBlob extends AbstractBlob implements Serializable
Blob
backed by a File
.
The backing file may be in a temporary location, which is the case if this FileBlob
was constructed from an
InputStream
or from a file which was explicitly marked as temporary. In this case, the file may be renamed,
or the file location may be changed to a non-temporary one.
Modifier and Type | Field and Description |
---|---|
protected File |
file |
protected boolean |
isTemporary |
digest, encoding, filename, mimeType, TEXT_PLAIN, UTF_8
Constructor and Description |
---|
FileBlob(File file) |
FileBlob(File file,
String mimeType) |
FileBlob(File file,
String mimeType,
String encoding) |
FileBlob(File file,
String mimeType,
String encoding,
String filename,
String digest) |
FileBlob(InputStream in)
Creates a
FileBlob from an InputStream , by saving it to a temporary file. |
FileBlob(InputStream in,
String mimeType)
Creates a
FileBlob from an InputStream , by saving it to a temporary file. |
FileBlob(InputStream in,
String mimeType,
String encoding)
Creates a
FileBlob from an InputStream , by saving it to a temporary file. |
FileBlob(InputStream in,
String mimeType,
String encoding,
File tmpDir)
Creates a
FileBlob from an InputStream , by saving it to a temporary file. |
FileBlob(String ext)
Creates a
FileBlob with an empty temporary file with the given extension. |
Modifier and Type | Method and Description |
---|---|
File |
getFile()
If this blob is backed by an actual file, returns it.
|
long |
getLength()
Gets the data length in bytes if known.
|
InputStream |
getStream()
Gets an
InputStream for the data of this blob. |
boolean |
isTemporary()
Checks whether this
FileBlob is backed by a temporary file. |
void |
moveTo(File dest)
Moves this blob's temporary file to a new non-temporary location.
|
equals, equalsStream, getByteArray, getCloseableFile, getCloseableFile, getDigest, getDigestAlgorithm, getEncoding, getFilename, getMimeType, getString, hashCode, setDigest, setEncoding, setFilename, setMimeType, transferTo, transferTo
protected boolean isTemporary
public FileBlob(File file, String mimeType, String encoding, String filename, String digest)
public FileBlob(InputStream in) throws IOException
FileBlob
from an InputStream
, by saving it to a temporary file.
The input stream is closed.
in
- the input stream, which is closed after useIOException
public FileBlob(InputStream in, String mimeType) throws IOException
FileBlob
from an InputStream
, by saving it to a temporary file.
The input stream is closed.
in
- the input stream, which is closed after usemimeType
- the MIME typeIOException
public FileBlob(InputStream in, String mimeType, String encoding) throws IOException
FileBlob
from an InputStream
, by saving it to a temporary file.
The input stream is closed.
in
- the input stream, which is closed after usemimeType
- the MIME typeencoding
- the encodingIOException
public FileBlob(InputStream in, String mimeType, String encoding, File tmpDir) throws IOException
FileBlob
from an InputStream
, by saving it to a temporary file.
The input stream is closed.
in
- the input stream, which is closed after usemimeType
- the MIME typeencoding
- the encodingtmpDir
- the temporary directory for file creationIOException
public FileBlob(String ext) throws IOException
FileBlob
with an empty temporary file with the given extension.ext
- the temporary file extensionIOException
public File getFile()
Blob
The returned file may be short-lived (temporary), so should be used immediately.
getFile
in interface Blob
getFile
in class AbstractBlob
null
if the blob is not backed by a filepublic long getLength()
Blob
getLength
in interface Blob
getLength
in class AbstractBlob
public InputStream getStream() throws IOException
Blob
InputStream
for the data of this blob.
The contract of Blob
is that this method can be called several times and will correctly return a new
InputStream
each time. In other words, several reads of the Blob
can be done.
Like all InputStream
, the result must be closed when done with it to avoid resource leaks.
getStream
in interface Blob
IOException
public boolean isTemporary()
FileBlob
is backed by a temporary file.public void moveTo(File dest) throws IOException
The move is done as atomically as possible.
IOException
Copyright © 2015 Nuxeo SA. All rights reserved.