Java 类android.os.ParcelFileDescriptor.AutoCloseInputStream 实例源码

项目:samba-documents-provider    文件:WriteFileTask.java   
@Override
public Void doInBackground(Void... args) {
  try (final AutoCloseInputStream is = new AutoCloseInputStream(mPfd);
      final SmbFile file = mClient.openFile(mUri, "w")){
    int size;
    byte[] buf = new byte[mBuffer.capacity()];
    while ((size = is.read(buf)) > 0) {
      mBuffer.put(buf, 0, size);
      file.write(mBuffer, size);
      mBuffer.clear();
    }
  } catch (IOException e) {
    Log.e(TAG, "Failed to write file.", e);

    try {
      mPfd.closeWithError(e.getMessage());
    } catch (IOException exc) {
      Log.e(TAG, "Can't even close PFD with error.", exc);
    }
  }

  return null;
}
项目:q-mail    文件:ParcelFileDescriptorUtil.java   
public static TransferThread pipeTo(OutputStream outputStream, ParcelFileDescriptor output)
        throws IOException {

    AutoCloseInputStream InputStream = new AutoCloseInputStream(output);
    TransferThread t = new TransferThread(InputStream, outputStream);

    t.start();
    return t;
}
项目:q-mail    文件:ParcelFileDescriptorUtil.java   
public static <T> DataSinkTransferThread<T> asyncPipeToDataSink(
        SMimeDataSink<T> dataSink, ParcelFileDescriptor output) throws IOException {
    InputStream inputStream = new BufferedInputStream(new AutoCloseInputStream(output));
    DataSinkTransferThread<T> dataSinkTransferThread =
            new DataSinkTransferThread<T>(dataSink, inputStream);
    dataSinkTransferThread.start();
    return dataSinkTransferThread;
}
项目:q-mail    文件:ParcelFileDescriptorUtil.java   
public static TransferThread pipeTo(OutputStream outputStream, ParcelFileDescriptor output)
        throws IOException {

    AutoCloseInputStream InputStream = new AutoCloseInputStream(output);
    TransferThread t = new TransferThread(InputStream, outputStream);

    t.start();
    return t;
}
项目:q-mail    文件:ParcelFileDescriptorUtil.java   
public static <T> DataSinkTransferThread<T> asyncPipeToDataSink(
        OpenPgpDataSink<T> dataSink, ParcelFileDescriptor output) throws IOException {
    InputStream inputStream = new BufferedInputStream(new AutoCloseInputStream(output));
    DataSinkTransferThread<T> dataSinkTransferThread =
            new DataSinkTransferThread<T>(dataSink, inputStream);
    dataSinkTransferThread.start();
    return dataSinkTransferThread;
}
项目:K9-MailClient    文件:ParcelFileDescriptorUtil.java   
public static TransferThread pipeTo(OutputStream outputStream, ParcelFileDescriptor output)
        throws IOException {

    AutoCloseInputStream InputStream = new AutoCloseInputStream(output);
    TransferThread t = new TransferThread(InputStream, outputStream);

    t.start();
    return t;
}
项目:K9-MailClient    文件:ParcelFileDescriptorUtil.java   
public static <T> DataSinkTransferThread<T> asyncPipeToDataSink(
        OpenPgpDataSink<T> dataSink, ParcelFileDescriptor output) throws IOException {
    InputStream inputStream = new BufferedInputStream(new AutoCloseInputStream(output));
    DataSinkTransferThread<T> dataSinkTransferThread =
            new DataSinkTransferThread<T>(dataSink, inputStream);
    dataSinkTransferThread.start();
    return dataSinkTransferThread;
}
项目:QuizUpWinner    文件:Request.java   
public void writeFile(String paramString1, ParcelFileDescriptor paramParcelFileDescriptor, String paramString2)
{
  if (paramString2 == null)
    paramString2 = "content/unknown";
  writeContentDisposition(paramString1, paramString1, paramString2);
  int i = 0;
  if ((this.outputStream instanceof ProgressNoopOutputStream))
  {
    ((ProgressNoopOutputStream)this.outputStream).addProgress(paramParcelFileDescriptor.getStatSize());
    i = 0;
  }
  else
  {
    ParcelFileDescriptor.AutoCloseInputStream localAutoCloseInputStream = null;
    BufferedInputStream localBufferedInputStream = null;
    try
    {
      localAutoCloseInputStream = new ParcelFileDescriptor.AutoCloseInputStream(paramParcelFileDescriptor);
      localBufferedInputStream = new BufferedInputStream(localAutoCloseInputStream);
      byte[] arrayOfByte = new byte[8192];
      while (true)
      {
        int j = localBufferedInputStream.read(arrayOfByte);
        if (j == -1)
          break;
        this.outputStream.write(arrayOfByte, 0, j);
        i += j;
      }
      localBufferedInputStream.close();
      localAutoCloseInputStream.close();
    }
    finally
    {
      if (localBufferedInputStream != null)
        localBufferedInputStream.close();
      if (localAutoCloseInputStream != null)
        localAutoCloseInputStream.close();
    }
  }
  writeLine("", new Object[0]);
  writeRecordBoundary();
  if (this.logger != null)
  {
    Logger localLogger = this.logger;
    String str = "    " + paramString1;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(i);
    localLogger.appendKeyValue(str, String.format("<Data: %d>", arrayOfObject));
  }
}
项目:silent-contacts-android    文件:ScContactsProvider.java   
@Override
protected Object doInBackground(Object... params) {
    AutoCloseInputStream is = new AutoCloseInputStream(mDescriptor);
    try {
        Bitmap b = BitmapFactory.decodeStream(is);
        if (b != null) {
            waitForAccess(mWriteAccessLatch);
            PhotoProcessor processor = new PhotoProcessor(b, getMaxDisplayPhotoDim(), getMaxThumbnailDim());

            // Store the compressed photo in the photo store.
            PhotoStore photoStore = mContactsPhotoStore; 
            long photoFileId = photoStore.insert(processor);

            // Depending on whether we already had a data row to attach the photo
            // to, do an update or insert.
            if (mDataId != 0) {
                // Update the data record with the new photo.
                ContentValues updateValues = new ContentValues();

                // Signal that photo processing has already been handled.
                updateValues.put(DataRowHandlerForPhoto.SKIP_PROCESSING_KEY, true);

                if (photoFileId != 0) {
                    updateValues.put(Photo.PHOTO_FILE_ID, photoFileId);
                }
                updateValues.put(Photo.PHOTO, processor.getThumbnailPhotoBytes());
                update(ContentUris.withAppendedId(Data.CONTENT_URI, mDataId),
                        updateValues, null, null);
            }
            else {
                // Insert a new primary data record with the photo.
                ContentValues insertValues = new ContentValues();

                // Signal that photo processing has already been handled.
                insertValues.put(DataRowHandlerForPhoto.SKIP_PROCESSING_KEY, true);

                insertValues.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
                insertValues.put(Data.IS_PRIMARY, 1);
                if (photoFileId != 0) {
                    insertValues.put(Photo.PHOTO_FILE_ID, photoFileId);
                }
                insertValues.put(Photo.PHOTO, processor.getThumbnailPhotoBytes());
                insert(RawContacts.CONTENT_URI.buildUpon()
                        .appendPath(String.valueOf(mRawContactId))
                        .appendPath(RawContacts.Data.CONTENT_DIRECTORY).build(),
                        insertValues);
            }

        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return null;
}