Class FileBlob

java.lang.Object
org.nuxeo.ecm.core.api.impl.blob.AbstractBlob
org.nuxeo.ecm.core.api.impl.blob.FileBlob
All Implemented Interfaces:
Serializable, Blob

public class FileBlob extends AbstractBlob implements Serializable
A 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.

See Also:
  • Field Details

    • file

      protected File file
    • isTemporary

      protected boolean isTemporary
  • Constructor Details

    • FileBlob

      public FileBlob(File file)
    • FileBlob

      public FileBlob(File file, String mimeType)
    • FileBlob

      public FileBlob(File file, String mimeType, String encoding)
    • FileBlob

      public FileBlob(File file, String mimeType, String encoding, String filename, String digest)
    • FileBlob

      public FileBlob(InputStream in) throws IOException
      Creates a FileBlob from an InputStream, by saving it to a temporary file.

      The input stream is closed.

      Parameters:
      in - the input stream, which is closed after use
      Throws:
      IOException
    • FileBlob

      public FileBlob(InputStream in, String mimeType) throws IOException
      Creates a FileBlob from an InputStream, by saving it to a temporary file.

      The input stream is closed.

      Parameters:
      in - the input stream, which is closed after use
      mimeType - the MIME type
      Throws:
      IOException
    • FileBlob

      public FileBlob(InputStream in, String mimeType, String encoding) throws IOException
      Creates a FileBlob from an InputStream, by saving it to a temporary file.

      The input stream is closed.

      Parameters:
      in - the input stream, which is closed after use
      mimeType - the MIME type
      encoding - the encoding
      Throws:
      IOException
    • FileBlob

      public FileBlob(InputStream in, String mimeType, String encoding, File tmpDir) throws IOException
      Creates a FileBlob from an InputStream, by saving it to a temporary file.

      The input stream is closed.

      Parameters:
      in - the input stream, which is closed after use
      mimeType - the MIME type
      encoding - the encoding
      tmpDir - the temporary directory for file creation
      Throws:
      IOException
    • FileBlob

      public FileBlob(String ext) throws IOException
      Creates a FileBlob with an empty temporary file with the given extension.
      Parameters:
      ext - the temporary file extension
      Throws:
      IOException
      Since:
      7.2
    • FileBlob

      public FileBlob(File file, boolean isTemporary)
      Creates a temporary FileBlob backed by a File.
      Since:
      10.3
  • Method Details

    • getFile

      public File getFile()
      Description copied from interface: Blob
      If this blob is backed by an actual file, returns it.

      The returned file may be short-lived (temporary), so should be used immediately.

      Specified by:
      getFile in interface Blob
      Overrides:
      getFile in class AbstractBlob
      Returns:
      a file, or null if the blob is not backed by a file
    • getLength

      public long getLength()
      Description copied from interface: Blob
      Gets the data length in bytes if known.
      Specified by:
      getLength in interface Blob
      Overrides:
      getLength in class AbstractBlob
      Returns:
      the data length or -1 if not known
    • getStream

      public InputStream getStream() throws IOException
      Description copied from interface: Blob
      Gets an 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.

      Specified by:
      getStream in interface Blob
      Returns:
      the stream
      Throws:
      IOException
    • isTemporary

      public boolean isTemporary()
      Checks whether this FileBlob is backed by a temporary file.
      Since:
      7.2
    • moveTo

      public void moveTo(File dest) throws IOException
      Moves this blob's temporary file to a new non-temporary location.

      The move is done as atomically as possible.

      Throws:
      IOException
      Since:
      7.2