Created
June 4, 2014 21:46
-
-
Save ggtools/4f618850ad8edfbd1516 to your computer and use it in GitHub Desktop.
Restx Router to handle PUT of a video stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PutVideoRoute extends StdEntityRoute<InputStream, String> { | |
private final VideoResource videoResource; | |
public PutVideoRoute(EntityResponseWriterRegistry writerRegistry, VideoResource videoResource) { | |
super("Put Video Route", | |
new EntityRequestBodyReader<InputStream>() { | |
@Override | |
public Type getType() { | |
return InputStream.class; | |
} | |
@Override | |
public InputStream readBody(RestxRequest req, RestxContext ctx) throws IOException { | |
return req.getContentStream(); | |
} | |
}, | |
writerRegistry.<String>build(String.class, Optional.<String>absent()), | |
new StdRestxRequestMatcher("PUT", "/videos"), | |
HttpStatus.CREATED, RestxLogLevel.DEFAULT | |
); | |
this.videoResource = videoResource; | |
} | |
@Override | |
protected Optional<String> doRoute(RestxRequest restxRequest, RestxRequestMatch match, InputStream inputStream) throws IOException { | |
return Optional.of(videoResource.addVideo(inputStream)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment