Copy input stream to output stream and close them both

@param is input stream
@param os output stream
@throws IOException for any error
160479
public static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException {
        copyStreamAndClose(is, os, DEFAULT_BUFFER_SIZE);
    }
1007461
private void copy( final InputStream is, final OutputStream os ) throws IOException
   {
      final byte[] buffer = new byte[ 512 ];
      int countOfBytes = -1;

      while ( !this.terminated )
      {
         while ( is.available() <= 0 )
         {
            synchronized( this )
            {
               try
               {
                  this.wait( 50 ); // guard
                  if ( this.terminated ) return;
               }
               catch ( InterruptedException ie )
               {
                  log.error(ie);
               }
            }
         }

         countOfBytes = is.read( buffer, 0, buffer.length );
         os.write( buffer, 0, countOfBytes );
      }
   }
961730
public void writeObject(Object o) throws IOException {
        ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(out);
        oos.writeObject(o);
        // don't close oss, which will close the underlying stream
        // no need to flush either, given the way oos is implemented
    }
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);
    }
548514
public void write(BitOutputStream os) throws IOException {

        os.writeRawULong(sampleNumber, SEEKPOINT_SAMPLE_NUMBER_LEN);
        os.writeRawULong(streamOffset, SEEKPOINT_STREAM_OFFSET_LEN);
        os.writeRawUInt(frameSamples, SEEKPOINT_FRAME_SAMPLES_LEN);
    }
157452
public static void copyStream(InputStream is, OutputStream os, int size) 
	throws IOException {
		byte[] buffer = new byte[size];
		for (int r = -1; (r = is.read(buffer, 0, size)) != -1;) {
			os.write(buffer, 0, r);
		}
	}
1311417
@Override
  public void close() throws IOException
  {
    Socket s = _s;
    _s = null;

    OutputStream os = _os;
    _os = null;

    InputStream is = _is;
    _is = null;

    try {
      if (os != null)
        os.close();
      
      if (is != null)
        is.close();
    } finally {
      if (s != null)
        s.close();
    }
  }
984324
public static void copyStream(InputStream is, OutputStream os) 
	throws IOException {
		copyStream(is,os,BUFFER_SIZE);
	}
292129
public void handleInputStream(final InputStream is) throws IOException
        {
        LOG.trace("Handling input stream.");
        final OutputStream os = new FileOutputStream(this.m_file);
        try
            {
            final long bytesWritten = org.littleshoot.util.IoUtils.copy(is, os, 
                this.m_writeListener);
            LOG.trace("Wrote "+bytesWritten+" to file: "+this.m_file);
            }
        finally
            {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
            }
        }
653001
public void inputStreamToFile(InputStream is, String filename) throws IOException {
        FileOutputStream fos = new FileOutputStream(filename);
        inputStreamToOutputStream(is, fos);
        fos.close();
    }
196654
public static int write(InputStream is, OutputStream os, boolean closeSink) {
        return copy(is, os, closeSink);
    }
595380
public void setProcessInputStream(OutputStream os) {
    if (input != null) {
      if (input == System.in) {
        inputThread = createSystemInPump(input, os);
      }
      else {
        inputThread = createPump(input, os, true, true);
      }
    }
    else {
      try {
        os.close();
      }
      catch (IOException e) {
        log.info("Got exception while closing output stream", e);
      }
    }
  }
178166
public static void write(byte b, OutputStream os) {
        try {
            os.write(b);
        } catch (IOException e) {
            throw E.ioException(e);
        }
    }
1155075
public void sendfile(OutputStream os, long offset, long length)
    throws IOException
  {
    if (os instanceof OutputStreamWithBuffer) {
      writeToStream((OutputStreamWithBuffer) os);
    }
    else {
      writeToStream(os);
    }
  }
26372
public static void compress(InputStream is, OutputStream os) throws Exception {
		GZIPOutputStream gos = new GZIPOutputStream(os);
		int count;
		byte data[] = new byte[BUFFER];
		while ((count = is.read(data, 0, BUFFER)) != -1) {
			gos.write(data, 0, count);
		}
		gos.finish();
		gos.flush();
		gos.close();
	}
386167
public void writeToStream(OutputStream os, int len)
    throws IOException
  {
    while (len > 0) {
      if (_readLength <= _readOffset) {
        if (! readBuffer())
          return;
      }

      int sublen = Math.min(len, _readLength - _readOffset);

      os.write(_readBuffer, _readOffset, sublen);
      _readOffset += sublen;
      len -= sublen;
    }
  }
726263
public void writeToStream(OutputStream os)
    throws IOException
  {
    StreamImpl is = openReadImpl();
    TempBuffer tempBuffer = TempBuffer.create();
    try {
      byte []buffer = tempBuffer.buffer();
      int length = buffer.length;
      int len;

      while ((len = is.read(buffer, 0, length)) > 0) {
        os.write(buffer, 0, len);
      }
    } finally {
      TempBuffer.free(tempBuffer);
      tempBuffer = null;

      is.close();
    }
  }