001/*
002 * (C) Copyright 2011-2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Florent Guillaume
016 */
017package org.nuxeo.ecm.core.blob.binary;
018
019import java.io.File;
020import java.io.IOException;
021
022/**
023 * Interface to store a file or fetch a file or its length.
024 *
025 * @since 5.9.2
026 */
027public interface FileStorage {
028
029    /**
030     * Stores a file based on a key.
031     *
032     * @param key the file key
033     * @param file the file
034     * @throws IOException if a storage error occurred
035     */
036    void storeFile(String key, File file) throws IOException;
037
038    /**
039     * Fetches a file based on its key.
040     *
041     * @param key the file key
042     * @param file the file to use to store the fetched data
043     * @return {@code true} if the file was fetched, {@code false} if the file was not found
044     * @throws IOException if a storage error occurred
045     */
046    boolean fetchFile(String key, File file) throws IOException;
047
048    /**
049     * Fetches the length of a file based on its key.
050     *
051     * @param key the file key
052     * @return the length, or {@code null} if the file was not found
053     * @throws IOException if a storage error occurred
054     */
055    Long fetchLength(String key) throws IOException;
056
057}