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

com.ithit.webdav.integration.android.AndroidDavResponse Maven / Gradle / Ivy

The newest version!
package com.ithit.webdav.integration.android;

import com.ithit.webdav.server.DavResponse;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * NanoHttpd specific implementation of DavResponse.
 */
public class AndroidDavResponse extends DavResponse {

    private final Map headers = new HashMap();
    private ByteArrayOutputStream inMemoryOutputStream;
    private String contentType;
    private String encoding;
    private long length = -1;
    private Status status = new Status(200, "Ok");

    public AndroidDavResponse() {
        inMemoryOutputStream = new ByteArrayOutputStream();
    }

    public void addHeader(String name, String value) {
        headers.put(name, value);
    }

    public void setStatus(int code, String description) {
        this.status = new Status(code, description);
    }

    public void setContentLength(long length) {
        this.length = length;
    }

    public void setContentType(String type) {
        contentType = type;
    }

    public void setCharacterEncoding(String encoding) {
        this.encoding = encoding;
    }

    public OutputStream getOutputStream() throws IOException {
        return inMemoryOutputStream;
    }

    public void setHeader(String name, String value) {
        headers.put(name, value);
    }

    public Object getOriginalResponse() {
        return this;
    }

    public String getContentType() {
        return contentType + "; charset=utf-8";
    }

    public String getEncoding() {
        return encoding;
    }

    public long getLength() {
        return length;
    }

    public Status getStatus() {
        return status;
    }

    public InputStream getInputStream() {
        return new ByteArrayInputStream(inMemoryOutputStream.toByteArray());
    }

    public Map getHeaders() {
        return headers;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy