⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mockfileitem.java

📁 springlive ch8
💻 JAVA
字号:
package org.appfuse.web;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

import org.apache.commons.fileupload.FileItem;

public class MockFileItem implements FileItem {

    private String fieldName;
    private String contentType;
    private String name;
    private String value;

    private File writtenFile;
    private boolean deleted;

    public MockFileItem(String fieldName, String contentType, String name, String value) {
        this.fieldName = fieldName;
        this.contentType = contentType;
        this.name = name;
        this.value = value;
    }

    public InputStream getInputStream() throws IOException {
        return new ByteArrayInputStream(value.getBytes());
    }

    public String getContentType() {
        return contentType;
    }

    public String getName() {
        return name;
    }

    public boolean isInMemory() {
        return true;
    }

    public long getSize() {
        return value.length();
    }

    public byte[] get() {
        return value.getBytes();
    }

    public String getString(String encoding) throws UnsupportedEncodingException {
        return new String(get(), encoding);
    }

    public String getString() {
        return value;
    }

    public void write(File file) throws Exception {
        this.writtenFile = file;
    }

    public File getWrittenFile() {
        return writtenFile;
    }

    public void delete() {
        this.deleted = true;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String s) {
        this.fieldName = s;
    }

    public boolean isFormField() {
        return (this.name == null);
    }

    public void setFormField(boolean b) {
        throw new UnsupportedOperationException();
    }

    public OutputStream getOutputStream() throws IOException {
        throw new UnsupportedOperationException();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -