Package java.nio.channels

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


        long bytesRead = 0;
        try
        {
            while (bytesRead < pendingFile.getExpectedBytes()) {
                bytesRead += fc.transferFrom(socketChannel, bytesRead, FileStreamTask.CHUNK_SIZE);
                pendingFile.update(bytesRead);
            }
            StreamingService.instance.setStatus("Receiving stream: finished reading chunk, awaiting more");
        }
        catch (IOException ex)
View Full Code Here


                targetFile.createNewFile();
            }

            sourceChannel = new FileInputStream(sourceFile).getChannel();
            targetChannel = new FileOutputStream(targetFile).getChannel();
            targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (Exception e) {
            throw new CedarRuntimeException("Failed to copy file: " + e.getMessage(), e);
        } finally {
            close(sourceChannel);
            close(targetChannel);
View Full Code Here

    {
        FileChannel c1 = new RandomAccessFile( src, "r" ).getChannel();
        FileChannel c2 = new RandomAccessFile( dst, "rw" ).getChannel();

        long tCount = 0, size = c1.size();
        while ( ( tCount += c2.transferFrom( c1, 0, size - tCount ) ) < size )
            ;

        c1.close();
        c2.force( true );
        c2.close();
View Full Code Here

            sourceChannel = sourceStream.getChannel();

            destinationStream = new FileOutputStream(newFile);
            destinationChannel = destinationStream.getChannel();

            destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
            sourceStream.close();
            destinationStream.close();
            File directory = historyFile.getParentFile();
            boolean deleted = historyFile.delete();
            if (!deleted) {
View Full Code Here

    private static void copyFile(File source, File dest) throws IOException {
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        // Create channel on the destination
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        // Copy file contents from source to destination
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        // Close the channels
        srcChannel.close();
        dstChannel.close();
    }
View Full Code Here

        FileChannel destination = null;

        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } catch (IOException ioe) {
            throw new RuntimeException("Unable to copy " + sourceFile.getAbsolutePath() + " to " + destFile.getAbsolutePath(), ioe);
        } finally {
            if(source != null) {
                try {
View Full Code Here

        FileChannel destination = null;

        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } catch (IOException ioe) {
            throw new RuntimeException("Unable to copy " + sourceFile.getAbsolutePath() + " to " + destFile.getAbsolutePath(), ioe);
        } finally {
            if(source != null) {
                try {
View Full Code Here

            outFile = new File(toDirectory, file.getName());
            fos = new FileOutputStream(outFile);
            FileChannel outCh = fos.getChannel();

            outCh.transferFrom(inCh, 0, inCh.size());

            return outFile;
        } catch (IOException ioe) {
            LOG.error(ioe);
            throw ioe;
View Full Code Here

                  ReadableByteChannel bch = Channels.newChannel(new ByteArrayInputStream(this.data));

                  if ((newIndex = (int)position) > 0)
                  {
                     // begin from the existed bytes
                     chch.transferFrom(bch, 0, newIndex < data.length ? newIndex : data.length);
                     bch.close();
                  }

                  // write update data
                  ReadableByteChannel sch = Channels.newChannel(stream);
View Full Code Here

                     bch.close();
                  }

                  // write update data
                  ReadableByteChannel sch = Channels.newChannel(stream);
                  chch.transferFrom(sch, newIndex, length);
                  sch.close();
                  newIndex += length;

                  if (newIndex < data.length)
                     // write the rest of existed data
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.