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

com.backblaze.b2.client.structures.B2UploadFileRequest Maven / Gradle / Ivy

Go to download

The core logic for B2 SDK for Java. Does not include any implementations of B2WebApiClient.

There is a newer version: 6.3.0
Show newest version
/*
 * Copyright 2017, Backblaze Inc. All Rights Reserved.
 * License https://www.backblaze.com/using_b2_code.html
 */
package com.backblaze.b2.client.structures;

import com.backblaze.b2.client.contentSources.B2ContentSource;

import java.util.Map;
import java.util.TreeMap;

public class B2UploadFileRequest {
    private final String bucketId;
    private final String fileName;
    private final String contentType;
    private final B2ContentSource contentSource;
    private final Map fileInfo;
    private final B2UploadListener listener;


    private B2UploadFileRequest(String bucketId,
                                String fileName,
                                String contentType,
                                Map fileInfo,
                                B2ContentSource contentSource,
                                B2UploadListener listener) {
        this.bucketId = bucketId;
        this.fileName = fileName;
        this.contentType = contentType;
        this.fileInfo = fileInfo;  // make sorted, immutable copyOf?!
        this.contentSource = contentSource;
        this.listener = (listener != null) ? listener : B2UploadListener.noopListener();
    }

    public String getBucketId() {
        return bucketId;
    }

    public String getFileName() {
        return fileName;
    }

    public String getContentType() {
        return contentType;
    }

    public B2ContentSource getContentSource() {
        return contentSource;
    }

    public Map getFileInfo() {
        return fileInfo;
    }

    public B2UploadListener getListener() {
        return listener;
    }

    public static Builder builder(String bucketId,
                                  String fileName,
                                  String contentType,
                                  B2ContentSource source) {
        return new Builder(bucketId, fileName, contentType, source);
    }

    public static class Builder {
        private String bucketId;
        private String fileName;
        private String contentType;
        private B2ContentSource source;
        private Map info;
        private B2UploadListener listener;

        Builder(String bucketId,
                String fileName,
                String contentType,
                B2ContentSource source) {
            this.bucketId = bucketId;
            this.fileName = fileName;
            this.contentType = contentType;
            this.source = source;
            this.info = new TreeMap<>();
        }

        public Builder setCustomField(String name, String value) {
            info.put(name, value);
            return this;
        }

        public Builder setCustomFields(Map fileInfo) {
            if (fileInfo != null) {
                info.putAll(fileInfo);
            }
            return this;
        }

        public Builder setListener(B2UploadListener listener) {
            this.listener = listener;
            return this;
        }

        public B2UploadFileRequest build() {
            return new B2UploadFileRequest(bucketId,
                    fileName,
                    contentType,
                    info,
                    source,
                    listener);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy