-
Notifications
You must be signed in to change notification settings - Fork 12
/
RestMediaResources.java
44 lines (36 loc) · 1.1 KB
/
RestMediaResources.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package impl.srv.rest;
import javax.ws.rs.WebApplicationException;
import impl.srv.shared.JavaMedia;
import microgram.api.java.Media;
import microgram.api.java.Result;
import microgram.api.rest.RestMediaStorage;
public class RestMediaResources extends RestResource implements RestMediaStorage {
final Media impl;
final String baseUri;
public RestMediaResources(String baseUri ) {
this.baseUri = baseUri + RestMediaStorage.PATH;
this.impl = new JavaMedia();
}
@Override
public String upload(byte[] bytes) {
Result<String> result = impl.upload(bytes);
if (result.isOK())
return baseUri + "/" + result.value();
else
throw new WebApplicationException(super.statusCode(result));
}
@Override
public byte[] download(String id) {
Result<byte[]> result = impl.download( id );
if( result.isOK() )
return result.value();
else
throw new WebApplicationException( super.statusCode( result )) ;
}
@Override
public void delete(String id) {
Result<Void> results = impl.delete ( id );
if ( ! results.isOK() )
throw new WebApplicationException( super.statusCode( results ) ) ;
}
}