Class DriveConnection


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

      Constructors 
      Constructor Description
      DriveConnection()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String createFile​(java.lang.String title, com.google.common.net.MediaType mimeType, java.lang.String parentFolderId, byte[] bytes)
      Creates a file with the given parent.
      java.lang.String createFolder​(java.lang.String title, java.lang.String parentFolderId)
      Creates a folder with the given parent.
      java.lang.String createOrUpdateFile​(java.lang.String title, com.google.common.net.MediaType mimeType, java.lang.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.
      java.util.List<java.lang.String> listFiles​(java.lang.String parentFolderId)
      Returns a list of Drive file ids for all files in Google Drive in the folder with the specified id.
      java.util.List<java.lang.String> listFiles​(java.lang.String parentFolderId, java.lang.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.
      java.lang.String updateFile​(java.lang.String fileId, java.lang.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 Detail

      • DriveConnection

        @Inject
        public DriveConnection()
    • Method Detail

      • createFolder

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

        public java.lang.String createFile​(java.lang.String title,
                                           com.google.common.net.MediaType mimeType,
                                           java.lang.String parentFolderId,
                                           byte[] bytes)
                                    throws java.io.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:
        java.io.IOException
      • createOrUpdateFile

        public java.lang.String createOrUpdateFile​(java.lang.String title,
                                                   com.google.common.net.MediaType mimeType,
                                                   java.lang.String parentFolderId,
                                                   byte[] bytes)
                                            throws java.io.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:
        java.lang.IllegalStateException - if multiple files with that name exist in the given folder.
        java.io.IOException - if communication with Google Drive fails for any reason.
      • updateFile

        public java.lang.String updateFile​(java.lang.String fileId,
                                           java.lang.String title,
                                           com.google.common.net.MediaType mimeType,
                                           byte[] bytes)
                                    throws java.io.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:
        java.io.IOException
      • listFiles

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

        public java.util.List<java.lang.String> listFiles​(java.lang.String parentFolderId,
                                                          java.lang.String query)
                                                   throws java.io.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:
        java.io.IOException
        See Also:
        The query format