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

io.atlassian.util.adapter.javax.servlet.http.JavaXPartAdapter Maven / Gradle / Ivy

Go to download

A collection of classes for adapting Servlet API 4.0 objects to Servlet API 5.0 and vice versa.

There is a newer version: 0.1.0
Show newest version
package io.atlassian.util.adapter.javax.servlet.http;

import io.atlassian.util.adapter.jakarta.servlet.http.JakartaPartAdapter;

import javax.servlet.http.Part;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;

import static io.atlassian.util.adapter.util.WrapperUtil.applyIfNonNull;
import static java.util.Objects.requireNonNull;

public class JavaXPartAdapter implements Part {

    private final jakarta.servlet.http.Part delegate;

    public static Part from(jakarta.servlet.http.Part delegate) {
        if (delegate instanceof JakartaPartAdapter castDelegate) {
            return castDelegate.getDelegate();
        }
        return applyIfNonNull(delegate, JavaXPartAdapter::new);
    }

    JavaXPartAdapter(jakarta.servlet.http.Part delegate) {
        this.delegate = requireNonNull(delegate);
    }

    public jakarta.servlet.http.Part getDelegate() {
        return delegate;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return delegate.getInputStream();
    }

    @Override
    public String getContentType() {
        return delegate.getContentType();
    }

    @Override
    public String getName() {
        return delegate.getName();
    }

    @Override
    public String getSubmittedFileName() {
        return delegate.getSubmittedFileName();
    }

    @Override
    public long getSize() {
        return delegate.getSize();
    }

    @Override
    public void write(String fileName) throws IOException {
        delegate.write(fileName);
    }

    @Override
    public void delete() throws IOException {
        delegate.delete();
    }

    @Override
    public String getHeader(String name) {
        return delegate.getHeader(name);
    }

    @Override
    public Collection getHeaders(String name) {
        return delegate.getHeaders(name);
    }

    @Override
    public Collection getHeaderNames() {
        return delegate.getHeaderNames();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy