View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.staticfiles.api;
23  
24  import org.opencastproject.util.NotFoundException;
25  
26  import java.io.IOException;
27  import java.io.InputStream;
28  
29  public interface StaticFileService {
30  
31    /**
32     * Returns an {@link InputStream} to read a file from the static file service by its UUID.
33     *
34     * @param uuid
35     *          The UUID of the file.
36     * @return The input stream to read the file
37     * @throws NotFoundException
38     *           Thrown if the file cannot be found.
39     * @throws IOException
40     *           If the file could not be read.
41     */
42    InputStream getFile(String uuid) throws NotFoundException, IOException;
43  
44    /**
45     * Returns the original filename of a file stored in the static file service.
46     *
47     * @param uuid
48     *          The UUID of the file.
49     * @return The filename.
50     * @throws NotFoundException
51     *           If the file with the given UUID was not found.
52     */
53    String getFileName(String uuid) throws NotFoundException;
54  
55    /**
56     * Returns the content length of a file stored in the static file service.
57     *
58     * @param uuid
59     *          The UUID of the file.
60     * @return The content length.
61     * @throws NotFoundException
62     *           If the file with the given UUID was not found.
63     */
64    Long getContentLength(String uuid) throws NotFoundException;
65  
66    /**
67     * Stores a file in the temporary storage section of the static file service. Make sure you call
68     * {@link #persistFile(String)} if you want to persist a file durable. A file that is stored in the temporary storage
69     * section may be removed at any time without notice!
70     *
71     * @param filename
72     *          The filename and extension for the file.
73     * @param inputStream
74     *          The {@link InputStream} that represents the file itself.
75     * @return A UUID that represents the static file.
76     * @throws IOException
77     *           Thrown if there is a problem storing the file.
78     */
79    String storeFile(String filename, InputStream inputStream) throws IOException;
80  
81    /**
82     * Persists a file that was previously uploaded to the temporary storage section with
83     * {@code #storeFile(String, InputStream)} for long-term usage.
84     *
85     * @param uuid
86     *          The UUID of the file to persist.
87     * @throws NotFoundException
88     *           If the file could not be found.
89     */
90    void persistFile(String uuid) throws NotFoundException, IOException;
91  
92    /**
93     * Deletes a static file.
94     *
95     * @param uuid
96     *          The uuid of the static file.
97     * @throws NotFoundException
98     *           if the file cannot be found.
99     */
100   void deleteFile(String uuid) throws NotFoundException, IOException;
101 
102 }