All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ratpack.file.FileRenderer Maven / Gradle / Ivy

There is a newer version: 2.0.0-rc-1
Show newest version
/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ratpack.file;

import ratpack.render.Renderer;

import java.nio.file.Path;

/**
 * A renderer for static files.
 * 

* An implementation of this is always provided by Ratpack core. *

* Example usage: *

 * import ratpack.handling.Handler;
 * import ratpack.handling.Context;
 * import java.nio.file.Path;
 *
 * public class FileRenderingHandler implements Handler {
 *   public void handle(Context context) {
 *     Path file = context.file("some/file/to/serve.txt");
 *     context.render(file);
 *   }
 * }
 * 
*

* Use of this renderer should be preferred over {@link ratpack.http.Response#sendFile} as it handles * HTTP Caching by way of the {@code If-Modified-Since} header, * based on timestamps reported by the filesystem. *

* If the {@link ratpack.http.Response#contentType(String)} has not been set prior to calling this method, * it will be guessed by retrieving the {@link MimeTypes} from the context and using it to calculate the type * based on the name of the file. */ public interface FileRenderer extends Renderer {}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy