/* (non-Javadoc)
@see org.processmining.framework.log.rfb.io.RandomAccessStorage#copy()
15355
public synchronized NikeFS2RandomAccessStorage copy() throws IOException {
		// NOTE: This method's implementation assumes that all blocks served
		// from the virtual file system are of equal block size!
		// If this condition does not hold, unexpected results will be
		// expected!
		NikeFS2RandomAccessStorageImpl clone = new NikeFS2RandomAccessStorageImpl(vfs);
		if(blocks.size() > 0) {
			// add copies of all contained blocks
			byte[] buffer = new byte[blocks.get(0).size()];
			for(NikeFS2Block block : blocks) {
				NikeFS2Block copyBlock = vfs.allocateBlock();
				block.read(0, buffer);
				copyBlock.write(0, buffer);
				clone.blocks.add(copyBlock);
			}
		}
		// adjust state
		clone.size = size;
		clone.pointer = 0;
		return clone;
	}
1153363
public static void copy(InputStream source, OutputStream destination) throws IOException
    {
        Check.notNull(source);
        Check.notNull(destination);

        final byte[] buffer = new byte[BUFFER_COPY];
        while (true)
        {
            final int read = source.read(buffer);
            if (read == -1)
            {
                break;
            }
            destination.write(buffer, 0, read);
        }
    }
1261833
private void copyInternal(
      BatchHelper batchHelper,
      final KeySetView<IOException, Boolean> innerExceptions,
      final String srcBucketName, final String srcObjectName,
      final String dstBucketName, final String dstObjectName)
      throws IOException {
    Storage.Objects.Copy copyObject =
        configureRequest(
            gcs.objects().copy(srcBucketName, srcObjectName, dstBucketName, dstObjectName, null),
            srcBucketName);

    batchHelper.queue(
        copyObject,
        new JsonBatchCallback<StorageObject>() {
          @Override
          public void onSuccess(StorageObject copyResponse, HttpHeaders responseHeaders) {
            String srcString = StorageResourceId.createReadableString(srcBucketName, srcObjectName);
            String dstString = StorageResourceId.createReadableString(dstBucketName, dstObjectName);
            logger.atFine().log("Successfully copied %s to %s", srcString, dstString);
          }

          @Override
          public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            onCopyFailure(innerExceptions, e, srcBucketName, srcObjectName);
          }
        });
  }
316386
private void copy(final WritableByteChannel target,
        final byte[] boundary, final ReadableByteChannel body)
        throws IOException {
        int match = 0;
        boolean cont = true;
        while (cont) {
            if (!this.buffer.hasRemaining()) {
                this.buffer.clear();
                for (int idx = 0; idx < match; ++idx) {
                    this.buffer.put(boundary[idx]);
                }
                match = 0;
                if (body.read(this.buffer) == -1) {
                    break;
                }
                this.buffer.flip();
            }
            final ByteBuffer btarget = this.buffer.slice();
            final int offset = this.buffer.position();
            btarget.limit(0);
            while (this.buffer.hasRemaining()) {
                final byte data = this.buffer.get();
                if (data == boundary[match]) {
                    ++match;
                } else if (data == boundary[0]) {
                    match = 1;
                } else {
                    match = 0;
                    btarget.limit(this.buffer.position() - offset);
                }
                if (match == boundary.length) {
                    cont = false;
                    break;
                }
            }
            target.write(btarget);
        }
    }
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);
    }
115229
public static int copy(File in, File out) throws IOException {
        assert in != null : "No input File specified";
        assert out != null : "No output File specified";
        return copy(new BufferedInputStream(Files.newInputStream(in.toPath())),
            new BufferedOutputStream(Files.newOutputStream(out.toPath())));
    }
1110055
public static void copy(final File src, final File dest) throws IOException {
        if (src.isDirectory()) {
            if (!dest.exists()) {
                dest.mkdir();
            }

            // Copy everything in directory
            String[] children = src.list();
            for (String child : children) {
                copy(new File(src, child), new File(dest, child));
            }
        } else {
            try (ReadableByteChannel in = Channels.newChannel(new FileInputStream(src))) {
                try (WritableByteChannel out = Channels.newChannel(new FileOutputStream(dest))) {
                    fastChannelCopy(in, out);
                }
            }
        }
    }
895690
private static final void copy(Reader r, Writer w, int blockSize, long timeout) throws IOException {
	if (timeout < 1) {
	    char[] buffer = new char[blockSize];
	    int len;

	    while ((len = r.read(buffer)) != -1)
		w.write(buffer, 0, len);
	}
	else {
	    Copy c = new Copy(r, w, blockSize, timeout);
	    c.start();

	    try {
		synchronized (c.notifier) {// print.err(timeout);
		    c.notifier.wait(timeout + 1);
		}
	    }
	    catch (InterruptedException ie) {
		throw ExceptionUtil.toIOException(c.t);
	    }
	    if (c.t != null) throw ExceptionUtil.toIOException(c.t);
	    if (!c.finished) throw new IOException("reached timeout (" + timeout + "ms) while copying data");

	}
    }
378863
public static void copyRecursive(Resource src, Resource trg, ResourceFilter filter) throws IOException {
	// print.out(src);
	// print.out(trg);
	if (!src.exists()) return;
	if (src.isDirectory()) {
	    if (!trg.exists()) trg.createDirectory(true);
	    Resource[] files = filter == null ? src.listResources() : src.listResources(filter);
	    if (files != null) for (int i = 0; i < files.length; i++) {
		copyRecursive(files[i], trg.getRealResource(files[i].getName()), filter);
	    }
	}
	else if (src.isFile()) {
	    touch(trg);
	    IOUtil.copy(src, trg);
	}
    }
656188
public static void copy(File from, File to) throws IOException {
        if (from.isDirectory())
            copyDir(from, to);
        else
            copyFile(from, to);
    }
691644
private static void copy(InputStream source, OutputStream sink) throws IOException {
        byte[] buf = new byte[8192];
        int n;
        while ((n = source.read(buf)) > 0) {
            sink.write(buf, 0, n);
        }
    }
683604
public static long copy(ReadableByteChannel in, WritableByteChannel out, int bufferSize) throws IORuntimeException {
		return copy(in, out, bufferSize, null);
	}
1281426
protected synchronized void copy(Writable other) {
    if (other != null) {
      try {
        DataOutputBuffer out = new DataOutputBuffer();
        other.write(out);
        DataInputBuffer in = new DataInputBuffer();
        in.reset(out.getData(), out.getLength());
        readFields(in);
        
      } catch (IOException e) {
        throw new IllegalArgumentException("map cannot be copied: " +
            e.getMessage());
      }
      
    } else {
      throw new IllegalArgumentException("source map cannot be null");
    }
  }
383869
private void copyObject(WebContext ctx, Bucket bucket, String id, String copy) throws IOException {
        StoredObject object = bucket.getObject(id);
        if (!copy.contains(PATH_DELIMITER)) {
            signalObjectError(ctx, HttpResponseStatus.BAD_REQUEST, "Source must contain '/'");
            return;
        }
        String srcBucketName = copy.substring(1, copy.lastIndexOf(PATH_DELIMITER));
        String srcId = copy.substring(copy.lastIndexOf(PATH_DELIMITER) + 1);
        Bucket srcBucket = storage.getBucket(srcBucketName);
        if (!srcBucket.exists()) {
            signalObjectError(ctx, HttpResponseStatus.BAD_REQUEST, "Source bucket does not exist");
            return;
        }
        StoredObject src = srcBucket.getObject(srcId);
        if (!src.exists()) {
            signalObjectError(ctx, HttpResponseStatus.BAD_REQUEST, "Source object does not exist");
            return;
        }
        Files.copy(src.getFile(), object.getFile());
        if (src.getPropertiesFile().exists()) {
            Files.copy(src.getPropertiesFile(), object.getPropertiesFile());
        }
        HashCode hash = Files.hash(object.getFile(), Hashing.md5());
        String etag = BaseEncoding.base16().encode(hash.asBytes());

        XMLStructuredOutput structuredOutput = ctx.respondWith().addHeader(HTTP_HEADER_NAME_ETAG, etag(etag)).xml();
        structuredOutput.beginOutput("CopyObjectResult");
        structuredOutput.beginObject("LastModified");
        structuredOutput.text(RFC822_INSTANT.format(object.getLastModifiedInstant()));
        structuredOutput.endObject();
        structuredOutput.beginObject(HTTP_HEADER_NAME_ETAG);
        structuredOutput.text(etag(etag));
        structuredOutput.endObject();
        structuredOutput.endOutput();
        signalObjectSuccess(ctx);
    }
312156
private boolean copy(InputStream source, String destination) {
        boolean success = true;

        try
        {
            Files.copy(source, Paths.get(destination), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException ex)
        {
            LOG.fatal("Cannot write file " + destination, ex);
            success = false;
        }

        return success;
    }
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);
	}
10967
@Override
	public T copy(T from) {
		if (CONCURRENT_ACCESS_CHECK) {
			enterExclusiveThread();
		}

		try {
			checkAvroInitialized();
			return avroData.deepCopy(runtimeSchema, from);
		}
		finally {
			if (CONCURRENT_ACCESS_CHECK) {
				exitExclusiveThread();
			}
		}
	}