Class VitamAsyncInputStreamResponse

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class VitamAsyncInputStreamResponse
    extends javax.ws.rs.core.Response
    This class implements a fake InputStream from a Response such that the response will be closed once the stream is closed itself. It should replace all the AsyncInputStreamHelper

    Example of usages:

    When using specific headers:

    Map<String, String> headers = new HashMap<>();
    headers.put(HttpHeaders.CONTENT_TYPE, response.getMediaType().toString());
    headers.put(HttpHeaders.CONTENT_DISPOSITION, response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION));
    headers.put(GlobalDataRest.X_QUALIFIER, xQualifier);
    headers.put(GlobalDataRest.X_VERSION, xVersion);
    return new VitamAsyncInputStreamResponse(response, Status.OK, headers);

    When using standard headers:

    return new VitamAsyncInputStreamResponse(response, Status.OK, MediaType.APPLICATION_OCTET_STREAM_TYPE);

    When using the native response as source:

    return new VitamAsyncInputStreamResponse(response);
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.ws.rs.core.Response

        javax.ws.rs.core.Response.ResponseBuilder, javax.ws.rs.core.Response.Status, javax.ws.rs.core.Response.StatusType
    • Constructor Summary

      Constructors 
      Constructor Description
      VitamAsyncInputStreamResponse​(java.io.InputStream inputStream, javax.ws.rs.core.Response.Status status, java.util.Map<java.lang.String,​java.lang.String> headers)  
      VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response)  
      VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response, javax.ws.rs.core.Response.Status status, java.util.Map<java.lang.String,​java.lang.String> headers)  
      VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response, javax.ws.rs.core.Response.Status status, javax.ws.rs.core.MediaType mediaType)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean bufferEntity()  
      void close()  
      java.util.Set<java.lang.String> getAllowedMethods()  
      java.util.Map<java.lang.String,​javax.ws.rs.core.NewCookie> getCookies()  
      java.util.Date getDate()  
      static java.util.Map<java.lang.String,​java.lang.String> getDefaultMapFromResponse​(javax.ws.rs.core.Response response)
      Return the default Map of headers from Response
      java.lang.Object getEntity()  
      javax.ws.rs.core.EntityTag getEntityTag()  
      javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> getHeaders()  
      java.lang.String getHeaderString​(java.lang.String name)  
      java.util.Locale getLanguage()  
      java.util.Date getLastModified()  
      int getLength()  
      javax.ws.rs.core.Link getLink​(java.lang.String relation)  
      javax.ws.rs.core.Link.Builder getLinkBuilder​(java.lang.String relation)  
      java.util.Set<javax.ws.rs.core.Link> getLinks()  
      java.net.URI getLocation()  
      javax.ws.rs.core.MediaType getMediaType()  
      javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> getMetadata()  
      int getStatus()  
      javax.ws.rs.core.Response.StatusType getStatusInfo()  
      javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> getStringHeaders()  
      boolean hasEntity()  
      boolean hasLink​(java.lang.String relation)  
      <T> T readEntity​(java.lang.Class<T> entityType)  
      <T> T readEntity​(java.lang.Class<T> entityType, java.lang.annotation.Annotation[] annotations)  
      <T> T readEntity​(javax.ws.rs.core.GenericType<T> entityType)  
      <T> T readEntity​(javax.ws.rs.core.GenericType<T> entityType, java.lang.annotation.Annotation[] annotations)  
      • Methods inherited from class javax.ws.rs.core.Response

        accepted, accepted, created, fromResponse, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, status, temporaryRedirect
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • VitamAsyncInputStreamResponse

        public VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response)
        Parameters:
        response -
      • VitamAsyncInputStreamResponse

        public VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response,
                                             javax.ws.rs.core.Response.Status status,
                                             javax.ws.rs.core.MediaType mediaType)
        Parameters:
        response -
        status -
        mediaType -
      • VitamAsyncInputStreamResponse

        public VitamAsyncInputStreamResponse​(javax.ws.rs.core.Response response,
                                             javax.ws.rs.core.Response.Status status,
                                             java.util.Map<java.lang.String,​java.lang.String> headers)
        Parameters:
        response -
        status -
        headers -
      • VitamAsyncInputStreamResponse

        public VitamAsyncInputStreamResponse​(java.io.InputStream inputStream,
                                             javax.ws.rs.core.Response.Status status,
                                             java.util.Map<java.lang.String,​java.lang.String> headers)
        Parameters:
        inputStream -
        status -
        headers -
    • Method Detail

      • getDefaultMapFromResponse

        public static final java.util.Map<java.lang.String,​java.lang.String> getDefaultMapFromResponse​(javax.ws.rs.core.Response response)
        Return the default Map of headers from Response
        Parameters:
        response -
        Returns:
        the default map
      • getStatus

        public int getStatus()
        Specified by:
        getStatus in class javax.ws.rs.core.Response
      • getStatusInfo

        public javax.ws.rs.core.Response.StatusType getStatusInfo()
        Specified by:
        getStatusInfo in class javax.ws.rs.core.Response
      • getMediaType

        public javax.ws.rs.core.MediaType getMediaType()
        Specified by:
        getMediaType in class javax.ws.rs.core.Response
      • getEntity

        public java.lang.Object getEntity()
        Specified by:
        getEntity in class javax.ws.rs.core.Response
      • readEntity

        public <T> T readEntity​(java.lang.Class<T> entityType)
        Specified by:
        readEntity in class javax.ws.rs.core.Response
      • readEntity

        public <T> T readEntity​(javax.ws.rs.core.GenericType<T> entityType)
        Specified by:
        readEntity in class javax.ws.rs.core.Response
      • readEntity

        public <T> T readEntity​(java.lang.Class<T> entityType,
                                java.lang.annotation.Annotation[] annotations)
        Specified by:
        readEntity in class javax.ws.rs.core.Response
      • readEntity

        public <T> T readEntity​(javax.ws.rs.core.GenericType<T> entityType,
                                java.lang.annotation.Annotation[] annotations)
        Specified by:
        readEntity in class javax.ws.rs.core.Response
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in class javax.ws.rs.core.Response
      • getHeaders

        public javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> getHeaders()
        Overrides:
        getHeaders in class javax.ws.rs.core.Response
      • hasEntity

        public boolean hasEntity()
        Specified by:
        hasEntity in class javax.ws.rs.core.Response
      • bufferEntity

        public boolean bufferEntity()
        Specified by:
        bufferEntity in class javax.ws.rs.core.Response
      • getLanguage

        public java.util.Locale getLanguage()
        Specified by:
        getLanguage in class javax.ws.rs.core.Response
      • getLength

        public int getLength()
        Specified by:
        getLength in class javax.ws.rs.core.Response
      • getAllowedMethods

        public java.util.Set<java.lang.String> getAllowedMethods()
        Specified by:
        getAllowedMethods in class javax.ws.rs.core.Response
      • getCookies

        public java.util.Map<java.lang.String,​javax.ws.rs.core.NewCookie> getCookies()
        Specified by:
        getCookies in class javax.ws.rs.core.Response
      • getEntityTag

        public javax.ws.rs.core.EntityTag getEntityTag()
        Specified by:
        getEntityTag in class javax.ws.rs.core.Response
      • getDate

        public java.util.Date getDate()
        Specified by:
        getDate in class javax.ws.rs.core.Response
      • getLastModified

        public java.util.Date getLastModified()
        Specified by:
        getLastModified in class javax.ws.rs.core.Response
      • getLocation

        public java.net.URI getLocation()
        Specified by:
        getLocation in class javax.ws.rs.core.Response
      • getLinks

        public java.util.Set<javax.ws.rs.core.Link> getLinks()
        Specified by:
        getLinks in class javax.ws.rs.core.Response
      • hasLink

        public boolean hasLink​(java.lang.String relation)
        Specified by:
        hasLink in class javax.ws.rs.core.Response
      • getLink

        public javax.ws.rs.core.Link getLink​(java.lang.String relation)
        Specified by:
        getLink in class javax.ws.rs.core.Response
      • getLinkBuilder

        public javax.ws.rs.core.Link.Builder getLinkBuilder​(java.lang.String relation)
        Specified by:
        getLinkBuilder in class javax.ws.rs.core.Response
      • getMetadata

        public javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> getMetadata()
        Specified by:
        getMetadata in class javax.ws.rs.core.Response
      • getStringHeaders

        public javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> getStringHeaders()
        Specified by:
        getStringHeaders in class javax.ws.rs.core.Response
      • getHeaderString

        public java.lang.String getHeaderString​(java.lang.String name)
        Specified by:
        getHeaderString in class javax.ws.rs.core.Response