www.dextsolution.com
DEXTUPLOAD
JK
menu toggleReference > dextuploadjk > support > spring > JKStreamDownloadView

dextuploadjk.support.spring
Class JKStreamDownloadView

Minimum version
1.0.0
Minimum environment
Java 17, Spring Framework 6.0.14, Spring Boot 3.0.12
Description

Concrete class of the JKAbstractDownloadableView abstract class that supports file-type responses in the Spring Framework environment.

Use it when you want to download data in memory rather than a physical file.

@RequestMapping(value = "download-stream", method = RequestMethod.GET)
public ModelAndView downloadStream() throws IOException {
  
    // Download the text data written as '0123456789' to a file.
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 1000; i++) {
        sb.append("0123456789\r\n");
    }

    InputStream is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
      
    // Create a JKStreamDownloadView object to download in stream format.
    JKStreamDownloadView view = new JKStreamDownloadView();
      
    // Set the input stream.
    view.setInputStream(is);
    view.setFilename("File name to download");
    view.setMime("text/plain");
    view.setCharsetName("UTF-8");
    // Set the stream to close automatically.
    view.setAutoClosingStream(true);
      
    return new ModelAndView(view);
}

When using a JKStreamDownloadView object to perform a download, the client cache is disabled and features such as downloading partial content are not available.

Constructor

JKStreamDownloadView

  • Create an object of class JKStreamDownloadView.

  • Signatures

    public JKStreamDownloadView()
    public JKStreamDownloadView(InputStream inputStream)
    public JKStreamDownloadView(InputStream inputStream, String filename)
    public JKStreamDownloadView(InputStream inputStream, String filename, String mime)
    public JKStreamDownloadView(InputStream inputStream, String filename, String mime, boolean inline)
    public JKStreamDownloadView(InputStream inputStream, String filename, String mime, boolean inline, int downloadStreamBufferSize)
    public JKStreamDownloadView(InputStream inputStream, String filename, String mime, boolean inline, int downloadStreamBufferSize, boolean autoClosingStream)
    public JKStreamDownloadView(InputStream inputStream, String filename, String mime, FileResponseContentDisposition contentDisposition, int downloadStreamBufferSize, boolean autoClosingStream)
  • Parameters

    Name Type Description
    inputStream java.io.InputStream An InputStream object to provide the data
    filename java.lang.String A file name for the client to download
    mime java.lang.String The value of the Content-Type header setting. The default value is application/octet-stream.
    inline boolean

    If you set the parameter value to true, the file will not be downloaded and can be opened directly in the browser.

    downloadStreamBufferSize int

    When downloading, the size of the buffer to write to the response stream at once.

    The default value is 32768 bytes.

    autoClosingStream boolean

    Whether to close the InputStream object when all data is written to the response stream.

    The default is false.

    contentDisposition dextuploadjk.FileResponseContentDisposition How file content is delivered to the browser
Methods

getInputStream

  • Returns a java.io.InputStream object to provide the data.

  • Signatures

    public InputStream getInputStream()
  • Return

    The java.io.InputStream object to provide data to

setInputStream

  • Sets the java.io.InputStream object to provide data to.

  • Signatures

    public void setInputStream(InputStream inputStream)
  • Parameters

    Name Type Description
    inputStream java.io.InputStream InputStream object to provide data to

isAutoClosingStream

  • Returns whether to automatically close the InputStream object when downloading data.

  • Signatures

    public boolean isAutoClosingStream()
  • Return

    true, false

setAutoClosingStream

  • Sets whether to automatically close the InputStream object when data is downloaded.

  • Signatures

    public void setAutoClosingStream(boolean autoClosingStream)
  • Parameters

    Name Type Description
    autoClosingStream boolean If the parameter value is true, the InputStream object is closed after writing the response data to the response buffer.

doRenderImpl

See the doRenderImpl method of the JKAbstractDownloadableView abstract class.

getFilename

See the getFilename method of the JKAbstractDownloadableView abstract class.

setFilename

See the setFilename method of the JKAbstractDownloadableView abstract class.

getMime

See the getMime method of the JKAbstractDownloadableView abstract class.

setMime

See the setMime method of the JKAbstractDownloadableView abstract class.

isInline

See the isInline method of the JKAbstractDownloadableView abstract class.

setInline

See the setInline method of the JKAbstractDownloadableView abstract class.

getCharsetName

See the getCharsetName method of the JKAbstractDownloadableView abstract class.

setCharsetName

See the setCharsetName method of the JKAbstractDownloadableView abstract class.

getDownloadStreamBufferSize

See the getDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

setDownloadStreamBufferSize

See the setDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

getContentDisposition

See the getContentDisposition method of the JKAbstractDownloadableView abstract class.

setContentDisposition

See the setContentDisposition method of the JKAbstractDownloadableView abstract class.