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


Java ParcelFileDescriptor.MODE_WRITE_ONLY屬性代碼示例

本文整理匯總了Java中android.os.ParcelFileDescriptor.MODE_WRITE_ONLY屬性的典型用法代碼示例。如果您正苦於以下問題:Java ParcelFileDescriptor.MODE_WRITE_ONLY屬性的具體用法?Java ParcelFileDescriptor.MODE_WRITE_ONLY怎麽用?Java ParcelFileDescriptor.MODE_WRITE_ONLY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.os.ParcelFileDescriptor的用法示例。


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

示例1: openFile

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
  Log.w(TAG, "openFile(" + uri + ", " + mode + ")");

  switch (uriMatcher.match(uri)) {
  case SINGLE_ROW:
    Log.w(TAG, "Fetching message body for a single row...");
    File tmpFile = getFile(uri);

    final int fileMode;
    switch (mode) {
    case "w": fileMode = ParcelFileDescriptor.MODE_TRUNCATE |
                         ParcelFileDescriptor.MODE_CREATE   |
                         ParcelFileDescriptor.MODE_WRITE_ONLY; break;
    case "r": fileMode = ParcelFileDescriptor.MODE_READ_ONLY;  break;
    default:  throw new IllegalArgumentException("requested file mode unsupported");
    }

    Log.w(TAG, "returning file " + tmpFile.getAbsolutePath());
    return ParcelFileDescriptor.open(tmpFile, fileMode);
  }

  throw new FileNotFoundException("Request for bad message.");
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:24,代碼來源:MmsBodyProvider.java

示例2: parseMode

public static int parseMode(String mode) {
    final int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Bad mode '" + mode + "'");
    }
    return modeBits;
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:24,代碼來源:ParcelFileDescriptorUtil.java

示例3: modeToMode

/**
 * Copied from ContentResolver.java
 */
private static int modeToMode(String mode) {
    int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new IllegalArgumentException("Invalid mode: " + mode);
    }
    return modeBits;
}
 
開發者ID:yasirkula,項目名稱:UnityNativeShare,代碼行數:27,代碼來源:UnitySSContentProvider.java

示例4: modeToMode

static public int modeToMode(Uri uri, String mode) throws FileNotFoundException {
    int modeBits;
    if ("r".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("w".equals(mode) || "wt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else if ("wa".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_WRITE_ONLY
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_APPEND;
    } else if ("rw".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE;
    } else if ("rwt".equals(mode)) {
        modeBits = ParcelFileDescriptor.MODE_READ_WRITE
                | ParcelFileDescriptor.MODE_CREATE
                | ParcelFileDescriptor.MODE_TRUNCATE;
    } else {
        throw new FileNotFoundException("Bad mode for " + uri + ": "
                + mode);
    }
    return modeBits;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:25,代碼來源:ScraperProvider.java

示例5: openFile

/**
 * Remotely opens a file
 */
@Override
public ParcelFileDescriptor openFile(final Uri uri, String mode) throws FileNotFoundException {
    if (Constants.LOGVV) {
        logVerboseOpenFileInfo(uri, mode);
    }

    final Cursor cursor = queryCleared(uri, new String[]{
                    Downloads.Impl._DATA, Downloads.Impl.COLUMN_STATUS,
                    Downloads.Impl.COLUMN_DESTINATION, Downloads.Impl.COLUMN_MEDIA_SCANNED}, null,
            null, null);
    final String path;
    final boolean shouldScan;
    try {
        int count = (cursor != null) ? cursor.getCount() : 0;
        if (count != 1) {
            // If there is not exactly one result, throw an appropriate exception.
            if (count == 0) {
                throw new FileNotFoundException("No entry for " + uri);
            }
            throw new FileNotFoundException("Multiple items at " + uri);
        }

        if (cursor.moveToFirst()) {
            final int status = cursor.getInt(1);
            final int destination = cursor.getInt(2);
            final int mediaScanned = cursor.getInt(3);

            path = cursor.getString(0);
            shouldScan = Downloads.Impl.isStatusSuccess(status) && (
                    destination == Downloads.Impl.DESTINATION_EXTERNAL
                            || destination == Downloads.Impl.DESTINATION_FILE_URI
                            || destination == Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD)
                    && mediaScanned != 2;
        } else {
            throw new FileNotFoundException("Failed moveToFirst");
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }

    if (path == null) {
        throw new FileNotFoundException("No filename found.");
    }

    final File file = new File(path);

    int fileMode = 0;
    if (mode.contains("w")) {
        fileMode |= ParcelFileDescriptor.MODE_WRITE_ONLY;
    }
    if (mode.contains("r")) {
        fileMode |= ParcelFileDescriptor.MODE_READ_ONLY;
    }
    if (mode.contains("+")) {
        fileMode |= ParcelFileDescriptor.MODE_APPEND;
    }
    return ParcelFileDescriptor.open(file, fileMode);
}
 
開發者ID:redleaf2002,項目名稱:downloadmanager,代碼行數:61,代碼來源:DownloadProvider.java

示例6: openFile

/**
 * Remotely opens a file
 */
@Override
public ParcelFileDescriptor openFile(final Uri uri, String mode) throws FileNotFoundException {
    if (Constants.LOGVV) {
        logVerboseOpenFileInfo(uri, mode);
    }

    final Cursor cursor = queryCleared(uri, new String[] {
                    Downloads.Impl._DATA, Downloads.Impl.COLUMN_STATUS,
                    Downloads.Impl.COLUMN_DESTINATION, Downloads.Impl.COLUMN_MEDIA_SCANNED }, null,
            null, null);
    final String path;
    final boolean shouldScan;
    try {
        int count = (cursor != null) ? cursor.getCount() : 0;
        if (count != 1) {
            // If there is not exactly one result, throw an appropriate exception.
            if (count == 0) {
                throw new FileNotFoundException("No entry for " + uri);
            }
            throw new FileNotFoundException("Multiple items at " + uri);
        }

        if (cursor.moveToFirst()) {
            final int status = cursor.getInt(1);
            final int destination = cursor.getInt(2);
            final int mediaScanned = cursor.getInt(3);

            path = cursor.getString(0);
            shouldScan = Downloads.Impl.isStatusSuccess(status) && (
                    destination == Downloads.Impl.DESTINATION_EXTERNAL
                            || destination == Downloads.Impl.DESTINATION_FILE_URI
                            || destination == Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD)
                    && mediaScanned != 2;
        } else {
            throw new FileNotFoundException("Failed moveToFirst");
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }

    if (path == null) {
        throw new FileNotFoundException("No filename found.");
    }

    final File file = new File(path);

    int fileMode = 0;
    if (mode.contains("w")) {
        fileMode |= ParcelFileDescriptor.MODE_WRITE_ONLY;
    }
    if (mode.contains("r")) {
        fileMode |= ParcelFileDescriptor.MODE_READ_ONLY;
    }
    if (mode.contains("+")) {
        fileMode |= ParcelFileDescriptor.MODE_APPEND;
    }
    return ParcelFileDescriptor.open(file, fileMode);
}
 
開發者ID:limpoxe,項目名稱:Android-DownloadManager,代碼行數:61,代碼來源:DownloadProvider.java


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