android.content.res.AssetFileDescriptor#createOutputStream()源码实例Demo

下面列出了android.content.res.AssetFileDescriptor#createOutputStream() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigDataPlatform   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码2 项目: xmall   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码5 项目: keemob   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码6 项目: keemob   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码7 项目: app-icon   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码8 项目: reader   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码9 项目: phonegapbootcampsite   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码11 项目: a2cardboard   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码12 项目: cordova-plugin-intent   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码13 项目: countly-sdk-cordova   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码14 项目: react-native-cordova   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码15 项目: chappiecast   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码17 项目: lona   文件: CordovaResourceApi.java
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
源代码18 项目: BaldPhone   文件: AddContactActivity.java
private static void addFullSizePhoto(int rawContactId, byte[] fullSizedPhotoData, final ContentResolver cr) throws IOException {
    final Uri baseUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawContactId);
    final Uri displayPhotoUri = Uri.withAppendedPath(baseUri, ContactsContract.RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
    final AssetFileDescriptor fileDescriptor = cr.openAssetFileDescriptor(displayPhotoUri, "rw");
    final FileOutputStream photoStream = fileDescriptor.createOutputStream();
    photoStream.write(fullSizedPhotoData);
    photoStream.close();
    fileDescriptor.close();
}
 
源代码19 项目: AndroidComponentPlugin   文件: ContentResolver.java
/**
 * Open a stream on to the content associated with a content URI.  If there
 * is no data associated with the URI, FileNotFoundException is thrown.
 *
 * <h5>Accepts the following URI schemes:</h5>
 * <ul>
 * <li>content ({@link #SCHEME_CONTENT})</li>
 * <li>file ({@link #SCHEME_FILE})</li>
 * </ul>
 *
 * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information
 * on these schemes.
 *
 * @param uri The desired URI.
 * @param mode May be "w", "wa", "rw", or "rwt".
 * @return OutputStream
 * @throws FileNotFoundException if the provided URI could not be opened.
 * @see #openAssetFileDescriptor(Uri, String)
 */
public final @Nullable OutputStream openOutputStream(@NonNull Uri uri, @NonNull String mode)
        throws FileNotFoundException {
    AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode, null);
    try {
        return fd != null ? fd.createOutputStream() : null;
    } catch (IOException e) {
        throw new FileNotFoundException("Unable to create stream");
    }
}
 
源代码20 项目: AndroidComponentPlugin   文件: ContentResolver.java
/**
 * Open a stream on to the content associated with a content URI.  If there
 * is no data associated with the URI, FileNotFoundException is thrown.
 *
 * <h5>Accepts the following URI schemes:</h5>
 * <ul>
 * <li>content ({@link #SCHEME_CONTENT})</li>
 * <li>file ({@link #SCHEME_FILE})</li>
 * </ul>
 *
 * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information
 * on these schemes.
 *
 * @param uri The desired URI.
 * @param mode May be "w", "wa", "rw", or "rwt".
 * @return OutputStream
 * @throws FileNotFoundException if the provided URI could not be opened.
 * @see #openAssetFileDescriptor(Uri, String)
 */
public final @Nullable OutputStream openOutputStream(@NonNull Uri uri, @NonNull String mode)
        throws FileNotFoundException {
    AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode, null);
    try {
        return fd != null ? fd.createOutputStream() : null;
    } catch (IOException e) {
        throw new FileNotFoundException("Unable to create stream");
    }
}