Class HttpFileUploadManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager
-
public final class HttpFileUploadManager extends Manager
A manager for XEP-0363: HTTP File Upload.- See Also:
- XEP-0363: HTTP File Upload
-
-
Field Summary
Fields Modifier and Type Field Description static String
NAMESPACE
Namespace of XEP-0363 v0.4 or higher.static String
NAMESPACE_0_2
Namespace of XEP-0363 v0.2 or lower.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
discoverUploadService()
Discover upload service.UploadService
getDefaultUploadService()
Get default upload service if it was discovered.static HttpFileUploadManager
getInstanceFor(XMPPConnection connection)
Obtain the HttpFileUploadManager responsible for a connection.boolean
isUploadServiceDiscovered()
Check if upload service was discovered.static UploadService.Version
namespaceToVersion(String namespace)
Slot
requestSlot(String filename, long fileSize)
Request a new upload slot from default upload service (if discovered).Slot
requestSlot(String filename, long fileSize, String contentType)
Request a new upload slot with optional content type from default upload service (if discovered).Slot
requestSlot(String filename, long fileSize, String contentType, DomainBareJid uploadServiceAddress)
Request a new upload slot with optional content type from custom upload service.void
setTlsContext(SSLContext tlsContext)
URL
uploadFile(File file)
Request slot and uploaded file to HTTP file upload service.URL
uploadFile(File file, UploadProgressListener listener)
Request slot and uploaded file to HTTP file upload service with progress callback.URL
uploadFile(InputStream inputStream, String fileName, long fileSize)
Request slot and uploaded stream to HTTP upload service.URL
uploadFile(InputStream inputStream, String fileName, long fileSize, UploadProgressListener listener)
Request slot and uploaded stream to HTTP upload service.-
Methods inherited from class org.jivesoftware.smack.Manager
connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
-
-
-
-
Field Detail
-
NAMESPACE
public static final String NAMESPACE
Namespace of XEP-0363 v0.4 or higher. Constant value "urn:xmpp:http:upload:0".- See Also:
- XEP-0363 v0.4.0, Constant Field Values
-
NAMESPACE_0_2
public static final String NAMESPACE_0_2
Namespace of XEP-0363 v0.2 or lower. Constant value "urn:xmpp:http:upload".- See Also:
- XEP-0363 v0.2.5, Constant Field Values
-
-
Method Detail
-
getInstanceFor
public static HttpFileUploadManager getInstanceFor(XMPPConnection connection)
Obtain the HttpFileUploadManager responsible for a connection.- Parameters:
connection
- the connection object.- Returns:
- a HttpFileUploadManager instance
-
discoverUploadService
public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException
Discover upload service. Called automatically when connection is authenticated. Note that this is a synchronous call -- Smack must wait for the server response.- Returns:
- true if upload service was discovered
- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.NoResponseException
- if there was no response from the remote entity.
-
isUploadServiceDiscovered
public boolean isUploadServiceDiscovered()
Check if upload service was discovered.- Returns:
- true if upload service was discovered
-
getDefaultUploadService
public UploadService getDefaultUploadService()
Get default upload service if it was discovered.- Returns:
- upload service JID or null if not available
-
uploadFile
public URL uploadFile(File file) throws InterruptedException, XMPPException.XMPPErrorException, SmackException, IOException
Request slot and uploaded file to HTTP file upload service. You don't need to request slot and upload file separately, this method will do both. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
file
- file to be uploaded- Returns:
- public URL for sharing uploaded file
- Throws:
InterruptedException
- if the calling thread was interrupted.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException
- if Smack detected an exceptional situation.IOException
- in case of HTTP upload errors
-
uploadFile
public URL uploadFile(File file, UploadProgressListener listener) throws InterruptedException, XMPPException.XMPPErrorException, SmackException, IOException
Request slot and uploaded file to HTTP file upload service with progress callback. You don't need to request slot and upload file separately, this method will do both. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
file
- file to be uploadedlistener
- Upload progress listener or null- Returns:
- public URL for sharing uploaded file
- Throws:
InterruptedException
- if the calling thread was interrupted.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException
- if Smack detected an exceptional situation.IOException
- if an I/O error occurred.
-
uploadFile
public URL uploadFile(InputStream inputStream, String fileName, long fileSize) throws XMPPException.XMPPErrorException, InterruptedException, SmackException, IOException
Request slot and uploaded stream to HTTP upload service. You don't need to request slot and upload input stream separately, this method will do both. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
inputStream
- Input stream used for the upload.fileName
- Name of the file.fileSize
- Size of the file.- Returns:
- public URL for sharing uploaded file
- Throws:
XMPPException.XMPPErrorException
- XMPPErrorException if there was an XMPP error returned.InterruptedException
- If the calling thread was interrupted.SmackException
- If Smack detected an exceptional situation.IOException
- If an I/O error occurred.
-
uploadFile
public URL uploadFile(InputStream inputStream, String fileName, long fileSize, UploadProgressListener listener) throws XMPPException.XMPPErrorException, InterruptedException, SmackException, IOException
Request slot and uploaded stream to HTTP upload service. You don't need to request slot and upload input stream separately, this method will do both. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
inputStream
- Input stream used for the upload.fileName
- Name of the file.fileSize
- file size in bytes.listener
- upload progress listener or null.- Returns:
- public URL for sharing uploaded file
- Throws:
XMPPException.XMPPErrorException
- XMPPErrorException if there was an XMPP error returned.InterruptedException
- If the calling thread was interrupted.SmackException
- If Smack detected an exceptional situation.IOException
- If an I/O error occurred.
-
requestSlot
public Slot requestSlot(String filename, long fileSize) throws InterruptedException, XMPPException.XMPPErrorException, SmackException
Request a new upload slot from default upload service (if discovered). When you get slot you should upload file to PUT URL and share GET URL. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
filename
- name of file to be uploadedfileSize
- file size in bytes.- Returns:
- file upload Slot in case of success
- Throws:
IllegalArgumentException
- if fileSize is less than or equal to zero or greater than the maximum size supported by the service.InterruptedException
- if the calling thread was interrupted.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException
- if smack exception.
-
requestSlot
public Slot requestSlot(String filename, long fileSize, String contentType) throws SmackException, InterruptedException, XMPPException.XMPPErrorException
Request a new upload slot with optional content type from default upload service (if discovered). When you get slot you should upload file to PUT URL and share GET URL. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
filename
- name of file to be uploadedfileSize
- file size in bytes.contentType
- file content-type or null- Returns:
- file upload Slot in case of success
- Throws:
IllegalArgumentException
- if fileSize is less than or equal to zero or greater than the maximum size supported by the service.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException
- if smack exception.
-
requestSlot
public Slot requestSlot(String filename, long fileSize, String contentType, DomainBareJid uploadServiceAddress) throws SmackException, InterruptedException, XMPPException.XMPPErrorException
Request a new upload slot with optional content type from custom upload service. When you get slot you should upload file to PUT URL and share GET URL. Note that this is a synchronous call -- Smack must wait for the server response.- Parameters:
filename
- name of file to be uploadedfileSize
- file size in bytes.contentType
- file content-type or nulluploadServiceAddress
- the address of the upload service to use or null for default one- Returns:
- file upload Slot in case of success
- Throws:
IllegalArgumentException
- if fileSize is less than or equal to zero or greater than the maximum size supported by the service.SmackException
- if Smack detected an exceptional situation.InterruptedException
- if the calling thread was interrupted.XMPPException.XMPPErrorException
- if there was an XMPP error returned.
-
setTlsContext
public void setTlsContext(SSLContext tlsContext)
-
namespaceToVersion
public static UploadService.Version namespaceToVersion(String namespace)
-
-