Search in sources :

Example 51 with FileDescriptor

use of java.io.FileDescriptor in project platform_frameworks_base by android.

the class ParcelFileDescriptor method createCommSocketPair.

private static FileDescriptor[] createCommSocketPair() throws IOException {
    try {
        // Use SOCK_SEQPACKET so that we have a guarantee that the status
        // is written and read atomically as one unit and is not split
        // across multiple IO operations.
        final FileDescriptor comm1 = new FileDescriptor();
        final FileDescriptor comm2 = new FileDescriptor();
        Os.socketpair(AF_UNIX, SOCK_SEQPACKET, 0, comm1, comm2);
        IoUtils.setBlocking(comm1, false);
        IoUtils.setBlocking(comm2, false);
        return new FileDescriptor[] { comm1, comm2 };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor)

Example 52 with FileDescriptor

use of java.io.FileDescriptor in project platform_frameworks_base by android.

the class ParcelFileDescriptor method fromFd.

/**
     * Create a new ParcelFileDescriptor from a raw native fd.  The new
     * ParcelFileDescriptor holds a dup of the original fd passed in here,
     * so you must still close that fd as well as the new ParcelFileDescriptor.
     *
     * @param fd The native fd that the ParcelFileDescriptor should dup.
     *
     * @return Returns a new ParcelFileDescriptor holding a FileDescriptor
     * for a dup of the given fd.
     */
public static ParcelFileDescriptor fromFd(int fd) throws IOException {
    final FileDescriptor original = new FileDescriptor();
    original.setInt$(fd);
    try {
        final FileDescriptor dup = Os.dup(original);
        return new ParcelFileDescriptor(dup);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor)

Example 53 with FileDescriptor

use of java.io.FileDescriptor in project platform_frameworks_base by android.

the class ParcelFileDescriptor method createSocketPair.

/**
     * @hide
     */
public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException {
    try {
        final FileDescriptor fd0 = new FileDescriptor();
        final FileDescriptor fd1 = new FileDescriptor();
        Os.socketpair(AF_UNIX, type, 0, fd0, fd1);
        return new ParcelFileDescriptor[] { new ParcelFileDescriptor(fd0), new ParcelFileDescriptor(fd1) };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor)

Example 54 with FileDescriptor

use of java.io.FileDescriptor in project platform_frameworks_base by android.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Example 55 with FileDescriptor

use of java.io.FileDescriptor in project glide by bumptech.

the class VideoBitmapDecoderTest method testReturnsRetrievedFrameForResource.

@Test
public void testReturnsRetrievedFrameForResource() throws IOException {
    Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    when(retriever.getFrameAtTime()).thenReturn(expected);
    FileDescriptor toSet = FileDescriptor.in;
    when(resource.getFileDescriptor()).thenReturn(toSet);
    Resource<Bitmap> result = decoder.decode(resource, 100, 100, options);
    verify(retriever).setDataSource(eq(toSet));
    assertEquals(expected, result.get());
}
Also used : Bitmap(android.graphics.Bitmap) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) Test(org.junit.Test)

Aggregations

FileDescriptor (java.io.FileDescriptor)361 IOException (java.io.IOException)161 ParcelFileDescriptor (android.os.ParcelFileDescriptor)95 ErrnoException (android.system.ErrnoException)95 FileInputStream (java.io.FileInputStream)82 File (java.io.File)51 AssetFileDescriptor (android.content.res.AssetFileDescriptor)37 FileOutputStream (java.io.FileOutputStream)35 Bitmap (android.graphics.Bitmap)30 LocalSocket (android.net.LocalSocket)26 FileNotFoundException (java.io.FileNotFoundException)26 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 InputStream (java.io.InputStream)15 Socket (java.net.Socket)14 ErrnoException (libcore.io.ErrnoException)14 Test (org.junit.Test)14 ServerSocket (java.net.ServerSocket)13 SSLHandshakeCallbacks (org.conscrypt.NativeCrypto.SSLHandshakeCallbacks)13 RemoteException (android.os.RemoteException)12 BitmapFactory (android.graphics.BitmapFactory)11