use of java.io.FileDescriptor in project fresco by facebook.
the class WebpBitmapFactoryTest method testJpegFileDescriptorDecode.
@Test
public void testJpegFileDescriptorDecode() throws Throwable {
FileDescriptor fd = getImageFileDescriptor("redsquare.jpg");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(fd, null, null);
testBitmapDefault(bitmap, 20, 20);
}
use of java.io.FileDescriptor in project XobotOS by xamarin.
the class BackupHelperDispatcher method performBackup.
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
// First, do the helpers that we've already done, since they're already in the state
// file.
int err;
Header header = new Header();
TreeMap<String, BackupHelper> helpers = (TreeMap<String, BackupHelper>) mHelpers.clone();
FileDescriptor oldStateFD = null;
FileDescriptor newStateFD = newState.getFileDescriptor();
if (oldState != null) {
oldStateFD = oldState.getFileDescriptor();
while ((err = readHeader_native(header, oldStateFD)) >= 0) {
if (err == 0) {
BackupHelper helper = helpers.get(header.keyPrefix);
Log.d(TAG, "handling existing helper '" + header.keyPrefix + "' " + helper);
if (helper != null) {
doOneBackup(oldState, data, newState, header, helper);
helpers.remove(header.keyPrefix);
} else {
skipChunk_native(oldStateFD, header.chunkSize);
}
}
}
}
// Then go through and do the rest that we haven't done.
for (Map.Entry<String, BackupHelper> entry : helpers.entrySet()) {
header.keyPrefix = entry.getKey();
Log.d(TAG, "handling new helper '" + header.keyPrefix + "'");
BackupHelper helper = entry.getValue();
doOneBackup(oldState, data, newState, header, helper);
}
}
use of java.io.FileDescriptor in project XobotOS by xamarin.
the class FileBackupHelperBase method performBackup_checked.
/**
* Check the parameters so the native code doesn't have to throw all the exceptions
* since it's easier to do that from Java.
*/
static void performBackup_checked(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState, String[] files, String[] keys) {
if (files.length == 0) {
return;
}
// files must be all absolute paths
for (String f : files) {
if (f.charAt(0) != '/') {
throw new RuntimeException("files must have all absolute paths: " + f);
}
}
// the length of files and keys must be the same
if (files.length != keys.length) {
throw new RuntimeException("files.length=" + files.length + " keys.length=" + keys.length);
}
// oldStateFd can be null
FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null;
FileDescriptor newStateFd = newState.getFileDescriptor();
if (newStateFd == null) {
throw new NullPointerException();
}
int err = performBackup_native(oldStateFd, data.mBackupWriter, newStateFd, files, keys);
if (err != 0) {
// TODO: more here
throw new RuntimeException("Backup failed 0x" + Integer.toHexString(err));
}
}
use of java.io.FileDescriptor in project XobotOS by xamarin.
the class IoBridge method closeSocket.
public static void closeSocket(FileDescriptor fd) throws IOException {
if (!fd.valid()) {
// Socket.close doesn't throw if you try to close an already-closed socket.
return;
}
int intFd = fd.getInt$();
fd.setInt$(-1);
FileDescriptor oldFd = new FileDescriptor();
oldFd.setInt$(intFd);
AsynchronousCloseMonitor.signalBlockedThreads(oldFd);
try {
Libcore.os.close(oldFd);
} catch (ErrnoException errnoException) {
// TODO: are there any cases in which we should throw?
}
}
use of java.io.FileDescriptor in project XobotOS by xamarin.
the class IoBridge method open.
/**
* java.io only throws FileNotFoundException when opening files, regardless of what actually
* went wrong. Additionally, java.io is more restrictive than POSIX when it comes to opening
* directories: POSIX says read-only is okay, but java.io doesn't even allow that. We also
* have an Android-specific hack to alter the default permissions.
*/
public static FileDescriptor open(String path, int flags) throws FileNotFoundException {
FileDescriptor fd = null;
try {
// On Android, we don't want default permissions to allow global access.
int mode = ((flags & O_ACCMODE) == O_RDONLY) ? 0 : 0600;
fd = Libcore.os.open(path, flags, mode);
if (fd.valid()) {
// Java disallows reading directories too.
if (S_ISDIR(Libcore.os.fstat(fd).st_mode)) {
throw new ErrnoException("open", EISDIR);
}
}
return fd;
} catch (ErrnoException errnoException) {
try {
if (fd != null) {
IoUtils.close(fd);
}
} catch (IOException ignored) {
}
FileNotFoundException ex = new FileNotFoundException(path + ": " + errnoException.getMessage());
ex.initCause(errnoException);
throw ex;
}
}
Aggregations