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

org.gs4tr.gcc.restclient.request.UploadContentReferenceRequest Maven / Gradle / Ivy

Go to download

GlobalLink Connect Cloud java is a library to connect your system to GlobalLink Connect Cloud REST API.

There is a newer version: 3.1.3
Show newest version
package org.gs4tr.gcc.restclient.request;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import org.gs4tr.gcc.restclient.util.StringUtils;

public class UploadContentReferenceRequest extends GCRequest {

	private byte[] contents;
	private String fileName;

	public UploadContentReferenceRequest(String filePath) throws IOException {
		this(filePath, null);
	}

	public UploadContentReferenceRequest(String filePath, String name) throws IOException {
		File file = new File(filePath);
		if (!file.exists()) {
			throw new IllegalArgumentException("File does not exist - " + filePath);
		}

		this.contents = Files.readAllBytes(Paths.get(filePath));
		this.fileName = name;
		if (StringUtils.isNullOrEmpty(name)) {
			this.fileName = file.getName();
		}
	}

	public UploadContentReferenceRequest(byte[] contents, String name) {
		this.contents = contents;
		if (contents == null || contents.length <= 0) {
			throw new IllegalArgumentException("Byte array with contents is empty");
		}
		if (StringUtils.isNullOrEmpty(name)) {
			throw new IllegalArgumentException("File name is required");
		}

		this.fileName = name;
	}

	public Map getParameters() {
		Map parameters = new HashMap();
		parameters.putAll(super.getParameters());

		parameters.put("name", this.fileName);
		parameters.put("file", this.contents);
		return parameters;
	}

	public byte[] getContents() {
		return contents;
	}

	public void setContents(byte[] contents) {
		this.contents = contents;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy