Search in sources :

Example 1 with StreamRepresentation

use of org.restlet.resource.StreamRepresentation in project GeoGig by boundlessgeo.

the class ConsoleResourceResource method handleGet.

@Override
public void handleGet() {
    final String resourceName;
    {
        String res = RESTUtils.getStringAttribute(getRequest(), "resource");
        if (null == res) {
            resourceName = "terminal.html";
        } else {
            resourceName = res;
        }
    }
    MediaType mediaType = guessMediaType(resourceName);
    getResponse().setEntity(new StreamRepresentation(mediaType) {

        @Override
        public void write(OutputStream outputStream) throws IOException {
            // System.out.println("returning " + resourceName);
            ByteStreams.copy(getStream(), outputStream);
        }

        @Override
        public InputStream getStream() throws IOException {
            InputStream inputStream = ConsoleResourceResource.class.getResourceAsStream(resourceName);
            return inputStream;
        }
    });
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) MediaType(org.restlet.data.MediaType) IOException(java.io.IOException) StreamRepresentation(org.restlet.resource.StreamRepresentation)

Aggregations

FileBackedOutputStream (com.google.common.io.FileBackedOutputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 MediaType (org.restlet.data.MediaType)1 StreamRepresentation (org.restlet.resource.StreamRepresentation)1