@Test
public void testFileWrite()
{
String copyFile = "file:"+this.getClass().getName()+"_"+this.getName()+".flv";
handler = new FileProtocolHandler();
int retval = 0;
// First, open the write handler.
retval = handler.open(copyFile, IURLProtocolHandler.URL_WRONLY_MODE);
assertTrue(retval >= 0);
// Now, create and open a read handler.
// note that without a protocol string, should default to file:
IURLProtocolHandler reader = new FileProtocolHandler(sampleFile);
retval = reader.open(null, IURLProtocolHandler.URL_RDONLY_MODE);
long bytesWritten = 0;
long totalBytes = reader.seek(0, IURLProtocolHandler.SEEK_SIZE);
byte[] buffer = new byte[1024];
while ((retval = reader.read(buffer, buffer.length)) > 0)
{
// Write the output.
retval = handler.write(buffer, retval);
assertTrue(retval >= 0);
bytesWritten += retval;
}
assertTrue(bytesWritten == totalBytes);
// close each file
retval = reader.close();
assertTrue(retval >= 0);
retval = handler.close();
assertTrue(retval >= 0);