private InputStreamReader getInputStreamReader() throws IOException { return new FileReader(mCsvTempFileUri.getEncodedPath()); }
public void destroy() { File originalFile = new File(mCsvTempFileUri.getEncodedPath()); if (originalFile.exists()) { originalFile.delete(); } mItemsCache.clear(); mChangedItems.clear(); }
@Override public File getFileForUri(Uri uri) { String path = uri.getEncodedPath(); final int splitIndex = path.indexOf('/', 1); final String tag = Uri.decode(path.substring(1, splitIndex)); path = Uri.decode(path.substring(splitIndex + 1)); final File root = mRoots.get(tag); if (root == null) { throw new IllegalArgumentException("Unable to find configured root for " + uri); } File file = new File(root, path); try { file = file.getCanonicalFile(); } catch (IOException e) { throw new IllegalArgumentException("Failed to resolve canonical path for " + file); } if (!file.getPath().startsWith(root.getPath())) { throw new SecurityException("Resolved path jumped beyond configured root"); } return file; } }
void init() { File tempFile = FileUtils.createTempFile(mContext); try { File originalFile = new File(mCsvFileUri.getEncodedPath()); FileUtils.copy(originalFile, tempFile); } catch (IOException e) { Log.e(TAG, "init method error ", e); } finally { mCsvTempFileUri = Uri.fromFile(tempFile); } mRowsCount = calculateLinesCount(); mColumnsCount = getRow(0).size(); }
private String applyChanges() { final String originalFilePath = mCsvFileDataSource.getCsvFileUri().getEncodedPath(); File originalFile = new File(originalFilePath); final String originalFileName = originalFile.getName();
private String saveChange() { final String originalFilePath = mCsvFileDataSource.getCsvFileUri().getEncodedPath(); File originalFile = new File(originalFilePath); final String originalFileName = originalFile.getName();
} else if (filename != null) { String tempOutDir = Uri.fromFile(new File(context.getCacheDir(), filename)).getEncodedPath(); errorMessage = ImportUtils.copyFileToCache(context, intent, tempOutDir) ? null : "copyFileToCache() failed";
public static void putDownloadLocation(@NonNull UniFile location) { Uri uri = location.getUri(); putString(KEY_DOWNLOAD_SAVE_SCHEME, uri.getScheme()); putString(KEY_DOWNLOAD_SAVE_AUTHORITY, uri.getEncodedAuthority()); putString(KEY_DOWNLOAD_SAVE_PATH, uri.getEncodedPath()); putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery()); putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment()); if (getMediaScan()) { CommonOperations.removeNoMediaFile(location); } else { CommonOperations.ensureNoMediaFile(location); } }
@Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { File root = new File(Environment.getExternalStorageDirectory(), "/Android/data/com.example.myapp/cache"); root.mkdirs(); File path = new File(root, uri.getEncodedPath()); // So, if the uri was content://com.example.myapp/some/data.xml, // we'll end up accessing /Android/data/com.example.myapp/cache/some/data.xml int imode = 0; if (mode.contains("w")) { imode |= ParcelFileDescriptor.MODE_WRITE_ONLY; if (!path.exists()) { try { path.createNewFile(); } catch (IOException e) { // TODO decide what to do about it, whom to notify... e.printStackTrace(); } } } if (mode.contains("r")) imode |= ParcelFileDescriptor.MODE_READ_ONLY; if (mode.contains("+")) imode |= ParcelFileDescriptor.MODE_APPEND; return ParcelFileDescriptor.open(path, imode); }
@Override public File getFileForUri(Uri uri) { String path = uri.getEncodedPath(); final int splitIndex = path.indexOf('/', 1); final String tag = Uri.decode(path.substring(1, splitIndex)); path = Uri.decode(path.substring(splitIndex + 1)); final File root = mRoots.get(tag); if (root == null) { throw new IllegalArgumentException("Unable to find configured root for " + uri); } File file = new File(root, path); try { file = file.getCanonicalFile(); } catch (IOException e) { throw new IllegalArgumentException("Failed to resolve canonical path for " + file); } if (!file.getPath().startsWith(root.getPath())) { throw new SecurityException("Resolved path jumped beyond configured root"); } return file; } }
private Uri.Builder buildRelativeURI(Uri.Builder resultBuilder, Uri base, Uri uri) { if (uri.getAuthority() != null) { return resultBuilder.scheme(base.getScheme()); } else { resultBuilder .encodedAuthority(base.getEncodedAuthority()) .scheme(base.getScheme()) .path(null); if (uri.getPath().startsWith("/")) { //relative to root resultBuilder.appendEncodedPath(uri.getEncodedPath().substring(1)); } else { List<String> segments = base.getPathSegments(); //ignore last segment if not end with / int ignoreLast = 1; if (base.getPath().endsWith("/")) { ignoreLast = 0; } for (int i = 0, len = segments.size() - ignoreLast; i < len; i++) { resultBuilder.appendEncodedPath(segments.get(i)); } resultBuilder.appendEncodedPath(uri.getEncodedPath()); } return resultBuilder; } }
Uri mediaUri = android.provider.CallLog.Calls.CONTENT_URI; Log.d("PhoneService", "The Encoded path of the media Uri is " + mediaUri.getEncodedPath()); CustomContentObserver custObser = new CustomContentObserver(handler); imageContentRsr.registerContentObserver(mediaUri, false, custObser);
private static Uri replaceClickHost(@NonNull Uri uri) { return uri.getHost().equals(TIMELINE_CLICK_HOST) ? Uri.parse(CONTENT_URI_SCHEME_AND_HOST + uri.getEncodedPath()) : uri; }
/** * Get a media thumbnail. * @return a bytearray with the RGBA thumbnail data inside. */ public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) { /* dvd thumbnails can work only with dvdsimple demux */ if (uri.getLastPathSegment().endsWith(".iso")) uri = Uri.parse("dvdsimple://" + uri.getEncodedPath()); final Media media = new Media(libVLC, uri); byte[] bytes = getThumbnail(media, i_width, i_height); media.release(); return bytes; }
/** * Get a media thumbnail. * @return a bytearray with the RGBA thumbnail data inside. */ public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) { /* dvd thumbnails can work only with dvdsimple demux */ if (uri.getLastPathSegment().endsWith(".iso")) uri = Uri.parse("dvdsimple://" + uri.getEncodedPath()); final Media media = new Media(libVLC, uri); byte[] bytes = getThumbnail(media, i_width, i_height); media.release(); return bytes; }
/** * Get a media thumbnail. * @return a bytearray with the RGBA thumbnail data inside. */ public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) { /* dvd thumbnails can work only with dvdsimple demux */ if (uri.getLastPathSegment().endsWith(".iso")) uri = Uri.parse("dvdsimple://" + uri.getEncodedPath()); final Media media = new Media(libVLC, uri); byte[] bytes = getThumbnail(media, i_width, i_height); media.release(); return bytes; }
/** * Get a media thumbnail. * @return a bytearray with the RGBA thumbnail data inside. */ public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) { /* dvd thumbnails can work only with dvdsimple demux */ if (uri.getLastPathSegment().endsWith(".iso")) uri = Uri.parse("dvdsimple://" + uri.getEncodedPath()); final Media media = new Media(libVLC, uri); byte[] bytes = getThumbnail(media, i_width, i_height); media.release(); return bytes; }
/** * Get a media thumbnail. * @return a bytearray with the RGBA thumbnail data inside. */ public static byte[] getThumbnail(LibVLC libVLC, Uri uri, int i_width, int i_height) { /* dvd thumbnails can work only with dvdsimple demux */ if (uri.getLastPathSegment().endsWith(".iso")) uri = Uri.parse("dvdsimple://" + uri.getEncodedPath()); final Media media = new Media(libVLC, uri); byte[] bytes = getThumbnail(media, i_width, i_height); media.release(); return bytes; }
public static Uri ensureScheme(final Uri uri) { if (uri.getScheme() == null) { Uri.Builder builder = new Uri.Builder(); builder.scheme("file").authority("").encodedPath(uri.getEncodedPath()); return builder.build(); } return uri; }
@Test public void getAuthorizationUrl_whenProvidedBadUrl_doesNotCrash() { PaymentIntent paymentIntent = PaymentIntent.fromString( EXAMPLE_PAYMENT_INTENT_SOURCE_WITH_BAD_AUTH_URL); Uri authUrl = paymentIntent.getAuthorizationUrl(); assertEquals(BAD_URL, authUrl.getEncodedPath()); }