@SuppressWarnings("Finally") @Override public void close() throws ContentDataSourceException { uri = null; try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { throw new ContentDataSourceException(e); } finally { inputStream = null; try { if (assetFileDescriptor != null) { assetFileDescriptor.close(); } } catch (IOException e) { throw new ContentDataSourceException(e); } finally { assetFileDescriptor = null; if (opened) { opened = false; transferEnded(); } } } }
public ByteBuffer map (FileChannel.MapMode mode) { if (type == FileType.Internal) { FileInputStream input = null; try { AssetFileDescriptor fd = getAssetFileDescriptor(); long startOffset = fd.getStartOffset(); long declaredLength = fd.getDeclaredLength(); input = new FileInputStream(fd.getFileDescriptor()); ByteBuffer map = input.getChannel().map(mode, startOffset, declaredLength); map.order(ByteOrder.nativeOrder()); return map; } catch (Exception ex) { throw new GdxRuntimeException("Error memory mapping file: " + this + " (" + type + ")", ex); } finally { StreamUtils.closeQuietly(input); } } return super.map(mode); }
throw new FileNotFoundException("Could not open file descriptor for: " + uri); inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor()); long assetStartOffset = assetFileDescriptor.getStartOffset(); long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset; if (skipped != dataSpec.position) { bytesRemaining = dataSpec.length; } else { long assetFileDescriptorLength = assetFileDescriptor.getLength(); if (assetFileDescriptorLength == AssetFileDescriptor.UNKNOWN_LENGTH) { FileChannel channel = inputStream.getChannel(); long channelSize = channel.size(); bytesRemaining = channelSize == 0 ? C.LENGTH_UNSET : channelSize - channel.position();
@Override public void initialize(MediaMetadataRetriever retriever, AssetFileDescriptor data) { retriever.setDataSource(data.getFileDescriptor(), data.getStartOffset(), data.getLength()); } }
AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid); if (afd == null) return; mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); afd.close();
GifInfoHandle(AssetFileDescriptor afd) throws IOException { try { gifInfoPtr = openFileDescriptor(afd.getFileDescriptor(), afd.getStartOffset(), false); } finally { try { afd.close(); } catch (IOException ignored) { //no-op } } }
phones.moveToFirst(); for(int i =0;i<phones.getCount();i++) String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey); FileInputStream fis = fd.createInputStream(); byte[] buf = new byte[(int) fd.getDeclaredLength()]; fis.read(buf); String VCard = new String(buf); String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile; FileOutputStream mFileOutputStream = new FileOutputStream(path, true); mFileOutputStream.write(VCard.toString().getBytes()); phones.moveToNext(); Log.d("Vcard", VCard);
public void saveCustomIcon(String appComponent, Uri fileUri) { File customIconFile = MyCache.getCustomIconFile(this, appComponent); try { if (null != customIconFile) { FileDescriptor fd = getContentResolver().openAssetFileDescriptor(fileUri, "r").getFileDescriptor(); FileInputStream fis = new FileInputStream(fd); FileOutputStream fos = new FileOutputStream(customIconFile); FileChannel src = fis.getChannel(); FileChannel dst = fos.getChannel(); dst.transferFrom(src, 0, src.size()); fis.close(); fos.close(); dst.close(); src.close(); } } catch (Exception e) {} }
openAssetFileDescriptor(thumbUri, "r"); FileDescriptor fdd = afd.getFileDescriptor(); inputStream = new FileInputStream(fdd); File file = File.createTempFile("PhoneContactProvider", "tmp"); file.deleteOnExit(); outputStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int len; while ((len = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); outputStream.close(); return "file://" + file.getAbsolutePath(); } catch (Exception e) { if (afd != null) { try { afd.close(); } catch (IOException e) {}
public void copyRaw(AssetFileDescriptor fd, File destinationFile) throws IOException { FileChannel sourceChannel = new FileInputStream(fd.getFileDescriptor()).getChannel(); FileChannel destinationChannel = new FileOutputStream(destinationFile).getChannel(); sourceChannel.transferTo(fd.getStartOffset(), fd.getLength(), destinationChannel); }
final String packageName = res.activityInfo.packageName; final Intent intent = new Intent(captureIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(packageName); cameraIntents.add(intent); final Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_PICK); pE.printStackTrace(); bmp = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor()); FileOutputStream out = new FileOutputStream(new File(mOutputFileUri.getPath())); bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace();
try { afd = context.getAssets().openFd(file); long len = afd.getLength(); fis = afd.createInputStream(); try { fos = new FileOutputStream(tmpFile); byte[] buffer = new byte[1024]; int bufferLen; while ((bufferLen = fis.read(buffer)) != -1) { fos.write(buffer, 0, bufferLen); fos.close(); } catch (IOException e) {} fis.close(); } catch (IOException e) {} afd.close(); } catch (IOException e) {}
AssetFileDescriptor fd = this.getContentResolver().openAssetFileDescriptor(uri, "r"); FileInputStream fis = fd.createInputStream(); byte[] buf = new byte[(int) fd.getDeclaredLength()]; fis.read(buf); String vcardstring= new String(buf); FileOutputStream mFileOutputStream = new FileOutputStream(file, true); mFileOutputStream.write(vcardstring.toString().getBytes()); mFileOutputStream.close(); //don't forget to close sharingIntent.setType("vnd.android.cursor.dir/email"); sharingIntent.setType("application/x-vcard"); sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(storage_path)); startActivity(Intent.createChooser(sharingIntent, "Send email"));
try { fd = context.getContentResolver().openAssetFileDescriptor(uri, "r"); FileInputStream fis = fd.createInputStream(); byte[] buf = new byte[(int) fd.getDeclaredLength()]; fis.read(buf); String VCard = new String(buf); String path = Environment.getExternalStorageDirectory() mFileOutputStream = new FileOutputStream(path, true); mFileOutputStream.write(VCard.toString().getBytes()); if (mFileOutputStream != null) { try { mFileOutputStream.close(); } catch (IOException e) { e.printStackTrace();
fis = fd.createInputStream(); byte[] buf = new byte[(int) fd.getDeclaredLength()]; fis.read(buf); String vcardstring= new String(buf); vCard.add(vcardstring); FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, false); mFileOutputStream.write(vcardstring.toString().getBytes()); System.out.println("i m in end of get vcardstring"); fis.close(); } catch (IOException e) {
private final String vfile = "POContactsRestore.vcf"; Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); phones.moveToFirst(); String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey); AssetFileDescriptor fd; try { fd = this.getContentResolver().openAssetFileDescriptor(uri, "r"); FileInputStream fis = fd.createInputStream(); byte[] buf = new byte[(int) fd.getDeclaredLength()]; fis.read(buf); String vCard = new String(buf); String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile; FileOutputStream mFileOutputStream = new FileOutputStream(path, false); mFileOutputStream.write(vCard.toString().getBytes()); Log.d("Vcard", vCard); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
@Test public void open_shouldProvideFileDescriptor() throws Exception { File file = new File( getTargetContext().getFilesDir() + File.separator + "open_shouldProvideFileDescriptor.txt"); FileOutputStream output = new FileOutputStream(file); output.write("hi".getBytes()); ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); AssetFileDescriptor assetFileDescriptor = new AssetFileDescriptor(parcelFileDescriptor, 0, "hi".getBytes().length); assertThat( CharStreams.toString( new InputStreamReader(assetFileDescriptor.createInputStream(), UTF_8))) .isEqualTo("hi"); assertThat(assetFileDescriptor.getLength()).isEqualTo(2); assetFileDescriptor.close(); } }
inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor()); inputStream.skip(assetFileDescriptor.getStartOffset()); long skipped = inputStream.skip(dataSpec.position); if (skipped < dataSpec.position) { bytesRemaining = dataSpec.length; } else { long assetFileDescriptorLength = assetFileDescriptor.getLength();
try { FileDescriptor fd = null; if (isInInternalMemory(audioFilename)) { int audioResourceId = mContext.getResources().getIdentifier(audioFilename, "raw", "com.ampirik.audio"); AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(audioResourceId); fd = afd.getFileDescriptor(); } else if (isInSdCard(audioFilename)) { File baseDir = Environment.getExternalStorageDirectory(); String audioPath = baseDir.getAbsolutePath() + audioFilename + ".mp3"; FileInputStream fis = new FileInputStream(audioPath); fd = fis.getFD(); } if (fd != null) { MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(fd); mediaPlayer.prepare(); mediaPlayer.start(); } } catch (Exception e) { e.printStackTrace(); }
final long length = assetManager.get().openFd(fileName).getLength(); final File folder = masterFileSystem.get().getExternalFileSystem().getFile(basePath); folder.mkdirs(); @Cleanup final OutputStream os = new FileOutputStream(targetFile); IoUtils.copy(is, os); log.debug(">>>> copied in {} msec", System.currentTimeMillis() - time);