Examples of transferFrom()


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

        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

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

            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

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

                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

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

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

                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

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

    {
        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

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

            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

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

    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

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

        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

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

        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
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.