Example usage for org.apache.commons.fileupload LiferayFileItem getInputStream

List of usage examples for org.apache.commons.fileupload LiferayFileItem getInputStream

Introduction

In this page you can find the example usage for org.apache.commons.fileupload LiferayFileItem getInputStream.

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Returns an java.io.InputStream InputStream that can be used to retrieve the contents of the file.

Usage

From source file:com.liferay.portal.upload.UploadServletRequestImpl.java

protected InputStream getInputStream(LiferayFileItem liferayFileItem, boolean deleteOnClose)
        throws IOException {

    InputStream inputStream = null;

    if (liferayFileItem.isInMemory() && (liferayFileItem.getSize() > 0)) {
        inputStream = liferayFileItem.getInputStream();
    } else if (!liferayFileItem.isInMemory()) {
        inputStream = new ByteArrayFileInputStream(liferayFileItem.getStoreLocation(),
                liferayFileItem.getSizeThreshold(), deleteOnClose);
    }/* w w  w . j  a va 2s  .com*/

    return inputStream;
}

From source file:com.liferay.portal.upload.UploadServletRequestImpl.java

public File getFile(String name, boolean forceCreate) {
    if (getFileName(name) == null) {
        return null;
    }//from w  ww  .  jav a  2  s.com

    LiferayFileItem[] liferayFileItems = _params.get(name);

    File file = null;

    if ((liferayFileItems != null) && (liferayFileItems.length > 0)) {
        LiferayFileItem liferayFileItem = liferayFileItems[0];

        file = liferayFileItem.getStoreLocation();

        if (liferayFileItem.isInMemory() && forceCreate) {
            try {
                FileUtil.write(file, liferayFileItem.getInputStream());
            } catch (IOException ioe) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to write temporary file " + file.getAbsolutePath(), ioe);
                }
            }
        }
    }

    return file;
}