/** * Returns an instance of a {@link StreamResource} that represents the contents of a resource binary file from the * classpath. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder} * <li class='jm'>{@link org.apache.juneau.rest.RestRequest#getClasspathStreamResource(String)} * </ul> * * @param name The name of the resource (i.e. the value normally passed to {@link Class#getResourceAsStream(String)}. * @param mediaType The value to set as the <js>"Content-Type"</js> header for this object. * @param cached If <jk>true</jk>, the resource will be read into a byte array for fast serialization. * @return A new stream resource, or <jk>null</jk> if resource could not be found. * @throws IOException */ @SuppressWarnings("resource") public StreamResource getClasspathStreamResource(String name, MediaType mediaType, boolean cached) throws IOException { InputStream is = context.getClasspathResource(name, getLocale()); if (is == null) return null; StreamResource.Builder b = StreamResource.create().mediaType(mediaType).contents(is); if (cached) b.cached(); return b.build(); }
/** * Returns an instance of a {@link StreamResource} that represents the contents of a resource binary file from the * classpath. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder} * <li class='jm'>{@link org.apache.juneau.rest.RestRequest#getClasspathStreamResource(String)} * </ul> * * @param name The name of the resource (i.e. the value normally passed to {@link Class#getResourceAsStream(String)}. * @param mediaType The value to set as the <js>"Content-Type"</js> header for this object. * @param cached If <jk>true</jk>, the resource will be read into a byte array for fast serialization. * @return A new stream resource, or <jk>null</jk> if resource could not be found. * @throws IOException */ @SuppressWarnings("resource") public StreamResource getClasspathStreamResource(String name, MediaType mediaType, boolean cached) throws IOException { InputStream is = context.getClasspathResource(name, getLocale()); if (is == null) return null; StreamResource.Builder b = StreamResource.create().mediaType(mediaType).contents(is); if (cached) b.cached(); return b.build(); }
/** * Returns an instance of a {@link StreamResource} that represents the contents of a resource binary file from the * classpath. * * <h5 class='section'>See Also:</h5> * <ul> * <li class='jf'>{@link org.apache.juneau.rest.RestContext#REST_classpathResourceFinder} * <li class='jm'>{@link org.apache.juneau.rest.RestRequest#getClasspathStreamResource(String)} * </ul> * * @param name The name of the resource (i.e. the value normally passed to {@link Class#getResourceAsStream(String)}. * @param mediaType The value to set as the <js>"Content-Type"</js> header for this object. * @param cached If <jk>true</jk>, the resource will be read into a byte array for fast serialization. * @return A new stream resource, or <jk>null</jk> if resource could not be found. * @throws IOException */ @SuppressWarnings("resource") public StreamResource getClasspathStreamResource(String name, MediaType mediaType, boolean cached) throws IOException { InputStream is = context.getClasspathResource(name, getLocale()); if (is == null) return null; StreamResource.Builder b = StreamResource.create().mediaType(mediaType).contents(is); if (cached) b.cached(); return b.build(); }