Package java.nio.channels

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


            try
            {
                FileChannel target = ((FileOutputStream) output).getChannel();
                FileChannel source = ((FileInputStream) input).getChannel();
               
                source.transferTo(0, Integer.MAX_VALUE, target);
               
                source.close();
                target.close();
               
                return;
View Full Code Here


            channel.write(buffer);
            assert buffer.remaining() == 0;

            while (start < endPosition)
            {
                long bytesTransferred = fc.transferTo(start, CHUNK_SIZE, channel);
                if (logger.isDebugEnabled())
                    logger.debug("Bytes transferred " + bytesTransferred);
                start += bytesTransferred;
                StreamOutManager.get(to).update(file, start);
            }
View Full Code Here

                fail();
            } catch (UnsupportedOperationException e) {
                // expected
            }
            try {
                channel.transferTo(0, 0, channel);
                fail();
            } catch (UnsupportedOperationException e) {
                // expected
            }
            channel.close();
View Full Code Here

        FileChannel srcChannel = null, destChannel = null;
        try {
            srcChannel = new FileInputStream(srcPath).getChannel();
            destChannel = new FileOutputStream(destPath).getChannel();

            srcChannel.transferTo(0, srcChannel.size(), destChannel);
        } finally {
            srcChannel.close();
            destChannel.close();
        }
    }
View Full Code Here

    try {
      in = new FileInputStream(from).getChannel();
      out = new FileOutputStream(to).getChannel();
      final long length = in.size();

      final long copied = in.transferTo(0, in.size(), out);
      if (copied != length) {
        throw new IOException("Could not transfer all bytes.");
      }
    } finally {
      Cleanly.close(out);
View Full Code Here

                        condition_.await();
                    }
                }
               
                /* returns the number of bytes transferred from file to the socket */
                long bytesTransferred = fc.transferTo(startPosition, limit, socketChannel_);
                if (logger_.isDebugEnabled())
                    logger_.debug("Bytes transferred " + bytesTransferred);               
                bytesWritten += bytesTransferred;
                startPosition += bytesTransferred;
                /*
 
View Full Code Here

            targetFileChannel = exchange.getConnection().getWorker().getXnio().openFile(tempTarget, FileAccess.READ_WRITE);
            sourceFileChannel = exchange.getConnection().getWorker().getXnio().openFile(file, FileAccess.READ_ONLY);

            StreamSinkConduit conduit = encoding.getEncoding().getResponseWrapper().wrap(new ImmediateConduitFactory<StreamSinkConduit>(new FileConduitTarget(targetFileChannel, exchange)), exchange);
            final ConduitStreamSinkChannel targetChannel = new ConduitStreamSinkChannel(null, conduit);
            long transfered = sourceFileChannel.transferTo(0, resource.getContentLength(), targetChannel);
            targetChannel.shutdownWrites();
            org.xnio.channels.Channels.flushBlocking(targetChannel);
            if (transfered != resource.getContentLength()) {
                UndertowLogger.REQUEST_LOGGER.error("Failed to write pre-cached file");
            }
View Full Code Here

            targetFileChannel = exchange.getConnection().getWorker().getXnio().openFile(tempTarget, FileAccess.READ_WRITE);
            sourceFileChannel = exchange.getConnection().getWorker().getXnio().openFile(file, FileAccess.READ_ONLY);

            StreamSinkConduit conduit = encoding.getEncoding().getResponseWrapper().wrap(new ImmediateConduitFactory<StreamSinkConduit>(new FileConduitTarget(targetFileChannel, exchange)), exchange);
            final ConduitStreamSinkChannel targetChannel = new ConduitStreamSinkChannel(null, conduit);
            long transferred = sourceFileChannel.transferTo(0, resource.getContentLength(), targetChannel);
            targetChannel.shutdownWrites();
            org.xnio.channels.Channels.flushBlocking(targetChannel);
            if (transferred != resource.getContentLength()) {
                UndertowLogger.REQUEST_LOGGER.error("Failed to write pre-cached file");
            }
View Full Code Here

  public void testTransferTo() throws IOException {
    RegularFile file = regularFile(10);
    FileChannel channel = channel(file, READ);

    ByteBufferChannel writeChannel = new ByteBufferChannel(buffer("1234567890"));
    assertEquals(10, channel.transferTo(0, 100, writeChannel));
    assertEquals(0, channel.position());
  }

  @Test
  public void testTransferFrom() throws IOException {
View Full Code Here

    assertNotEquals(accessTime, file.getLastAccessTime());

    accessTime = file.getLastAccessTime();
    Uninterruptibles.sleepUninterruptibly(2, MILLISECONDS);

    channel.transferTo(0, 10, new ByteBufferChannel(10));
    assertNotEquals(accessTime, file.getLastAccessTime());

    // modified
    long modifiedTime = file.getLastModifiedTime();
    Uninterruptibles.sleepUninterruptibly(2, MILLISECONDS);
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.