Java Code Examples for android.content.res.AssetFileDescriptor#createOutputStream()
The following examples show how to use
android.content.res.AssetFileDescriptor#createOutputStream() .
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: CordovaResourceApi.java From reader with MIT License | 6 votes |
/** * 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); }
Example 2
Source File: CordovaResourceApi.java From lona with GNU General Public License v3.0 | 6 votes |
/** * 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); }
Example 3
Source File: CordovaResourceApi.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 6 votes |
/** * 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); }
Example 4
Source File: CordovaResourceApi.java From chappiecast with Mozilla Public License 2.0 | 6 votes |
/** * 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); }
Example 5
Source File: CordovaResourceApi.java From react-native-cordova with MIT License | 6 votes |
/** * 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); }
Example 6
Source File: CordovaResourceApi.java From countly-sdk-cordova with MIT License | 6 votes |
/** * 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); }
Example 7
Source File: CordovaResourceApi.java From cordova-plugin-intent with MIT License | 6 votes |
/** * 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); }
Example 8
Source File: CordovaResourceApi.java From a2cardboard with Apache License 2.0 | 6 votes |
/** * 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); }
Example 9
Source File: CordovaResourceApi.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
/** * 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); }
Example 10
Source File: CordovaResourceApi.java From phonegapbootcampsite with MIT License | 6 votes |
/** * 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); }
Example 11
Source File: CordovaResourceApi.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
/** * 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); }
Example 12
Source File: CordovaResourceApi.java From app-icon with MIT License | 6 votes |
/** * 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); }
Example 13
Source File: CordovaResourceApi.java From keemob with MIT License | 6 votes |
/** * 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); }
Example 14
Source File: CordovaResourceApi.java From keemob with MIT License | 6 votes |
/** * 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); }
Example 15
Source File: CordovaResourceApi.java From ultimate-cordova-webview-app with MIT License | 6 votes |
/** * 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); }
Example 16
Source File: CordovaResourceApi.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
/** * 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); }
Example 17
Source File: CordovaResourceApi.java From xmall with MIT License | 6 votes |
/** * 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); }
Example 18
Source File: AddContactActivity.java From BaldPhone with Apache License 2.0 | 5 votes |
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(); }
Example 19
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 3 votes |
/** * 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"); } }
Example 20
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 3 votes |
/** * 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"); } }