com.pengrad.telegrambot.request.AbstractMultipartRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-telegram-bot-api Show documentation
Show all versions of java-telegram-bot-api Show documentation
Java API for Telegram Bot API
package com.pengrad.telegrambot.request;
import java.io.File;
/**
* stas
* 5/1/16.
*/
abstract public class AbstractMultipartRequest> extends AbstractSendRequest {
private boolean isMultipart;
private String fileName;
private String contentType;
public AbstractMultipartRequest(Object chatId, Object file) {
super(chatId);
if (file instanceof String) {
isMultipart = false;
} else if (file instanceof File) {
isMultipart = true;
fileName = ((File) file).getName();
} else if (file instanceof byte[]) {
isMultipart = true;
} else {
throw new IllegalArgumentException("Sending data should be String, File or byte[]");
}
add(getFileParamName(), file);
}
public T fileName(String fileName) {
this.fileName = fileName;
return thisAsT;
}
public T contentType(String contentType) {
this.contentType = contentType;
return thisAsT;
}
protected T thumb(Object thumb) {
isMultipart = true;
return add("thumb", thumb);
}
@Override
public boolean isMultipart() {
return isMultipart;
}
@Override
public String getFileName() {
if (fileName != null && !fileName.isEmpty()) {
return fileName;
} else {
return getDefaultFileName();
}
}
@Override
public String getContentType() {
return (contentType != null && !contentType.isEmpty()) ? contentType : getDefaultContentType();
}
abstract protected String getDefaultFileName();
abstract protected String getDefaultContentType();
abstract protected String getFileParamName();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy