本文整理匯總了Java中com.google.api.services.drive.model.FileList類的典型用法代碼示例。如果您正苦於以下問題:Java FileList類的具體用法?Java FileList怎麽用?Java FileList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileList類屬於com.google.api.services.drive.model包,在下文中一共展示了FileList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fetchGameStatesSync
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
/**
* Blocking version of {@link #fetchGameStatesSync()}
*
* @return game states
* @throws IOException
*/
public Array<String> fetchGameStatesSync() throws IOException {
if (!driveApiEnabled)
throw new UnsupportedOperationException();
Array<String> games = new Array<String>();
FileList l = GApiGateway.drive.files().list()
.setSpaces("appDataFolder")
.setFields("files(name)")
.execute();
for (File f : l.getFiles()) {
games.add(f.getName());
}
return games;
}
示例2: getBackupFileId
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
public static String getBackupFileId(Drive service, String folderId) throws IOException {
if (folderId == null) {
return null;
}
FileList jsonFile = service.files().list()
.setQ("\'" + folderId + "\' in parents and name = \'" + BACKUP_DB_FILE_NAME + "\'")
.setPageSize(1)
.setFields("files(id)")
.execute();
if (jsonFile.getFiles() == null) {
return null;
} else if (jsonFile.getFiles().size() != 1) {
Log.e(LOG_TAG, "There are more files " + BACKUP_DB_FILE_NAME + " in your FuelUp folder on Google Drive.");
// TODO handle this with message
return null;
}
return jsonFile.getFiles().get(0).getId();
}
示例3: getBackupFolderId
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
public static String getBackupFolderId(Drive service) throws IOException {
FileList fuelUpFolder = service.files().list()
.setQ("\'root\' in parents and name = \'"+ BACKUP_DB_FOLDER +"\'")
.setPageSize(1)
.setFields("files(id)")
.execute();
if (fuelUpFolder.getFiles() == null) {
return null;
} else if (fuelUpFolder.getFiles().size() != 1) {
Log.e(LOG_TAG, "There are more folders " + BACKUP_DB_FOLDER + " on your Google Drive Account.");
// TODO handle this with message
return null;
}
return fuelUpFolder.getFiles().get(0).getId();
}
示例4: getOrCreateDriveFolder
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
public static String getOrCreateDriveFolder(Drive drive, String targetFolder) throws IOException {
String folderId = null;
FileList folders = drive.files().list().setQ("mimeType='application/vnd.google-apps.folder'").execute();
for (com.google.api.services.drive.model.File f : folders.getItems()) {
if (f.getTitle().equals(targetFolder)) {
folderId = f.getId();
}
}
//if not found create it
if (folderId == null) {
com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
body.setTitle(targetFolder);
body.setMimeType("application/vnd.google-apps.folder");
com.google.api.services.drive.model.File file = drive.files().insert(body).execute();
folderId = file.getId();
}
return folderId;
}
示例5: getFiles
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
/**
* Gets all the files from a request.
*
* @param request the request
* @param excludeSharedWithMe true to exclude shared with me files
* @return a map of file id to file
*/
private Map<String, File> getFiles(Files.List request, boolean excludeSharedWithMe)
throws IOException {
Map<String, File> idToFileMap = new HashMap<String, File>();
do {
FileList files = request.execute();
for (File file : files.getItems()) {
if (excludeSharedWithMe && file.getSharedWithMeDate() != null) {
continue;
}
idToFileMap.put(file.getId(), file);
}
request.setPageToken(files.getNextPageToken());
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
return idToFileMap;
}
示例6: getBookmarkFiles
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Override
public List<File> getBookmarkFiles() throws IOException {
List<File> files = Lists.newArrayList();
String pageToken = null;
do {
StringBuilder query = new StringBuilder("mimeType='"+BookmarkFileConstants.MESFAVORIS_MIME_TYPE+"' and trashed=false");
if (folderId.isPresent()) {
query.append(String.format(" and '%s' in parents", folderId.get()));
}
FileList result = drive.files().list()
.setQ(query.toString())
.setSpaces("drive")
.setPageToken(pageToken)
.execute();
files.addAll(result.getItems());
pageToken = result.getNextPageToken();
} while (pageToken != null);
return files;
}
示例7: listChildren
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
public List<File> listChildren(String parentId) {
List<File> resultList = new LinkedList<File>();
Drive drive = driveFactory.getDrive(this.credential);
try {
Drive.Files.List request = drive.files().list().setFields("nextPageToken, files");
request.setQ("trashed = false and '" + parentId + "' in parents");
request.setPageSize(1000);
LOGGER.log(Level.FINE, "Listing children of folder " + parentId + ".");
do {
FileList fileList = executeWithRetry(options, () -> request.execute());
List<File> items = fileList.getFiles();
resultList.addAll(items);
request.setPageToken(fileList.getNextPageToken());
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
if (LOGGER.isLoggable(Level.FINE)) {
for (File file : resultList) {
LOGGER.log(Level.FINE, "Child of " + parentId + ": " + file.getId() + ";" + file.getName() + ";" + file.getMimeType());
}
}
removeDuplicates(resultList);
return resultList;
} catch (IOException e) {
throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to execute list request: " + e.getMessage(), e);
}
}
示例8: getRootFolderId
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
public String getRootFolderId(boolean create) throws Exception {
if (!TextUtils.isEmpty(rootId))
return rootId;
Log.d(TAG, "Looking for Uoccin folder...");
FileList files = service.files().list().setQ("mimeType = '" + DriveFolder.MIME_TYPE +
"' and title = '" + FOLDER + "' and trashed = false").execute();
if (files != null && !files.isEmpty() && files.getItems().size() > 0) {
Log.d(TAG, "Uoccin folder found");
rootId = files.getItems().get(0).getId();
} else if (create) {
Log.i(TAG, "Creating Uoccin folder...");
File body = new File();
body.setTitle(FOLDER);
body.setMimeType(DriveFolder.MIME_TYPE);
rootId = service.files().insert(body).execute().getId();
} else
Log.w(TAG, "Uoccin folder NOT found");
return rootId;
}
示例9: copyFolder
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
/**
* @param sourceFolderId source folder ID
* @param destinationFolderId folder ID where to copy the sourceFolderId's content
* @param newName folder name to assign
* @return created folder ID
* @throws IOException when operation fails
*/
public String copyFolder(String sourceFolderId, String destinationFolderId, String newName) throws IOException {
LOG.debug("[copyFolder] sourceFolderId: {}; destinationFolderId: {}; newName: {}", sourceFolderId, destinationFolderId,
newName);
// create a new folder
String newFolderId = createFolder(destinationFolderId, newName);
// Make a recursive copy of all files/folders inside the source folder
String query = format(Q_IN_PARENTS, sourceFolderId) + Q_AND + Q_NOT_TRASHED;
FileList originals = drive.files().list().setQ(query).execute();
LOG.debug("[copyFolder] Searching for copy {}", query);
for (File file : originals.getFiles()) {
if (file.getMimeType().equals(MIME_TYPE_FOLDER)) {
copyFolder(file.getId(), newFolderId, file.getName());
} else {
copyFile(file.getId(), newFolderId, file.getName(), false);
}
}
return newFolderId;
}
示例10: testRunAtDriverTooManyFiles
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Test
public void testRunAtDriverTooManyFiles() throws Exception {
FileList hasfilelist = new FileList();
List<File> hfiles = new ArrayList<>();
File hfile = new File();
hfile.setId(FILE_PUT_NAME);
hfiles.add(hfile);
hfiles.add(new File());
hasfilelist.setFiles(hfiles);
when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist);
properties.overwrite.setValue(true);
testRuntime.initialize(container, properties);
try {
testRuntime.runAtDriver(container);
fail("Should not be here");
} catch (Exception e) {
}
}
示例11: testRunAtDriverOverwrite
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Test
public void testRunAtDriverOverwrite() throws Exception {
FileList hasfilelist = new FileList();
List<File> hfiles = new ArrayList<>();
File hfile = new File();
hfile.setId(FILE_PUT_NAME);
hfiles.add(hfile);
hasfilelist.setFiles(hfiles);
when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist);
properties.overwrite.setValue(true);
testRuntime.initialize(container, properties);
testRuntime.runAtDriver(container);
assertNull(container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_CONTENT)));
assertEquals(PUT_FILE_ID,
container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_FILE_ID)));
assertEquals(PUT_FILE_PARENT_ID,
container.getComponentData(TEST_CONTAINER, getStudioName(GoogleDrivePutDefinition.RETURN_PARENT_FOLDER_ID)));
}
示例12: testRunAtDriverOverwriteError
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Test
public void testRunAtDriverOverwriteError() throws Exception {
FileList hasfilelist = new FileList();
List<File> hfiles = new ArrayList<>();
File hfile = new File();
hfile.setId(FILE_PUT_NAME);
hfiles.add(hfile);
hasfilelist.setFiles(hfiles);
when(drive.files().list().setQ(anyString()).execute()).thenReturn(hasfilelist);
properties.overwrite.setValue(false);
testRuntime.initialize(container, properties);
try {
testRuntime.runAtDriver(container);
fail("Should not be here");
} catch (Exception e) {
}
}
示例13: setUp
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
container = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return TEST_CONTAINER;
}
};
//
DATA_STORE_DIR = new File(getClass().getClassLoader().getResource("./").toURI().getPath());
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
//
drive = mock(Drive.class, RETURNS_DEEP_STUBS);
sourceOrSink = spy(GoogleDriveSourceOrSink.class);
source = spy(GoogleDriveSource.class);
sink = spy(GoogleDriveSink.class);
doReturn(drive).when(sourceOrSink).getDriveService();
doReturn(drive).when(source).getDriveService();
doReturn(drive).when(sink).getDriveService();
//
emptyFileList = new FileList();
emptyFileList.setFiles(new ArrayList<com.google.api.services.drive.model.File>());
}
示例14: createFolderFileList
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
protected FileList createFolderFileList(String folderId, boolean createDuplicate) {
FileList fileList = new FileList();
java.util.List<com.google.api.services.drive.model.File> files = new ArrayList<>();
com.google.api.services.drive.model.File file = new com.google.api.services.drive.model.File();
file.setId(folderId);
files.add(file);
//
if (createDuplicate) {
com.google.api.services.drive.model.File fileDup = new com.google.api.services.drive.model.File();
fileDup.setId(folderId);
files.add(fileDup);
}
fileList.setFiles(files);
return fileList;
}
示例15: testManyResourcesMatching
import com.google.api.services.drive.model.FileList; //導入依賴的package包/類
@Test(expected = ComponentException.class)
public void testManyResourcesMatching() throws Exception {
FileList flA = new FileList();
List<File> fs = new ArrayList<>();
File fA = new File();
fA.setId("A");
fs.add(fA);
File fAp = new File();
fAp.setId("A");
fs.add(fAp);
flA.setFiles(fs);
when(drive.files().list().setQ(eq(qA)).execute()).thenReturn(flA);
properties.parentFolder.setValue("/A");
testRuntime.initialize(container, properties);
testRuntime.runAtDriver(container);
fail("Should not be here");
}