Class DriveConnection

java.lang.Object
google.registry.storage.drive.DriveConnection

public class DriveConnection extends Object
Class encapsulating parameters and state for accessing the Drive API.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createFile(String title, com.google.common.net.MediaType mimeType, String parentFolderId, byte[] bytes)
    Creates a file with the given parent.
    createFolder(String title, String parentFolderId)
    Creates a folder with the given parent.
    createOrUpdateFile(String title, 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 title and parent.
    listFiles(String parentFolderId)
    Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id.
    listFiles(String parentFolderId, String query)
    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 title, com.google.common.net.MediaType mimeType, byte[] bytes)
    Updates the file with the given id in place, setting the title, content, and mime type to the newly specified values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DriveConnection

      @Inject public DriveConnection()
  • Method Details

    • createFolder

      public String createFolder(String title, String parentFolderId) throws IOException
      Creates a folder with the given parent.
      Returns:
      the folder id.
      Throws:
      IOException
    • createFile

      public String createFile(String title, 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 title, 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 title 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 title, com.google.common.net.MediaType mimeType, byte[] bytes) throws IOException
      Updates the file with the given id in place, setting the title, content, and mime type to the newly specified values.
      Returns:
      the file id.
      Throws:
      IOException
    • listFiles

      public List<String> listFiles(String parentFolderId) throws IOException
      Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id.
      Throws:
      IOException
    • listFiles

      public List<String> listFiles(String parentFolderId, String query) throws IOException
      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: