Search in sources :

Example 31 with FileDescriptor

use of java.io.FileDescriptor in project robolectric by robolectric.

the class ShadowParcelFileDescriptor method open.

@Implementation
public static ParcelFileDescriptor open(File file, int mode) throws FileNotFoundException {
    ParcelFileDescriptor pfd;
    try {
        Constructor<ParcelFileDescriptor> constructor = ParcelFileDescriptor.class.getDeclaredConstructor(FileDescriptor.class);
        pfd = constructor.newInstance(new FileDescriptor());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Shadows.shadowOf(pfd).file = new RandomAccessFile(file, mode == ParcelFileDescriptor.MODE_READ_ONLY ? "r" : "rw");
    return pfd;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ParcelFileDescriptor(android.os.ParcelFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Implementation(org.robolectric.annotation.Implementation)

Example 32 with FileDescriptor

use of java.io.FileDescriptor in project robolectric by robolectric.

the class ShadowBitmapFactoryTest method decodeFileDescriptor_shouldGetWidthAndHeightFromHints.

@Test
public void decodeFileDescriptor_shouldGetWidthAndHeightFromHints() throws Exception {
    File tmpFile = File.createTempFile("BitmapFactoryTest", null);
    try {
        tmpFile.deleteOnExit();
        FileInputStream is = new FileInputStream(tmpFile);
        try {
            FileDescriptor fd = is.getFD();
            ShadowBitmapFactory.provideWidthAndHeightHints(fd, 123, 456);
            Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
            assertEquals("Bitmap for fd:" + fd, shadowOf(bitmap).getDescription());
            assertEquals(123, bitmap.getWidth());
            assertEquals(456, bitmap.getHeight());
        } finally {
            is.close();
        }
    } finally {
        tmpFile.delete();
    }
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) FileInputStream(java.io.FileInputStream) FileDescriptor(java.io.FileDescriptor) Test(org.junit.Test)

Example 33 with FileDescriptor

use of java.io.FileDescriptor in project libstreaming by fyhertz.

the class AudioStream method encodeWithMediaRecorder.

@Override
protected void encodeWithMediaRecorder() throws IOException {
    // We need a local socket to forward data output by the camera to the packetizer
    createSockets();
    Log.v(TAG, "Requested audio with " + mQuality.bitRate / 1000 + "kbps" + " at " + mQuality.samplingRate / 1000 + "kHz");
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setAudioSource(mAudioSource);
    mMediaRecorder.setOutputFormat(mOutputFormat);
    mMediaRecorder.setAudioEncoder(mAudioEncoder);
    mMediaRecorder.setAudioChannels(1);
    mMediaRecorder.setAudioSamplingRate(mQuality.samplingRate);
    mMediaRecorder.setAudioEncodingBitRate(mQuality.bitRate);
    // We write the output of the camera in a local socket instead of a file !			
    // This one little trick makes streaming feasible quiet simply: data from the camera
    // can then be manipulated at the other end of the socket
    FileDescriptor fd = null;
    if (sPipeApi == PIPE_API_PFD) {
        fd = mParcelWrite.getFileDescriptor();
    } else {
        fd = mSender.getFileDescriptor();
    }
    mMediaRecorder.setOutputFile(fd);
    mMediaRecorder.setOutputFile(fd);
    mMediaRecorder.prepare();
    mMediaRecorder.start();
    InputStream is = null;
    if (sPipeApi == PIPE_API_PFD) {
        is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
    } else {
        try {
            // mReceiver.getInputStream contains the data from the camera
            is = mReceiver.getInputStream();
        } catch (IOException e) {
            stop();
            throw new IOException("Something happened with the local sockets :/ Start failed !");
        }
    }
    // the mPacketizer encapsulates this stream in an RTP stream and send it over the network
    mPacketizer.setInputStream(is);
    mPacketizer.start();
    mStreaming = true;
}
Also used : InputStream(java.io.InputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 34 with FileDescriptor

use of java.io.FileDescriptor in project fresco by facebook.

the class GingerbreadPurgeableDecoder method decodeFileDescriptorAsPurgeable.

protected Bitmap decodeFileDescriptorAsPurgeable(CloseableReference<PooledByteBuffer> bytesRef, int inputLength, byte[] suffix, BitmapFactory.Options options) {
    MemoryFile memoryFile = null;
    try {
        memoryFile = copyToMemoryFile(bytesRef, inputLength, suffix);
        FileDescriptor fd = getMemoryFileDescriptor(memoryFile);
        Bitmap bitmap = sWebpBitmapFactory.decodeFileDescriptor(fd, null, options);
        return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        if (memoryFile != null) {
            memoryFile.close();
        }
    }
}
Also used : MemoryFile(android.os.MemoryFile) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException) FileDescriptor(java.io.FileDescriptor)

Example 35 with FileDescriptor

use of java.io.FileDescriptor in project fresco by facebook.

the class WebpBitmapFactoryTest method testWebpFileDescriptorDecode.

@Test
public void testWebpFileDescriptorDecode() throws Throwable {
    FileDescriptor fd = getImageFileDescriptor("redsquare.webp");
    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)

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