|
4 | 4 | */ |
5 | 5 | package wtf.g4s8.mime; |
6 | 6 |
|
7 | | -import java.io.IOException; |
8 | | -import java.util.Map; |
| 7 | +import java.util.Optional; |
| 8 | +import java.util.Set; |
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * Media type (or MIME type). |
12 | 12 | * |
13 | | - * @since 0.1 |
| 13 | + * @since 2.0 |
14 | 14 | */ |
15 | 15 | public interface MimeType { |
16 | 16 |
|
17 | 17 | /** |
18 | 18 | * Type name. |
19 | | - * @return Type name string |
20 | | - * @throws IOException If failed to read |
| 19 | + * @return Name string |
21 | 20 | */ |
22 | | - String type() throws IOException; |
| 21 | + String type(); |
23 | 22 |
|
24 | 23 | /** |
25 | 24 | * Subtype name. |
26 | | - * @return Subtype name string |
27 | | - * @throws IOException If failed to read |
| 25 | + * @return Subtype string |
28 | 26 | */ |
29 | | - String subtype() throws IOException; |
| 27 | + String subtype(); |
30 | 28 |
|
31 | 29 | /** |
32 | | - * Optional parameters. |
33 | | - * @return Parameter map |
34 | | - * @throws IOException If failed to read |
| 30 | + * Optional parameters names. |
| 31 | + * @return unordered case-insentetive set of strings |
35 | 32 | */ |
36 | | - Map<String, String> params() throws IOException; |
| 33 | + Set<String> params(); |
| 34 | + |
| 35 | + /** |
| 36 | + * Parameter value for name. |
| 37 | + * @param name Parameter name, case-insentetive |
| 38 | + * @return Optional parameter value if present for the name |
| 39 | + */ |
| 40 | + Optional<String> param(String name); |
| 41 | + |
| 42 | + /** |
| 43 | + * Mime type of string source. |
| 44 | + * @return Mime type implementation for string provided |
| 45 | + */ |
| 46 | + static MimeType of(final CharSequence src) { |
| 47 | + return new MimeTypeOfString(src); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Default decorator for mime type. |
| 52 | + * @since 2.0 |
| 53 | + */ |
| 54 | + abstract class Wrap implements MimeType { |
| 55 | + |
| 56 | + /** |
| 57 | + * Delegate. |
| 58 | + */ |
| 59 | + private final MimeType origin; |
| 60 | + |
| 61 | + /** |
| 62 | + * Wraps origin. |
| 63 | + * @param origin Delegate |
| 64 | + */ |
| 65 | + protected Wrap(final MimeType origin) { |
| 66 | + this.origin = origin; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public final String type() { |
| 71 | + return this.origin.type(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public String subtype() { |
| 76 | + return this.origin.subtype(); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public Set<String> params() { |
| 81 | + return this.origin.params(); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public Optional<String> param(final String name) { |
| 86 | + return this.origin.param(name); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public String toString() { |
| 91 | + return this.origin.toString(); |
| 92 | + } |
| 93 | + } |
37 | 94 | } |
0 commit comments