Package systems.dmx.files
Class UploadedFile
- java.lang.Object
-
- systems.dmx.files.UploadedFile
-
public class UploadedFile extends Object
An InputStream attributable by name and size values. TODO: rename to NamedInputStream2 use cases:
- Representation of an uploaded file
Files are uploaded via the REST API by POSTing
multipart/form-data
to a resource method which consumesmultipart/form-data
and has UploadedFile as its entity parameter. - Created via constructor to represent any streamable (possibly in-memory) data and additional size and (optional) name information.
- Author:
- Jörg Richter
- Representation of an uploaded file
-
-
Constructor Summary
Constructors Constructor Description UploadedFile(String name, long size, InputStream in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStream
getInputStream()
Returns an InputStream that can be used to retrieve the contents of the uploaded file.String
getName()
Returns the original filename in the client's filesystem, as provided by the browser (or other client software).long
getSize()
String
getString()
Returns the contents of the uploaded file as a String, using the default character encoding.String
getString(String encoding)
Returns the contents of the uploaded file as a String, using the given encoding.void
setBuffered()
Transforms the InputStream into a BufferedInputStream and sets a mark.String
toString()
-
-
-
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 callingsetBuffered()
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.
-
-