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  package org.opencastproject.assetmanager.api.storage;
22  
23  import org.opencastproject.util.MimeType;
24  
25  import java.net.URI;
26  import java.util.Optional;
27  
28  import javax.annotation.ParametersAreNonnullByDefault;
29  
30  /** 
31   * A data source along with some optional content hints.
32   */
33  @ParametersAreNonnullByDefault
34  public final class Source {
35    private final URI uri;
36    private final Optional<Long> size;
37    private final Optional<MimeType> mimeType;
38  
39    public Source(URI uri, Optional<Long> size, Optional<MimeType> mimeType) {
40      this.uri = uri;
41      this.size = size;
42      this.mimeType = mimeType;
43    }
44  
45    /** Create a new source. */
46    public static Source mk(URI uri) {
47      return new Source(uri, Optional.<Long>empty(), Optional.<MimeType>empty());
48    }
49  
50    /** Create a new source. */
51    public static Source mk(URI uri, Long size) {
52      return new Source(uri, Optional.of(size), Optional.<MimeType>empty());
53    }
54  
55    /** Create a new source. */
56    public static Source mk(URI uri, Long size, MimeType mimeType) {
57      return new Source(uri, Optional.of(size), Optional.of(mimeType));
58    }
59  
60    /** Create a new source. */
61    public static Source mk(URI uri, Optional<Long> size, Optional<MimeType> mimeType) {
62      return new Source(uri, size, mimeType);
63    }
64  
65    public URI getUri() {
66      return uri;
67    }
68  
69    public Optional<Long> getSize() {
70      return size;
71    }
72  
73    public Optional<MimeType> getMimeType() {
74      return mimeType;
75    }
76  }