Package java.nio.channels

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


    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


              wrapped = in;
            }
           
            if (wrapped instanceof FileInputStream) {
                FileChannel fileChannel = ((FileInputStream)wrapped).getChannel();
                fileChannel.transferTo(skipped, fileChannel.size(), channel);
                fileChannel.close();
            } else {
                int i = 0;

                // read all the content of the underlying InputStream in 16384 byte chunks, wrap them
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

            wbc = Channels.newChannel(out);

            long count    = 0;
            int attempts  = 0;
            while (count < sz) {
                long written = fc.transferTo(count, sz, wbc);
                count += written;

                if (written == 0) {
                    attempts++;
                    if (attempts > 100) {
View Full Code Here

                out = Channels.newChannel(os);
            }
            FileChannel fc = s.getChannel();
            long pos = 0;
            while (pos < len) {
                long i = fc.transferTo(pos, len - pos, out);
                pos += i;
            }
            s.close();
        } else {
            IOHelper.copy(getInputStream(), os);
View Full Code Here

        int safe_max = (64 * 1024 * 1024) / 4;
        long size = srcChannel.size();
        long position = 0;
        while (position < size)
        {
          position += srcChannel.transferTo(position, safe_max,
              dstChannel);
        }
      }

      // Close the channels
View Full Code Here

            File fileServer = new File(Constants.PHOTO_DIR + personId + ".jpg");
            if(!fileServer.exists()) {
              fileServer.createNewFile();
            }
         
          in.transferTo(0, in.size(), new FileOutputStream(fileServer).getChannel());
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

            File fileServer = new File(Constants.PHOTO_DIR + personId + ".jpg");
            if(!fileServer.exists()) {
              fileServer.createNewFile();
            }
         
          in.transferTo(0, in.size(), new FileOutputStream(fileServer).getChannel());
          in.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

                     File fileServer = new File(Constants.DOWNLOAD_DIR +  fileDescriptor.getName());
                     if(!fileServer.exists()) {
                       fileServer.createNewFile();
                     }
                  
                   inFileChannel.transferTo(0, inFileChannel.size(), new FileOutputStream(fileServer).getChannel());
                  
                   inFileChannel.close();
                 }
            }
           
View Full Code Here

                {
                    int toTransfer = (int) Math.min(CHUNK_SIZE, length - bytesTransferred);
                    long lastWrite;
                    if (sc != null)
                    {
                        lastWrite = fc.transferTo(section.left + bytesTransferred, toTransfer, sc);
                        throttle.throttleDelta(lastWrite);
                    }
                    else
                    {
                        // NIO is not available. Fall back to normal streaming.
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.