All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gargoylesoftware.htmlunit.util.KeyDataPair Maven / Gradle / Ivy

Go to download

Vaadin is a web application framework for Rich Internet Applications (RIA). Vaadin enables easy development and maintenance of fast and secure rich web applications with a stunning look and feel and a wide browser support. It features a server-side architecture with the majority of the logic running on the server. Ajax technology is used at the browser-side to ensure a rich and interactive user experience.

There is a newer version: 1.2.0
Show newest version
/*
 * Copyright (c) 2002-2011 Gargoyle Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gargoylesoftware.htmlunit.util;

import java.io.File;

/**
 * A holder for a key/value pair that represents a file to upload.
 *
 * @version $Revision: 6209 $
 * @author Brad Clarke
 * @author David D. Kilzer
 * @author Mike Bowler
 */
public class KeyDataPair extends NameValuePair {

    private final File fileObject_;
    private final String contentType_;
    private final String charset_;
    private byte[] data_;

    /**
     * Creates an instance.
     *
     * @param key the key
     * @param file the file
     * @param contentType the content type
     * @param charset the charset encoding
     */
    public KeyDataPair(final String key, final File file, final String contentType,
            final String charset) {

        super(key, file.getName());

        if (file.exists()) {
            fileObject_ = file;
        }
        else {
            fileObject_ = null;
        }

        contentType_ = contentType;
        charset_ = charset;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object object) {
        // this is overwritten to make FindBugs happy
        // and to make it clear, that we really want to have
        // the same equals semantic like our parent class
        return super.equals(object);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        // this is overwritten to make FindBugs happy
        // and to make it clear, that we really want to have
        // the same hashCode like our parent class
        return super.hashCode();
    }

    /**
     * @return the {@link File} object if the file exists, else null
     */
    public File getFile() {
        return fileObject_;
    }

    /**
     * Gets the charset encoding for this file upload.
     * @return the charset
     */
    public String getCharset() {
        return charset_;
    }

    /**
     * Gets the content type for this file upload.
     * @return the content type
     */
    public String getContentType() {
        return contentType_;
    }

    /**
     * Gets in-memory data assigned to file value.
     * @return null if the file content should be used.
     */
    public byte[] getData() {
        return data_;
    }

    /**
     * Sets file value data. If nothing is set, the file content will be used.
     * @param data byte array with file data.
     */
    public void setData(final byte[] data) {
        data_ = data;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy