Java Code Examples for com.google.api.services.drive.model.File#getMimeType()

The following examples show how to use com.google.api.services.drive.model.File#getMimeType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncUtils.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: SyncUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if a drive file is a KML or KMZ file in the Shared with me
 * directory.
 * 
 * @param driveFile the drive file
 */
public static boolean isInSharedWithMe(File driveFile) {
  if (driveFile == null) {
    return false;
  }
  String mimeType = driveFile.getMimeType();
  if (!SyncUtils.KML_MIME_TYPE.equals(mimeType) && !SyncUtils.KMZ_MIME_TYPE.equals(mimeType)) {
    return false;
  }
  return driveFile.getSharedWithMeDate() != null;
}
 
Example 3
Source File: GoogleDriveAdapter.java    From jdrivesync with Apache License 2.0 5 votes vote down vote up
public boolean isGoogleAppsDocument(File file) {
	String mimeType = file.getMimeType();
	if (mimeType != null && mimeType.startsWith("application/vnd.google-apps") && !mimeType.equals("application/vnd.google-apps.folder")) {
		LOGGER.log(Level.FINE, "Not touching file " + file.getId() + " because it is a Google Apps document.");
		return true;
	}
	return false;
}
 
Example 4
Source File: GoogleDriveAdapter.java    From jdrivesync with Apache License 2.0 5 votes vote down vote up
public boolean isGoogleAppsDocumentforExport(File file) {
	String mimeType = file.getMimeType();
	if (mimeType != null && supportedGooglMimeType.containsKey(mimeType)) {
		LOGGER.log(Level.FINE, "exporting file " + file.getId() + " because it is a Google Apps document.");
		return true;
	}
	return false;
}
 
Example 5
Source File: GoogleDriveUtils.java    From components with Apache License 2.0 5 votes vote down vote up
public GoogleDriveGetResult getResource(GoogleDriveGetParameters parameters) throws IOException {
    String fileId = parameters.getResourceId();
    File file = getMetadata(fileId, "id,mimeType,fileExtension");
    String fileMimeType = file.getMimeType();
    String outputFileExt = "." + file.getFileExtension();
    LOG.debug("[getResource] Found fileName `{}` [id: {}, mime: {}, ext: {}]", parameters.getResourceId(), fileId,
            fileMimeType, file.getFileExtension());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    /* Google Apps types */
    if (GoogleDriveMimeTypes.GOOGLE_DRIVE_APPS.contains(fileMimeType)) {
        String exportFormat = parameters.getMimeType().get(fileMimeType).getMimeType();
        outputFileExt = parameters.getMimeType().get(fileMimeType).getExtension();
        drive.files().export(fileId, exportFormat).executeMediaAndDownloadTo(outputStream);
    } else { /* Standard fileName */
        drive.files().get(fileId).executeMediaAndDownloadTo(outputStream);
    }
    byte[] content = outputStream.toByteArray();
    if (parameters.isStoreToLocal()) {
        String localFile = parameters.getOutputFileName();
        if (parameters.isAddExt()) {
            localFile = localFile + ((localFile.endsWith(outputFileExt)) ? "" : outputFileExt);
        }
        LOG.info(messages.getMessage("message.writing.resource", parameters.getResourceId(), localFile));
        try (FileOutputStream fout = new FileOutputStream(localFile)) {
            fout.write(content);
            fout.close();
        }
    }

    return new GoogleDriveGetResult(fileId, content);
}
 
Example 6
Source File: GoogleDriveAdapter.java    From jdrivesync with Apache License 2.0 5 votes vote down vote up
public boolean isGoogleAppsDocument(File file) {
	String mimeType = file.getMimeType();
	if (mimeType != null && mimeType.startsWith("application/vnd.google-apps") && !mimeType.equals("application/vnd.google-apps.folder")) {
		LOGGER.log(Level.FINE, "Not touching file " + file.getId() + " because it is a Google Apps document.");
		return true;
	}
	return false;
}
 
Example 7
Source File: GoogleDriveAdapter.java    From jdrivesync with Apache License 2.0 5 votes vote down vote up
public boolean isGoogleAppsDocumentforExport(File file) {
	String mimeType = file.getMimeType();
	if (mimeType != null && supportedGooglMimeType.containsKey(mimeType)) {
		LOGGER.log(Level.FINE, "exporting file " + file.getId() + " because it is a Google Apps document.");
		return true;
	}
	return false;
}