Package java.nio.channels

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


                    socketChannel_.write(buffer);
                    handleIncompleteWrite(buffer);
                }
               
                /* returns the number of bytes transferred from file to the socket */
                long bytesTransferred = fc.transferTo(startPosition, limit, socketChannel_);
                logger_.debug("Bytes transferred " + bytesTransferred);               
                bytesWritten += bytesTransferred;
                startPosition += bytesTransferred;
                /*
                 * If the number of bytes transferred is less than intended
View Full Code Here


               
                long bytesTransferred;
                try
                {
                    /* returns the number of bytes transferred from file to the socket */
                    bytesTransferred = fc.transferTo(startPosition, limit, socketChannel_);
                }
                catch (IOException e)
                {
                    // at least jdk1.6.0 on Linux seems to throw IOException
                    // when the socket is full. (Bug fixed for 1.7: http://bugs.sun.com/view_bug.do?bug_id=5103988)
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 in = new FileInputStream(file).getChannel();
        // FileLock lock = in.lock();
        try {
            final long size = in.size();
            long written = 0;
            while ((written += in.transferTo(written, size, target)) < size) {
                ;
            }
            return size;
        } finally {
            in.close();
View Full Code Here

      amount += ChannelUtil.writeLong(channel, dataLen);

      long position = 0;
      do
      {
        position += fc.transferTo(position, dataLen - position, channel);
      } while (position < dataLen);
     
      amount += position;
    }
    finally
View Full Code Here

      File bakFile = new File(javaFile.getAbsolutePath() + ".bak");
      FileOutputStream fos = new FileOutputStream(bakFile);
      fos.write(DEFAULT_HEADER.getBytes());
      FileChannel fc = raf.getChannel();
      long count = raf.length() - endOfHeader;
      fc.transferTo(endOfHeader, count, fos.getChannel());
      fc.close();
      fos.close();
      raf.close();
      if (!javaFile.delete())
         log.severe("Failed to delete java file: " + javaFile);
View Full Code Here

    public static String read(File file, String encoding) throws IOException {
        FileChannel in = new FileInputStream(file).getChannel();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            in.transferTo(0, in.size(), Channels.newChannel(baos));
            return baos.toString(encoding);
        } finally {
            in.close();
        }
    }
View Full Code Here

    public static String read(File file, String encoding) throws IOException {
        FileChannel in = new FileInputStream(file).getChannel();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            in.transferTo(0, in.size(), Channels.newChannel(baos));
            return baos.toString(encoding);
        } finally {
            in.close();
        }
    }
View Full Code Here

    public static String read(File file, String encoding) throws IOException {
        FileChannel in = new FileInputStream(file).getChannel();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            in.transferTo(0, in.size(), Channels.newChannel(baos));
            return baos.toString(encoding);
        } finally {
            in.close();
        }
    }
View Full Code Here

    public static String read(File file, String encoding) throws IOException {
        FileChannel in = new FileInputStream(file).getChannel();
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            in.transferTo(0, in.size(), Channels.newChannel(baos));
            return baos.toString(encoding);
        } finally {
            in.close();
        }
    }
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.