Copy the contents of the given Reader to the given Writer.
Closes both when done.

@param in  the Reader to copy from
@param out the Writer to copy to
@return the number of characters copied
@throws IOException in case of I/O errors
428001
public static int copy(Reader in, Writer out) throws IOException {
        assert in != null : "No input Reader specified";
        assert out != null : "No output Writer specified";

        try {
            int byteCount = 0;
            char[] buffer = new char[BUFFER_SIZE];
            int bytesRead = -1;
            while ((bytesRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
                byteCount += bytesRead;
            }
            out.flush();
            return byteCount;
        } finally {
            try {
                in.close();
            } catch (IOException ex) {
            }
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }
607177
private static final void copy(Reader r, Writer w, long timeout) throws IOException {
	copy(r, w, 0xffff, timeout);
    }
935199
public static void copyFile(File in, File out) throws IOException {
     FileChannel inChannel = new
         FileInputStream(in).getChannel();
     FileChannel outChannel = new
         FileOutputStream(out).getChannel();
     try {
         inChannel.transferTo(0, inChannel.size(), outChannel);
     } 
     catch (IOException e) {
         throw e;
     }
     finally {
         if (inChannel != null)  { 
             inChannel.close();
         }
         if (outChannel != null)  {
             outChannel.close();
         }
     }
 }
502828
public static int copyAndCloseOutput(Reader input, Writer output) throws IOException {
		try {
			return copy(input, output);
		} finally {
			output.close();
		}
		
	}
235624
public void copyToOutputStream(OutputStream o) throws IOException {
		long left = end - start;
		int BUFF_SIZE = 4096;
		byte buf[] = new byte[BUFF_SIZE];
		RandomAccessFile raf = new RandomAccessFile(file, "r");
		try {
			raf.seek(start);
			while(left > 0) {
				int amtToRead = (int) Math.min(left, BUFF_SIZE);
				int amtRead = raf.read(buf, 0, amtToRead);
				if(amtRead < 0) {
					throw new IOException("Not enough to read! EOF before expected region end");
				}
				o.write(buf,0,amtRead);
				left -= amtRead;
			}
		} finally {
			raf.close();
		}
	}
484194
public static long copy(ReadableByteChannel in, WritableByteChannel out) throws IORuntimeException {
		return copy(in, out, DEFAULT_BUFFER_SIZE);
	}
647408
public static String getContent(Reader in) throws IOException {
    try {
      StringWriter sw = new StringWriter();
      copy(in, sw);
      return sw.toString();
    }
    finally {
      in.close();
    }
  }
336034
public static int writeTo(final OutputStream out, LinkedBuffer node) throws IOException
    {
        int contentSize = 0, len;
        do
        {
            if ((len = node.offset - node.start) > 0)
            {
                out.write(node.buffer, node.start, len);
                contentSize += len;
            }
        } while ((node = node.next) != null);

        return contentSize;
    }
666317
public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[BUFFER_SIZE];
        while (true) {
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            out.write(buffer, 0, read);
            byteCount += read;
        }
        return byteCount;
    }
1099153
public static void copy(InputStream in, OutputStream out, long count)
			throws IOException {
		copy(in, out, count, BUFFER_SIZE);
	}
1093617
public static void copyThread(Reader in, Writer out)
    {
        try
        {
            instance().run(new Job(in,out));
        }
        catch(InterruptedException e)
        {
            log.warn(LogSupport.EXCEPTION,e);
        }
    }
748600
public static long copy(final Reader input, final Writer output) throws IOException {
		return CharStreams.copy(input, output);
	}
813413
public long copy(InputStream in, OutputStream out, long max) throws IOException {
        int chunk;
        long all;
        long remaining;
        
        remaining = max;
        all = 0;
        while (remaining > 0) {
            // cast is save because the buffer.length is an integer
            chunk = in.read(buffer, 0, (int) Math.min(remaining, buffer.length));
            if (chunk < 0) {
                break;
            }
            out.write(buffer, 0, chunk);
            all += chunk;
            remaining -= chunk;
        }
        out.flush();
        return all;
    }
534378
public static void copy(byte[] in, File out) throws IOException {
        assert in != null : "No input byte array specified";
        assert out != null : "No output File specified";
        ByteArrayInputStream inStream = new ByteArrayInputStream(in);
        OutputStream outStream = new BufferedOutputStream(Files.newOutputStream(out.toPath()));
        copy(inStream, outStream);
    }
416260
public static void copy(byte[] in, File out) throws IOException {
		Assert.notNull(in, "No input byte array specified");
		Assert.notNull(out, "No output File specified");
		ByteArrayInputStream inStream = new ByteArrayInputStream(in);
		OutputStream outStream = new BufferedOutputStream(new FileOutputStream(out));
		copy(inStream, outStream);
	}
1273505
public static void copy(final InputStream in, final OutputStream out)
			throws IOException {
		copy(in, out, DEFAULT_BUFFER_SIZE);
	}
423241
public void copy(File in, File out) throws IOException {
	InputStream is = null;
	OutputStream os = null;
	try {
	    is = new BufferedFileInputStream(in);
	    os = new BufferedFileOutputStream(out);
	}
	catch (IOException ioe) {
	    closeEL(is, os);
	    throw ioe;
	}
	copy(is, os, true, true);
    }