Package java.nio.channels

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


          ioe.toString();
        };
      }
    };
    t.start();
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
    Assert.assertFalse(clientChannel.isOpen());
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

            FileChannel fromCh = in.getChannel();
            FileChannel toCh = out.getChannel();
            long size = fromCh.size();
            long toCopy = size;
            while (toCopy > 0) {
                toCopy -= toCh.transferFrom(fromCh, size - toCopy, toCopy);
            }
        } finally {
            try {
                in.close();
            } catch (IOException e) {
View Full Code Here

        {
            in = new FileInputStream(src);
            out = new FileOutputStream(target);
            FileChannel inCh = in.getChannel();
            FileChannel outCh = out.getChannel();
            if (outCh.transferFrom(inCh, 0, src.length()) == src.length())
            {
                // adjust timestamp
                target.setLastModified(src.lastModified());
                flag = true;
            }
View Full Code Here

      FileChannel destination = null;

      try {
          source = new FileInputStream(sourceFile).getChannel();
          destination = new FileOutputStream(destFile).getChannel();
          destination.transferFrom(source, 0, source.size());
      }
      finally {
          if(source != null) {
              source.close();
          }
View Full Code Here

        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if(source != null) {
                source.close();
            }
            if(destination != null) {
View Full Code Here

            long pos = 0;
            long count = 0;
            while (pos < size) {
                final long remain = size - pos;
                count = remain > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : remain;
                final long bytesCopied = output.transferFrom(input, pos, count);
                if (bytesCopied == 0) { // IO-385 - can happen if file is truncated after caching the size
                    break; // ensure we don't loop forever
                }
                pos += bytesCopied;
            }
View Full Code Here

                long length = section.right - section.left;
                long bytesRead = 0;
                while (bytesRead < length)
                {
                    long toRead = Math.min(FileStreamTask.CHUNK_SIZE, length - bytesRead);
                    long lastRead = fc.transferFrom(socketChannel, offset + bytesRead, toRead);
                    // if the other side fails, we will not get an exception, but instead transferFrom will constantly return 0 byte read
                    // and we would thus enter an infinite loop. So intead, if no bytes are tranferred we assume the other side is dead and
                    // raise an exception (that will be catch belove and 'the right thing' will be done).
                    if (lastRead == 0)
                        throw new IOException("Transfer failed for remote file " + remoteFile);
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.