Package java.nio.channels

Examples of java.nio.channels.FileChannel.transferFrom()


      // Create channel on the destination
      fos = new FileOutputStream(targetFile);
      dstChannel = fos.getChannel();

      // Copy file contents from source to destination
      dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

    }
    catch (IOException e)
    {
      throw new XException(Constants.LOCATION_EXTERN,
View Full Code Here


  public static void copyFile(String source, String destination) throws Exception {
        FileChannel srcChannel = new FileInputStream(source).getChannel();
   
        FileChannel dstChannel = new FileOutputStream(destination).getChannel();
   
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
   
        srcChannel.close();
        dstChannel.close();
  }
 
View Full Code Here

        destinationFile.createNewFile();

      outputStream = new FileOutputStream(destinationFile);
      FileChannel dstChannel = outputStream.getChannel();

      dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

    } catch (IOException e) {
      throw new PersistenceException(e);
    } finally {
      closeCloseable(inputStream);
View Full Code Here

      FileChannel dstChannel = outputStream.getChannel();

      long bytesToTransfer = srcChannel.size();
      long position = 0;
      while (bytesToTransfer > 0) {
        long bytesTransferred = dstChannel.transferFrom(srcChannel, position, bytesToTransfer);
        position += bytesTransferred;
        bytesToTransfer -= bytesTransferred;
      }

    } catch (IOException e) {
View Full Code Here

    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    QAUtil.sleep(200);
   
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
   
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
View Full Code Here

    server.close();
   
    QAUtil.sleep(1000);

    try {
        fc.transferFrom(clientChannel, 0, 17);
        Assert.fail("IOException expected");
    } catch (IOException expected) { }

    file.delete();
    server.close();
View Full Code Here

    serverChannel.write(txt);
    serverChannel.flush();
    serverChannel.close();
    QAUtil.sleep(200);
   
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
   
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
View Full Code Here

    QAUtil.sleep(200);
   
    clientChannel.close();
   
    try {
      fc.transferFrom(clientChannel, 0, 9000000);
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
    file.delete();
    server.close();
View Full Code Here

    QAUtil.sleep(200);
   
    clientChannel.close();
   
    try {
      fc.transferFrom(clientChannel, 0, 9000000);
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
    file.delete();
    server.close();
View Full Code Here

    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    QAUtil.sleep(200);
   
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
   
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.