Class UploadedFile


  • public class UploadedFile
    extends Object
    An InputStream attributable by name and size values. TODO: rename to NamedInputStream

    2 use cases:

    1. Representation of an uploaded file

      Files are uploaded via the REST API by POSTing multipart/form-data to a resource method which consumes multipart/form-data and has UploadedFile as its entity parameter.

    2. Created via constructor to represent any streamable (possibly in-memory) data and additional size and (optional) name information.
    Author:
    Jörg Richter
    • Constructor Detail

      • UploadedFile

        public UploadedFile​(String name,
                            long size,
                            InputStream in)
        Parameters:
        name - optional: a sole filename, no path information
    • Method Detail

      • getName

        public String getName()
        Returns the original filename in the client's filesystem, as provided by the browser (or other client software). In most cases, this will be the base file name, without path information. However, some clients, such as the Opera browser, do include path information.
      • getSize

        public long getSize()
      • getInputStream

        public InputStream getInputStream()
        Returns an InputStream that can be used to retrieve the contents of the uploaded file.
      • setBuffered

        public void setBuffered()
        Transforms the InputStream into a BufferedInputStream and sets a mark. This allows to call reset() later on in order to read the stream's bytes again. Should be called before you read any bytes from the stream.

        Call getInputStream() after calling setBuffered() in order to get the actual BufferedInputStream.

        Calling reset() without calling setBuffered() before throws an IOException.

      • getString

        public String getString()
        Returns the contents of the uploaded file as a String, using the default character encoding.
      • getString

        public String getString​(String encoding)
        Returns the contents of the uploaded file as a String, using the given encoding.