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();
}
}
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();
}
}
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();
}
}
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;
}
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());
}
Aggregations