io.proximax.upload.InputStreamParameterData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-chain-xipfs-sdk Show documentation
Show all versions of java-chain-xipfs-sdk Show documentation
Official ProximaX P2P Storage SDK Library in Java.
The newest version!
/*
*
* * Copyright 2018 ProximaX Limited
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/
package io.proximax.upload;
import java.io.InputStream;
import java.util.Map;
import java.util.function.Supplier;
import static io.proximax.utils.ParameterValidationUtils.checkParameter;
/**
* This model class is one type of the upload parameter data that defines a file upload
*/
public class InputStreamParameterData extends AbstractByteStreamParameterData {
private final Supplier inputStreamSupplier;
private InputStreamParameterData(Supplier inputStreamSupplier, String description, String name, String contentType, Map metadata) {
super(description, name, contentType, metadata);
checkParameter(inputStreamSupplier != null, "inputStreamSupplier is required");
this.inputStreamSupplier = inputStreamSupplier;
}
/**
* Get the byte stream
* @return the byte stream
*/
@Override
public InputStream getByteStream() {
return inputStreamSupplier.get();
}
/**
* Create instance by providing the file
* @param inputStreamSupplier the supplier of stream to upload
* @return the instance of this class
*/
public static InputStreamParameterData create(Supplier inputStreamSupplier) {
return create(inputStreamSupplier, null, null, null, null);
}
/**
* Create instance by providing the file
* @param inputStreamSupplier the supplier of stream to upload
* @param description a searchable description attach on the upload
* @param name a searchable name attach on the upload
* @param contentType the content type attach on the upload
* @param metadata a searchable key-pair metadata attach on the upload
* @return the instance of this class
*/
public static InputStreamParameterData create(Supplier inputStreamSupplier, String description, String name, String contentType, Map metadata) {
return new InputStreamParameterData(inputStreamSupplier, description, name, contentType, metadata);
}
}