congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
StreamResource
Code IndexAdd Tabnine to your IDE (free)

How to use
StreamResource
in
org.apache.juneau.http

Best Java code snippets using org.apache.juneau.http.StreamResource (Showing top 19 results out of 315)

origin: apache/juneau

  /**
   * Create a new {@link StreamResource} using values in this builder.
   *
   * @return A new immutable {@link StreamResource} object.
   * @throws IOException
   */
  public StreamResource build() throws IOException {
    return new StreamResource(this);
  }
}
origin: apache/juneau

@RestMethod
public StreamResource a05() throws Exception {
  return StreamResource.create().contents(new ByteArrayInputStream("foo".getBytes())).build();
}
origin: apache/juneau

  @RestMethod
  public StreamResource a07() throws Exception {
    return StreamResource.create().contents(new StringBuilder("foo")).build();
  }
}
origin: apache/juneau

@RestMethod
public StreamResource a04() throws Exception {
  return StreamResource.create().contents("foo".getBytes()).build();
}
origin: org.apache.juneau/juneau-marshall

  /**
   * Create a new {@link StreamResource} using values in this builder.
   *
   * @return A new immutable {@link StreamResource} object.
   * @throws IOException
   */
  public StreamResource build() throws IOException {
    return new StreamResource(this);
  }
}
origin: apache/juneau

@RestMethod
public StreamResource a06() throws Exception {
  return StreamResource.create().contents(new StringReader("foo")).build();
}
origin: apache/juneau

  /**
   * Create a new {@link StreamResource} using values in this builder.
   *
   * @return A new immutable {@link StreamResource} object.
   * @throws IOException
   */
  public StreamResource build() throws IOException {
    return new StreamResource(this);
  }
}
origin: apache/juneau

@RestMethod
public StreamResource a01() throws Exception {
  return StreamResource.create().contents("foo").build();
}
origin: apache/juneau

String mediaType = mimetypesFileTypeMap.getContentType(name);
Map<String,Object> responseHeaders = sfm.responseHeaders != null ? sfm.responseHeaders : staticFileResponseHeaders;
sr = new StreamResource(MediaType.forString(mediaType), responseHeaders, true, is);
break;
origin: apache/juneau

@RestMethod
public StreamResource a02() throws Exception {
  return StreamResource.create().header("Foo", "Bar").build();
}
origin: org.apache.juneau/juneau-rest-server

String mediaType = mimetypesFileTypeMap.getContentType(name);
Map<String,Object> responseHeaders = sfm.responseHeaders != null ? sfm.responseHeaders : staticFileResponseHeaders;
sr = new StreamResource(MediaType.forString(mediaType), responseHeaders, true, is);
break;
origin: apache/juneau

@RestMethod
public StreamResource a03() throws Exception {
  return StreamResource.create().mediaType(MediaType.JSON).build();
}
origin: apache/juneau

String mediaType = mimetypesFileTypeMap.getContentType(name);
Map<String,Object> responseHeaders = sfm.responseHeaders != null ? sfm.responseHeaders : staticFileResponseHeaders;
sr = new StreamResource(MediaType.forString(mediaType), responseHeaders, true, is);
break;
origin: apache/juneau

/**
 * 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();
}
origin: org.apache.juneau/juneau-rest-server

/**
 * 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();
}
origin: apache/juneau

/**
 * 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();
}
origin: apache/juneau

return (T)StreamResource.create().headers(headers).mediaType(mediaType).contents(getInputStream()).build();
origin: org.apache.juneau/juneau-rest-client

return (T)StreamResource.create().headers(headers).mediaType(mediaType).contents(getInputStream()).build();
origin: apache/juneau

return (T)StreamResource.create().headers(headers).mediaType(mediaType).contents(getInputStream()).build();
org.apache.juneau.httpStreamResource

Javadoc

Represents the contents of a byte stream file with convenience methods for adding HTTP response headers.


These objects can to be returned as responses by REST methods.

StreamResources are meant to be thread-safe and reusable objects.
The contents of the request passed into the constructor are immediately converted to read-only byte arrays.

Instances of this class can be built using Builder.

See Also:
  • juneau-rest-server.RestMethod.StreamResource

Most used methods

  • create
    Creates a new instance of a Builder for this class.
  • <init>

Popular in Java

  • Reading from database using SQL prepared statement
  • startActivity (Activity)
  • getResourceAsStream (ClassLoader)
  • putExtra (Intent)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • String (java.lang)
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now