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

项目:zimdroid    文件:ZimContentProvider.java   
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    ParcelFileDescriptor[] pipe;
    try {
        pipe = ParcelFileDescriptor.createPipe();

        String url = getFilePath(uri);
        Log.d(TAG, "Retrieving " + url);
        ByteArrayOutputStream stream = getDataForUrl(url);

        new TransferThread(stream, new AutoCloseOutputStream(pipe[1])).start();

    } catch (IOException e) {
        e.printStackTrace();
        throw new FileNotFoundException("Could not open pipe for: " + uri.toString());
    }
    return (pipe[0]);
}
项目:samba-documents-provider    文件:ReadFileTask.java   
@Override
public Void doInBackground(Void... args) {
  try (final AutoCloseOutputStream os = new AutoCloseOutputStream(mPfd);
      final SmbFile file = mClient.openFile(mUri, "r")) {
    int size;
    byte[] buf = new byte[mBuffer.capacity()];
    while ((size = file.read(mBuffer, Integer.MAX_VALUE)) > 0) {
      mBuffer.get(buf, 0, size);
      os.write(buf, 0, size);
      mBuffer.clear();
    }
  } catch (IOException e) {
    Log.e(TAG, "Failed to read file.", e);

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

  return null;
}
项目:SimpleKiwixWikivoyage    文件:ZimContentProvider.java   
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
        throws FileNotFoundException {
    ParcelFileDescriptor[] pipe = null;

    try {
        pipe = ParcelFileDescriptor.createPipe();
        new TransferThread(jniKiwix, uri, new AutoCloseOutputStream(
                pipe[1])).start();
    } catch (IOException e) {
        Log.e(getClass().getSimpleName(), "Exception opening pipe", e);
        throw new FileNotFoundException("Could not open pipe for: "
                + uri.toString());
    }

    return (pipe[0]);
}
项目:cwac-provider    文件:AbstractPipeStrategy.java   
/**
 * {@inheritDoc}
 */
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
  throws FileNotFoundException {
  if ("r".equals(mode)) {
    ParcelFileDescriptor[] pipe=null;

    try {
      pipe=ParcelFileDescriptor.createPipe();

      new TransferOutThread(getInputStream(uri),
                            new AutoCloseOutputStream(pipe[1])).start();
    }
    catch (IOException e) {
      Log.e(getClass().getSimpleName(), "Exception opening pipe", e);

      throw new FileNotFoundException("Could not open pipe for: "
          + uri.toString());
    }

    return(pipe[0]);
  }

  throw new IllegalArgumentException("Cannot support writing!");
}
项目:facebook-content-provider    文件:PipeContentProvider.java   
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) {
    ParcelFileDescriptor[] pipe = null;

    try {
        pipe = ParcelFileDescriptor.createPipe();

        new TransferThread(getInputStream(uri), new AutoCloseOutputStream(pipe[1])).start();
    }
    catch (IOException e) {
        Log.e("PipeContentProvider", "Exception opening pipe", e);
    }

    return pipe[0];
}
项目:FMTech    文件:jsz.java   
public final void a(ParcelFileDescriptor paramParcelFileDescriptor, Object paramObject)
{
  String str1 = String.valueOf(iaw.b(Long.valueOf(this.a)));
  String str2;
  if (str1.length() != 0) {
    str2 = "PicasaStore.download ".concat(str1);
  }
  for (;;)
  {
    int i = jsm.a(str2);
    InputStream localInputStream = this.b;
    ParcelFileDescriptor.AutoCloseOutputStream localAutoCloseOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(paramParcelFileDescriptor);
    try
    {
      byte[] arrayOfByte = new byte[2048];
      int j = localInputStream.read(arrayOfByte);
      for (;;)
      {
        if (j > 0)
        {
          localAutoCloseOutputStream.write(arrayOfByte, 0, j);
          int k = localInputStream.read(arrayOfByte);
          j = k;
          continue;
          str2 = new String("PicasaStore.download ");
          break;
        }
      }
      return;
    }
    catch (IOException localIOException)
    {
      String str3 = String.valueOf(localIOException);
      new StringBuilder(29 + String.valueOf(str3).length()).append("pipe closed early by caller? ").append(str3);
      return;
    }
    catch (Throwable localThrowable) {}finally
    {
      iaw.a(localAutoCloseOutputStream);
      iaw.a(localInputStream);
      jsm.a(i);
    }
  }
}