Debug (dump) the contents of an input stream. This effectively copies
the input stream into a byte array, dumps one and then returns another.
If logging is not enabled, nothing happens.

@param in
@throws IOException
331944
private InputStream debugInputStream(InputStream in) throws IOException {
        if (logger.isLoggable(Level.FINEST)) {
            final byte[] buffer = new byte[1024];
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int len;
            String line;

            logger.finest("[START] Dumping the InputStream that will be passed to JSON.parse()");
            while ((len = in.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }
            baos.flush();

            ByteArrayInputStream dumpIn = new ByteArrayInputStream(baos.toByteArray());
            BufferedReader br = new BufferedReader(new InputStreamReader(dumpIn));
            while ((line = br.readLine()) != null) {
                logger.finest(line);
            }
            logger.finest("[END] Dumping the InputStream that will be passed to JSON.parse()");

            return new ByteArrayInputStream(baos.toByteArray());
        } else {
            return in;

        }
    }
224602
public static void copyStream(InputStream from, OutputStream to) throws IOException {
        byte buffer[] = new byte[2048];
        int bytesRead;
        while ((bytesRead = from.read(buffer)) != -1) {
            to.write(buffer, 0, bytesRead);
        }
        from.close();
    }
384633
public static void copy(InputStream inputStream, OutputStream outputStream, byte[] buffer) throws IOException {
    LOGGER.trace("copy(InputStream, OutputStream, byte[])");
    copy(inputStream, outputStream, buffer, null);
  }
1261971
private void copydata(InputStream in, OutputStream out) throws java.io.IOException
    {
        long timestamp= 0;
        long byteCount = 0;
        while (true)
        {
            try
            {
                byteCount = copyBytes(in, out,-1);
                timestamp= 0;
                if (byteCount == -1) {
                    return;
                }
            }
            catch (InterruptedIOException e)
            {
                LogSupport.ignore(log, e);
                if (timestamp == 0)
                    timestamp= System.currentTimeMillis();
                else if (_timeoutMs > 0 && (System.currentTimeMillis() - timestamp) > _timeoutMs)
                    throw e;
            }
        }
    }
135915
public long copy(InputStream in, OutputStream out) throws IOException {
        return copy(in, out, Integer.MAX_VALUE);
    }
1273505
public static void copy(final InputStream in, final OutputStream out)
			throws IOException {
		copy(in, out, DEFAULT_BUFFER_SIZE);
	}
973450
public static void copyStream(final InputStream src, OutputStream dest) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = src.read(buffer)) > -1) {
            dest.write(buffer, 0, read);
        }
        dest.flush();
    }
648714
private static void inflater(InputStream in, OutputStream out) {
		final InflaterOutputStream ios = (out instanceof InflaterOutputStream) ? (InflaterOutputStream) out : new InflaterOutputStream(out, new Inflater(true));
		IoUtil.copy(in, ios);
		try {
			ios.finish();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
632790
protected void logByteBuffer(String msg, ByteBuffer inBuffer) {
        if(!logger.isLoggable(DEBUG)) return;

        ByteBuffer bb = inBuffer.duplicate();

        byte[] byData = new byte[512];
        int len = Math.min(byData.length, bb.remaining());
        byte dataByte = bb.get();
        int pos = 0;
        while(pos < len && dataByte != '~') {
            byData[pos] = dataByte;
            pos++;
            dataByte = bb.get();
        }

        logger.log(DEBUG, msg + ". Content: " + new String(byData, 0, pos));
    }
802262
public static void copy(InputStream input,
      OutputStream output,
      int bufferSize)
      throws IOException {
    byte[] buf = new byte[bufferSize];
    int bytesRead = input.read(buf);
    while (bytesRead != -1) {
      output.write(buf, 0, bytesRead);
      bytesRead = input.read(buf);
    }
    output.flush();
  }
723669
public static void copy(String in, Writer out) throws IOException {
		Assert.notNull(in, "No input String specified");
		Assert.notNull(out, "No Writer specified");
		try {
			out.write(in);
		}
		finally {
			try {
				out.close();
			}
			catch (IOException ex) {
			}
		}
	}
1312310
public static void copy(String in, Writer out) throws IOException {
        assert in != null : "No input String specified";
        assert out != null : "No output Writer specified";

        try {
            out.write(in);
        } finally {
            try {
                out.close();
            } catch (IOException ex) {
            }
        }
    }
645301
public static void copy(InputStream in,
			OutputStream out) throws IOException {
		copy(in, out, false);
	}
23238
public void dump() throws IOException {
    FileWriter out = new FileWriter(outFile, true);
    try {
      dump(out);
    } finally {
      out.close();
    }
  }
1299639
public static int copy(File in, File out) throws IOException {
		Assert.notNull(in, "No input File specified");
		Assert.notNull(out, "No output File specified");
		return copy(new BufferedInputStream(new FileInputStream(in)),
			new BufferedOutputStream(new FileOutputStream(out)));
	}
688352
public static void copyBytes(InputStream in, OutputStream out, Configuration conf)
    throws IOException {
    copyBytes(in, out, conf.getInt("io.file.buffer.size", 4096), true);
  }
533745
private void copyStream(InputStream inputStream) throws IOException {
		OutputStream outputStream = null;
		try {
			outputStream = getContext().getOutputStream();
			byte[] buffer = new byte[65535];
			int bufferLen;
			int totalLen = 0;
			while ((bufferLen = inputStream.read(buffer)) > 0) {
				outputStream.write(buffer, 0, bufferLen);
				totalLen += bufferLen;
			}
			getContext().getResponse().setContentLength(totalLen);
		} finally {
			if (outputStream != null) {
				outputStream.flush();
			}
		}
	}