Search in sources :

Example 36 with FileDescriptor

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);
}
Also used : Bitmap(android.graphics.Bitmap) FileDescriptor(java.io.FileDescriptor) Test(org.junit.Test)

Example 37 with FileDescriptor

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);
    }
}
Also used : TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 38 with FileDescriptor

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));
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 39 with FileDescriptor

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?
    }
}
Also used : FileDescriptor(java.io.FileDescriptor)

Example 40 with FileDescriptor

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;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileDescriptor(java.io.FileDescriptor)

Aggregations

FileDescriptor (java.io.FileDescriptor)363 IOException (java.io.IOException)162 ParcelFileDescriptor (android.os.ParcelFileDescriptor)95 ErrnoException (android.system.ErrnoException)95 FileInputStream (java.io.FileInputStream)83 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)16 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