ISnowflake
public static class Message.Attachment extends java.lang.Object implements ISnowflake
Message
file attachment.Constructor | Description |
---|---|
Attachment(long id,
java.lang.String url,
java.lang.String proxyUrl,
java.lang.String fileName,
int size,
int height,
int width,
net.dv8tion.jda.core.entities.impl.JDAImpl jda) |
Modifier and Type | Method | Description |
---|---|---|
boolean |
download(java.io.File file) |
Downloads this attachment to given File
|
Icon |
getAsIcon() |
|
java.lang.String |
getFileName() |
The file name of the Attachment when it was first uploaded.
|
int |
getHeight() |
The height of the Attachment if this Attachment is an image.
|
long |
getIdLong() |
The Snowflake id of this entity.
|
java.io.InputStream |
getInputStream() |
Creates a copy of the
InputStream that is created using an OkHttpClient . |
JDA |
getJDA() |
The corresponding JDA instance for this Attachment
|
java.lang.String |
getProxyUrl() |
The url of the Attachment, proxied by Discord.
|
int |
getSize() |
The size of the attachment in bytes.
|
java.lang.String |
getUrl() |
The url of the Attachment, most likely on the Discord servers.
|
int |
getWidth() |
The width of the Attachment if this Attachment is an image.
|
boolean |
isImage() |
Whether or not this attachment is an Image.
|
void |
withInputStream(IOConsumer<java.io.InputStream> then) |
Allows to access the InputStream that is available from the HTTP
Response
to be used without having to copy it. |
getCreationTime, getId
public Attachment(long id, java.lang.String url, java.lang.String proxyUrl, java.lang.String fileName, int size, int height, int width, net.dv8tion.jda.core.entities.impl.JDAImpl jda)
public JDA getJDA()
public long getIdLong()
ISnowflake
getIdLong
in interface ISnowflake
public java.lang.String getUrl()
public java.lang.String getProxyUrl()
isImage()
)public java.lang.String getFileName()
public Icon getAsIcon() throws java.io.IOException
Icon
instance for
this attachment if isImage()
is true
!
When a global proxy was specified via JDABuilder
this will use the
specified proxy to create an InputStream
otherwise it will use a normal URLConnection
with the User-Agent for the currently logged in account.
Icon
for this image attachmentjava.io.IOException
- If an IOError occurs while reading the imagejava.lang.IllegalStateException
- If this is not an image attachmentpublic boolean download(java.io.File file)
file
- The file, where the attachment will get downloaded topublic java.io.InputStream getInputStream() throws java.io.IOException
InputStream
that is created using an OkHttpClient
.
You can access the input stream directly using withInputStream(IOConsumer)
which will have an open input stream available within the consumer scope. The stream will be closed once that method returns.
java.io.IOException
- If an IO error occurs trying to read from the opened HTTP channelpublic void withInputStream(IOConsumer<java.io.InputStream> then) throws java.io.IOException
Response
to be used without having to copy it.
getInputStream()
this does not return a full copy of the input stream.
Instead this method will provide the InputStream data in the specified consumer in which it is still accessible.
When this method returns the InputStream will be closed accordingly!
then
- Not-null IOConsumer
to accept the InputStreamjava.lang.IllegalArgumentException
- If the provided IOConsumer is null
java.io.IOException
- If an IOException occurs within the IOConsumer or while opening an HTTP channelpublic int getSize()
getSize()
returns 1024, then the attachment is 1024 bytes, or 1KiB, in size.public int getHeight()
public int getWidth()
public boolean isImage()