Package google.registry.storage.drive
Class DriveConnection
java.lang.Object
google.registry.storage.drive.DriveConnection
Class encapsulating parameters and state for accessing the Drive API.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateFile
(String name, com.google.common.net.MediaType mimeType, String parentFolderId, byte[] bytes) Creates a file with the given parent.createFolder
(String name, String parentFolderId) Creates a folder with the given parent.createOrUpdateFile
(String name, com.google.common.net.MediaType mimeType, String parentFolderId, byte[] bytes) Creates a file with the given parent or updates the existing one if a file already exists with that same name and parent.Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id.Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id and matching the given Drive query.updateFile
(String fileId, String name, com.google.common.net.MediaType mimeType, byte[] bytes) Updates the file with the given id in place, setting the name, content, and mime type to the newly specified values.
-
Constructor Details
-
DriveConnection
@Inject public DriveConnection()
-
-
Method Details
-
createFolder
Creates a folder with the given parent.- Returns:
- the folder id.
- Throws:
IOException
-
createFile
public String createFile(String name, com.google.common.net.MediaType mimeType, String parentFolderId, byte[] bytes) throws IOException Creates a file with the given parent.If a file with the same path already exists, a duplicate is created. If overwriting the existing file is the desired behavior, use
createOrUpdateFile(String, MediaType, String, byte[])
instead.- Returns:
- the file id.
- Throws:
IOException
-
createOrUpdateFile
public String createOrUpdateFile(String name, com.google.common.net.MediaType mimeType, String parentFolderId, byte[] bytes) throws IOException Creates a file with the given parent or updates the existing one if a file already exists with that same name and parent.- Returns:
- the file id.
- Throws:
IllegalStateException
- if multiple files with that name exist in the given folder.IOException
- if communication with Google Drive fails for any reason.
-
updateFile
public String updateFile(String fileId, String name, com.google.common.net.MediaType mimeType, byte[] bytes) throws IOException Updates the file with the given id in place, setting the name, content, and mime type to the newly specified values.- Returns:
- the file id.
- Throws:
IOException
-
listFiles
Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id.- Throws:
IOException
-
listFiles
Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id and matching the given Drive query.- Throws:
IOException
- See Also:
-