Package HTTP

Source Code of HTTP.HTTPFile

/*
Copyright (c) 2003-2008 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package HTTP;

import java.io.File;

import org.apache.commons.fileupload.FileItem;
import org.apache.log4j.Logger;

import Framework.BinaryData;
import Framework.ErrorMgr;
import Framework.TextData;
/**
* The HTTPFile class represents a file that is uploaded to an {@link HTTPAccess} server.
* The class can represent a binary or a text file sent by the client, which uses a content type of multipart/form-data in the HTTP request.
*
* NOTE: not all methods are implemented
*/
public class HTTPFile {
    public final static String HTTP_FILE_LIST = "qq_FileList";
    protected FileItem content;

    public HTTPFile() {
        super();
        Logger.getLogger("HTTPFile").warn("Default constructor to HTTPFile invoked, which is meaningless and dangerous.");
    }

    public HTTPFile(FileItem pFile) {
        super();
        this.content = pFile;
    }

    public BinaryData getBinaryBody() {
        return new BinaryData(this.content.get());
    }

    public void setBinaryBody(BinaryData binaryBody) {
        UnsupportedOperationException errorVar = new UnsupportedOperationException("setBinaryBody is not implemented on HTTPFile");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }

    public String getContentType() {
        return this.content.getContentType();
    }
    public void setContentType(String contentType) {
        UnsupportedOperationException errorVar = new UnsupportedOperationException("setContentType is not implemented on HTTPFile");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }

    public String getControlName() {
        return this.content.getFieldName();
    }
    public void setControlName(String controlName) {
        this.content.setFieldName(controlName);
    }

    public String getFileName() {
        return this.content.getName();
    }
    public void setFileName(String fileName) {
        UnsupportedOperationException errorVar = new UnsupportedOperationException("setFileName is not implemented on HTTPFile");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }

    public boolean getIsBinary() {
        byte []data = this.content.get();
        for (int i = 0; i < data.length; i++) {
            if (!Character.isDefined((char)data[i])) {
                return true;
            }
        }
        return false;
    }

    public void setIsBinary(boolean isBin) {
        UnsupportedOperationException errorVar = new UnsupportedOperationException("setIsBinary is not implemented on HTTPFile");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }

    public TextData getTextBody() {
        return new TextData(this.content.getString());
    }
    public void setTextBody(TextData textBody) {
        UnsupportedOperationException errorVar = new UnsupportedOperationException("setTextBody is not implemented on HTTPFile");
        ErrorMgr.addError(errorVar);
        throw errorVar;
    }

    public void write(File pFile) throws Exception {
        this.content.write(pFile);
    }
}
TOP

Related Classes of HTTP.HTTPFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.