當前位置: 首頁>>代碼示例>>Java>>正文


Java File類代碼示例

本文整理匯總了Java中com.google.api.services.drive.model.File的典型用法代碼示例。如果您正苦於以下問題:Java File類的具體用法?Java File怎麽用?Java File使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


File類屬於com.google.api.services.drive.model包,在下文中一共展示了File類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uploadFile

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public void uploadFile(String path, byte[] data, boolean writeTransactional)
		throws Exception {
	logDebug("upload file...");		
	try
	{
		ByteArrayContent content = new ByteArrayContent(null, data);
		GDrivePath gdrivePath = new GDrivePath(path);
		Drive driveService = getDriveService(gdrivePath.getAccount());
		
		File driveFile = getFileForPath(gdrivePath, driveService);
		getDriveService(gdrivePath.getAccount()).files()
				.update(driveFile.getId(), driveFile, content).execute();
		logDebug("upload file ok.");
	}
	catch (Exception e)
	{
		throw convertException(e);
	}

}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:22,代碼來源:GoogleDriveFileStorage.java

示例2: mkdir

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException {
    try {
        // Identified by the special folder MIME type application/vnd.google-apps.folder
        final Drive.Files.Create insert = session.getClient().files().create(new File()
                .setName(folder.getName())
                .setMimeType("application/vnd.google-apps.folder")
                .setParents(Collections.singletonList(new DriveFileidProvider(session).getFileid(folder.getParent(), new DisabledListProgressListener()))));
        final File execute = insert
            .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
        return new Path(folder.getParent(), folder.getName(), folder.getType(), new PathAttributes(folder.attributes()));
    }
    catch(IOException e) {
        throw new DriveExceptionMappingService().map("Cannot create folder {0}", e, folder);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:17,代碼來源:DriveDirectoryFeature.java

示例3: fetchGameStatesSync

import com.google.api.services.drive.model.File; //導入依賴的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;
}
 
開發者ID:MrStahlfelge,項目名稱:gdx-gamesvcs,代碼行數:25,代碼來源:GpgsClient.java

示例4: loadGameStateSync

import com.google.api.services.drive.model.File; //導入依賴的package包/類
/**
 * Blocking version of {@link #loadGameState(String, ILoadGameStateResponseListener)}
 *
 * @param fileId
 * @return game state data
 * @throws IOException
 */
public byte[] loadGameStateSync(String fileId) throws IOException {

    InputStream stream = null;
    byte[] data = null;
    try {
        File remoteFile = findFileByNameSync(fileId);
        if (remoteFile != null) {

            stream = GApiGateway.drive.files().get(remoteFile.getId()).executeMediaAsInputStream();

            data = StreamUtils.copyStreamToByteArray(stream);
        }
    } finally {
        StreamUtils.closeQuietly(stream);
    }
    return data;
}
 
開發者ID:MrStahlfelge,項目名稱:gdx-gamesvcs,代碼行數:25,代碼來源:GpgsClient.java

示例5: openFileForRead

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public InputStream openFileForRead(String path) throws Exception {

	logDebug("openFileForRead...");
	GDrivePath gdrivePath = new GDrivePath(path);
	Drive driveService = getDriveService(gdrivePath.getAccount());

	try
	{
		File file = getFileForPath(gdrivePath, driveService);
		InputStream res =  getFileContent(file, driveService);
		logDebug("openFileForRead ok.");
		return res;
	}
	catch (Exception e)
	{
		throw convertException(e);
	}
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:20,代碼來源:GoogleDriveFileStorage.java

示例6: createFolder

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public String createFolder(String parentPath, String newDirName) throws Exception {
	File body = new File();
	body.setTitle(newDirName);
	body.setMimeType(FOLDER_MIME_TYPE);
	
	GDrivePath parentGdrivePath = new GDrivePath(parentPath);
	
	body.setParents(
			Arrays.asList(new ParentReference().setId(parentGdrivePath.getGDriveId())));
	try
	{
		File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();
		
		logDebug("created folder "+newDirName+" in "+parentPath+". id: "+file.getId());

		return new GDrivePath(parentPath, file).getFullPath();
	}
	catch (Exception e)
	{
		throw convertException(e);
	}

}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:25,代碼來源:GoogleDriveFileStorage.java

示例7: createFilePath

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public String createFilePath(String parentPath, String newFileName) throws Exception {
	File body = new File();
	body.setTitle(newFileName);
	GDrivePath parentGdrivePath = new GDrivePath(parentPath);
	
	body.setParents(
			Arrays.asList(new ParentReference().setId(parentGdrivePath.getGDriveId())));
	try
	{
		File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();

		return new GDrivePath(parentPath, file).getFullPath();
	}
	catch (Exception e)
	{
		throw convertException(e);
	}
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:20,代碼來源:GoogleDriveFileStorage.java

示例8: convertToFileEntry

import com.google.api.services.drive.model.File; //導入依賴的package包/類
private FileEntry convertToFileEntry(File file, String path) {
	FileEntry e = new FileEntry();
	e.canRead = e.canWrite = true; 
	e.isDirectory = FOLDER_MIME_TYPE.equals(file.getMimeType());
	e.lastModifiedTime = file.getModifiedDate().getValue();
	e.path = path; 
	try
	{
		e.sizeInBytes = file.getFileSize();			
	}
	catch (NullPointerException ex)
	{
		e.sizeInBytes = 0;
	}
	e.displayName = file.getTitle();
	return e;
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:18,代碼來源:GoogleDriveFileStorage.java

示例9: touch

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Override
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
    try {
        final Drive.Files.Create insert = session.getClient().files().create(new File()
                .setName(file.getName())
                .setMimeType(status.getMime())
                .setParents(Collections.singletonList(new DriveFileidProvider(session).getFileid(file.getParent(), new DisabledListProgressListener()))));
        final File execute = insert.
            setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
        return new Path(file.getParent(), file.getName(), file.getType(),
                new PathAttributes(file.attributes()).withVersionId(execute.getId()));
    }
    catch(IOException e) {
        throw new DriveExceptionMappingService().map("Cannot create file {0}", e, file);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:17,代碼來源:DriveTouchFeature.java

示例10: testSameFoldername

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Test
public void testSameFoldername() throws Exception {
    final String f1 = new AlphanumericRandomStringService().random();
    final String f2 = new AlphanumericRandomStringService().random();
    final Path parent = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, f1, EnumSet.of(Path.Type.directory));
    final Path folder = new Path(parent, f2, EnumSet.of(Path.Type.directory));
    new DriveDirectoryFeature(session).mkdir(parent, null, new TransferStatus());
    new DriveDirectoryFeature(session).mkdir(folder, null, new TransferStatus());
    assertTrue(new DefaultFindFeature(session).find(folder));
    assertEquals(1, new DriveDefaultListService(session).list(parent, new DisabledListProgressListener()).size());
    final String fileid = new DriveFileidProvider(session).getFileid(folder, new DisabledListProgressListener());
    final File body = new File();
    body.set("trashed", true);
    session.getClient().files().update(fileid, body).execute();
    new DriveDirectoryFeature(session).mkdir(folder, null, new TransferStatus());
    assertEquals(2, new DriveDefaultListService(session).list(parent, new DisabledListProgressListener()).size());
    new DriveDeleteFeature(session).delete(Arrays.asList(parent), new DisabledLoginCallback(), new Delete.DisabledCallback());
    assertFalse(new DefaultFindFeature(session).find(parent));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:20,代碼來源:DriveDefaultListServiceTest.java

示例11: testPatch

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Test
public void testPatch() throws Exception {
    File file = uploadTestFile();

    // lets update the filename
    file.setTitle(UPLOAD_FILE.getName() + "PATCHED");
    
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", file.getId());
    // parameter type is String
    headers.put("CamelGoogleDrive.fields", "title");       
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", file);

    File result = requestBodyAndHeaders("direct://PATCH", null, headers);

    assertNotNull("patch result", result);
    assertEquals(UPLOAD_FILE.getName() + "PATCHED", result.getTitle());
    LOG.debug("patch: " + result);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:DriveFilesIntegrationTest.java

示例12: isInMyTracks

import com.google.api.services.drive.model.File; //導入依賴的package包/類
/**
 * Returns true if a drive file is a KML or KMZ file in the My Tracks folder.
 * 
 * @param driveFile the drive file
 * @param folderId the My Tracks folder id
 */
public static boolean isInMyTracks(File driveFile, String folderId) {
  if (driveFile == null) {
    return false;
  }
  String mimeType = driveFile.getMimeType();
  if (!SyncUtils.KML_MIME_TYPE.equals(mimeType) && !SyncUtils.KMZ_MIME_TYPE.equals(mimeType)) {
    return false;
  }
  if (driveFile.getSharedWithMeDate() != null) {
    return false;
  }
  for (ParentReference parentReference : driveFile.getParents()) {
    String id = parentReference.getId();
    if (id != null && id.equals(folderId)) {
      return true;
    }
  }
  return false;
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:26,代碼來源:SyncUtils.java

示例13: testCreateOrUpdateFile_succeedsForUpdatingFile

import com.google.api.services.drive.model.File; //導入依賴的package包/類
@Test
public void testCreateOrUpdateFile_succeedsForUpdatingFile() throws Exception {
  when(files.update(
      eq("id"),
      eq(new File().setTitle("title")),
      argThat(hasByteArrayContent(DATA))))
          .thenReturn(update);
  ChildList childList = new ChildList()
      .setItems(ImmutableList.of(new ChildReference().setId("id")))
      .setNextPageToken(null);
  when(childrenList.execute()).thenReturn(childList);
  assertThat(driveConnection.createOrUpdateFile(
          "title",
          MediaType.WEBM_VIDEO,
          "driveFolderId",
          DATA))
      .isEqualTo("id");
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:19,代碼來源:DriveConnectionTest.java

示例14: searchSpreadsheets

import com.google.api.services.drive.model.File; //導入依賴的package包/類
/**
 * Searches Google Spreadsheets.
 * 
 * @param context the context
 * @param accountName the account name
 * @return the list of spreadsheets matching the title. Null if unable to
 *         search.
 */
public static List<File> searchSpreadsheets(Context context, String accountName) {
  try {
    GoogleAccountCredential googleAccountCredential = SendToGoogleUtils
        .getGoogleAccountCredential(context, accountName, SendToGoogleUtils.DRIVE_SCOPE);
    if (googleAccountCredential == null) {
      return null;
    }

    Drive drive = SyncUtils.getDriveService(googleAccountCredential);
    com.google.api.services.drive.Drive.Files.List list = drive.files().list().setQ(String.format(
        Locale.US, SendSpreadsheetsAsyncTask.GET_SPREADSHEET_QUERY, SPREADSHEETS_NAME));
    return list.execute().getItems();
  } catch (Exception e) {
    Log.e(TAG, "Unable to search spreadsheets.", e);
  }
  return null;
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:26,代碼來源:GoogleUtils.java

示例15: checkFilesNumber

import com.google.api.services.drive.model.File; //導入依賴的package包/類
/**
 * Checks the files number on Google Drive
 * 
 * @param drive a Google Drive object
 * @throws IOException
 */
public static void checkFilesNumber(Drive drive) throws IOException {
  EndToEndTestUtils.instrumentation.waitForIdleSync();
  long startTime = System.currentTimeMillis();
  int trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
  List<File> files = getDriveFiles(EndToEndTestUtils.trackListActivity.getApplicationContext(),
      drive);
  while (System.currentTimeMillis() - startTime < MAX_TIME_TO_WAIT_SYNC) {
    try {
      if (files.size() == trackNumber) {
        return;
      }
      trackNumber = EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount();
      files = getDriveFiles(EndToEndTestUtils.trackListActivity.getApplicationContext(), drive);
      EndToEndTestUtils.sleep(EndToEndTestUtils.SHORT_WAIT_TIME);
      EndToEndTestUtils.findMenuItem(
          EndToEndTestUtils.trackListActivity.getString(R.string.menu_sync_now), true);
    } catch (GoogleJsonResponseException e) {
      Log.e(TAG, e.getMessage(), e);
    }
  }
  Assert.assertEquals(files.size(), trackNumber);
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:29,代碼來源:SyncTestUtils.java


注:本文中的com.google.api.services.drive.model.File類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。