@Test public void testFileRead() throws FileNotFoundException { // open our file FileInputStream stream = new FileInputStream(mSampleFile); mHandler = new InputOutputStreamHandler(stream, null, true); int retval = 0; retval = mHandler.open(mSampleFile, IURLProtocolHandler.URL_RDONLY_MODE); assertTrue(retval >= 0); long bytesRead = 0; byte[] buffer = new byte[1024]; while ((retval = mHandler.read(buffer, buffer.length)) > 0) { bytesRead += retval; } // and close retval = mHandler.close(); assertTrue(retval >= 0); assertEquals(4546420, bytesRead); }
@Test public void testValidFFMPEGURLFileOpenForReading() throws FileNotFoundException { int flags = IURLProtocolHandler.URL_RDONLY_MODE; FileInputStream stream = new FileInputStream(mSampleFile); String url = mProtocolString + ":" + mSampleFile; mFactory.mapIO(url, new InputOutputStreamHandler(stream, null, true), false); int retval = -1; // Test all the different ways to open a valid file. mHandler = mFactory.getHandler(XugglerIO.DEFAULT_PROTOCOL, url, flags); assertTrue("could not find a mHandler using the mFactory", mHandler != null); // the mFactory should pass the URL to the mHandler retval = mHandler.open(null, flags); assertEquals(0, retval); retval = mHandler.close(); assertEquals(0, retval); retval = mHandler.open(url, flags); assertTrue(retval == 0); retval = mHandler.close(); assertEquals(0, retval); // now, try opening using FFMPEG FfmpegIOHandle handle = new FfmpegIOHandle(); retval = FfmpegIO.url_open(handle, url, flags); assertEquals(0, retval); retval = FfmpegIO.url_close(handle); assertTrue(retval == 0); assertNotNull(mFactory.unmapIO(url)); }
@Test public void testFileWrite() throws FileNotFoundException { String copyFile = this.getClass().getName() + "_" + this.getName() + ".flv"; FileInputStream inStream = new FileInputStream(mSampleFile); FileOutputStream outStream = new FileOutputStream(copyFile); mHandler = new InputOutputStreamHandler(null, outStream, true); int retval = 0; // First, open the write mHandler. retval = mHandler.open(copyFile, IURLProtocolHandler.URL_WRONLY_MODE); assertTrue(retval >= 0); // Now, create and open a read mHandler. // note that without a protocol string, should default to file: IURLProtocolHandler reader = new InputOutputStreamHandler(inStream, null, true); retval = reader.open(null, IURLProtocolHandler.URL_RDONLY_MODE); long bytesWritten = 0; long totalBytes = 0; byte[] buffer = new byte[1024]; while ((retval = reader.read(buffer, buffer.length)) > 0) { totalBytes += retval; // Write the output. retval = mHandler.write(buffer, retval); assertTrue(retval >= 0); bytesWritten += retval; } assertEquals(totalBytes, bytesWritten); assertEquals(4546420, totalBytes); // close each file retval = reader.close(); assertTrue(retval >= 0); retval = mHandler.close(); assertTrue(retval >= 0); }