copy data from source struct to target struct

@param source
@param target
@param overwrite overwrite data if exist in target
188693
public static void copy(Struct source, Struct target, boolean overwrite) {
	Iterator<Entry<Key, Object>> it = source.entryIterator();
	Entry<Key, Object> e;
	while (it.hasNext()) {
	    e = it.next();
	    if (overwrite || !target.containsKey(e.getKey())) target.setEL(e.getKey(), e.getValue());
	}
    }
940366
public static void writeToMemory(byte[] src, Object target, long targetOffset) {
    Platform.copyMemory(src, Platform.BYTE_ARRAY_OFFSET, target, targetOffset, src.length);
  }
1075396
void submit(boolean overwrite, Map<String, String> makroMap) {

        try {
            CmsResource targetFolder = null;
            String targetName = null;
            String target = m_targetPath.getValue();
            boolean isSingleResource = m_context.getResources().size() == 1;
            // resolve relative paths
            target = CmsLinkManager.getAbsoluteUri(
                target,
                CmsResource.getParentFolder(getCms().getSitePath(m_context.getResources().get(0))));

            // check if the given path is a root path
            CmsObject cms = OpenCms.getSiteManager().getSiteForRootPath(target) != null ? getRootCms() : getCms();

            if (cms.existsResource(target, CmsResourceFilter.ALL.addRequireFolder())) {
                // The target is an existing folder
                // always copy files into that folder
                targetFolder = cms.readResource(target);
            } else if (cms.existsResource(target, CmsResourceFilter.ALL.addRequireFile())) {
                // The target is an existing file
                if (isSingleResource) {
                    // Replace the file with the resource copied, if it is just a single resource
                    if (target.equals(m_context.getResources().get(0).getRootPath())) {
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_COPY_ONTO_ITSELF_1,
                                target));
                    }
                    targetName = CmsResource.getName(target);
                    targetFolder = cms.readResource(CmsResource.getParentFolder(target));
                } else {
                    // Throw an error if a single file should be replaced with multiple resources
                    // since we cannot copy multiple resources to a single file
                    throw new CmsVfsException(
                        org.opencms.workplace.commons.Messages.get().container(
                            org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                            target));
                }
            } else {
                // The target does not exist
                if (isSingleResource) {
                    // If we have a single resource, we could possible create the target as copy of that resource
                    if (cms.existsResource(
                        CmsResource.getParentFolder(target),
                        CmsResourceFilter.ALL.addRequireFolder())) {
                        targetName = CmsResource.getName(target);
                        targetFolder = cms.readResource(CmsResource.getParentFolder(target));
                    } else {
                        // If the parent folder of the resource does not exist, we will not create it automatically.
                        // Thus we need to throw an exception.
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_COPY_TARGET_PARENT_FOLDER_MISSING_1,
                                target));
                    }
                } else {
                    // We cannot copy multiple resources to a single resource
                    throw new CmsVfsException(
                        org.opencms.workplace.commons.Messages.get().container(
                            org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                            target));
                }
            }

            Action action = m_actionCombo != null ? (Action)m_actionCombo.getValue() : Action.move;

            overwrite = overwrite || isOverwriteExisting();
            if (!overwrite || action.equals(Action.move)) {
                List<CmsResource> collidingResources = getExistingFileCollisions(targetFolder, targetName);
                if (collidingResources != null) {
                    if (action.equals(Action.move)) {
                        throw new CmsVfsException(
                            org.opencms.workplace.commons.Messages.get().container(
                                org.opencms.workplace.commons.Messages.ERR_MOVE_FORCES_OVERWRITE_EXISTING_RESOURCE_0));
                    } else {
                        showConfirmOverwrite(collidingResources);
                        return;
                    }
                }
            }
            Map<CmsResource, CmsException> errors = new HashMap<CmsResource, CmsException>();

            //Check if dialog for macro resolver has to be shown: action correct?, makroMap==null (default, not set by dialog yet)
            if ((action == Action.sub_sitemap) & (makroMap == null)) {
                if (CmsSiteManager.isFolderWithMacros(getRootCms(), m_context.getResources().get(0).getRootPath())) {
                    showMacroResolverDialog(m_context.getResources().get(0));
                    return;
                }
            }
            if (targetName == null) {
                for (CmsResource source : m_context.getResources()) {
                    try {
                        performSingleOperation(source, targetFolder, action, overwrite, makroMap);
                    } catch (CmsException e) {
                        errors.put(source, e);
                        LOG.error(
                            "Error while executing "
                                + m_actionCombo.getValue().toString()
                                + " on resource "
                                + source.getRootPath(),
                            e);
                    }
                }
            } else {
                // this will only be the case in a single resource scenario
                CmsResource source = m_context.getResources().get(0);
                try {
                    performSingleOperation(source, targetFolder, targetName, action, overwrite, makroMap);
                } catch (CmsException e) {
                    errors.put(source, e);
                    LOG.error(
                        "Error while executing "
                            + m_actionCombo.getValue().toString()
                            + " on resource "
                            + source.getRootPath(),
                        e);
                }
            }

            if (!errors.isEmpty()) {
                m_context.finish(m_updateResources);
                m_context.error(errors.values().iterator().next());
            } else {
                m_context.finish(m_updateResources);
            }

        } catch (CmsException e) {
            m_context.error(e);
        }
    }
51247
public static function rename($origin, $target, $overwrite = false)
    {
        self::ensureFileSystem()->rename($origin, $target, $overwrite);
    }
741179
private void copyToTargetBufferFrom(ByteBuffer source) {
		if (this.targetBuffer == null) {
			return;
		}

		int needed = source.remaining();
		int available = this.limit - this.position;
		int toCopy = Math.min(needed, available);

		this.targetBuffer.getMemorySegment().put(this.position, source, toCopy);

		this.position += toCopy;
	}
993481
public static void copyDirs(Path source, Path target, CopyOption... options) throws IOException {
        if (Files.notExists(target)) {
            Files.createDirectory(target);
        }

        logger.debug("  --> Copying resources from [{}]", source);
        if (Files.notExists(source)) {
            throw new RuntimeException(source + " doesn't seem to exist.");
        }

        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new InternalFileVisitor(source, target, options));

        logger.debug("  --> Resources ready in [{}]", target);
    }
942341
static void copyDirectory(File sourceDirectory, File targetDirectory) throws IOException {

		final Path sourcePath = Paths.get(sourceDirectory.toURI()).toRealPath();
		final Path targetPath = Paths.get(targetDirectory.toURI());

		Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
				Path relative = sourcePath.relativize(dir);
				Path target = targetPath.resolve(relative);
				File folder = target.toFile();
				if (!folder.exists()) {
					mkdirs(folder);
				}
				return FileVisitResult.CONTINUE;
			}

			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				Path relative = sourcePath.relativize(file);
				Path target = targetPath.resolve(relative);
				Files.copy(file, target, StandardCopyOption.COPY_ATTRIBUTES);
				return FileVisitResult.CONTINUE;
			}
		});
	}
804990
public <T> void move(Local<T> target, Local<T> source) {
        addInstruction(new PlainInsn(Rops.opMove(source.type.ropType),
                sourcePosition, target.spec(), source.spec()));
    }
42454
function overwrite(input, clone) {
  // Overwrite input.getReader, input.locked, etc to point to clone
  Object.entries(Object.getOwnPropertyDescriptors(ReadableStream.prototype)).forEach(([name, descriptor]) => {
    if (name === 'constructor') {
      return;
    }
    if (descriptor.value) {
      descriptor.value = descriptor.value.bind(clone);
    } else {
      descriptor.get = descriptor.get.bind(clone);
    }
    Object.defineProperty(input, name, descriptor);
  });
}
199840
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
    {
        if (self::DO_NOT_COPY === $this->copySource) {
            return;
        }

        if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is same, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );
            return;
        }

        if ((self::COPY_IF_EMPTY === $this->copySource) && !$target->isSourceEmpty()) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is not empty, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );

            return;
        }

        $this->logger->log(
            LogLevel::NOTICE,
            '{key}: Updating source value.',
            ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
        );

        if ($this->dryRun) {
            return;
        }

        $target->setSource($newValue);
    }
1350923
private void updateProperties(T target, Map<String, Object> source) {
        Map<String, PropertyDescriptor> mapTargetProps = MappingUtils.mapPropertyDescriptors(target.getClass());

        for (String sourceKey : source.keySet()) {
            if (mapTargetProps.containsKey(sourceKey) == true) {
                MappingUtils.callSetter(target, mapTargetProps.get(sourceKey), source.get(sourceKey));
            }
        }
    }
1217190
public void writeToMemory(Object target, long targetOffset) {
    Platform.copyMemory(base, offset, target, targetOffset, numBytes);
  }
321771
public void copyFile(String source, String target) {

        try {
            CmsFileUtil.copy(m_configRfsPath + source, m_configRfsPath + target);
        } catch (IOException e) {
            m_errors.add("Could not copy " + source + " to " + target + " \n");
            m_errors.add(e.toString() + "\n");
        }
    }
327288
static function copyDirectory($source, $target, $overwrite = true)
    {
        $scanResult = static::scanDirectory($source);
        if (!$scanResult) return false;
        if (!is_dir($target)) self::createDirectory($target);

        try {
            $sourceRealPath = realpath($source);
            foreach ($scanResult['files'] as $file) {
                $targetRealPath = realpath($target) . '/' . ltrim(substr($file, strlen($sourceRealPath)), '/');
                static::copyFile($file, $targetRealPath, $overwrite);
            }
            return true;
        } catch (\Throwable $throwable) {
            return false;
        }
    }
632100
public static <V> void copyGraph(DirectedGraph<V, DefaultEdge> sourceGraph, DirectedGraph<V, DefaultEdge> targetGraph) {
        addAllVertices(targetGraph, sourceGraph.vertexSet());
        for (DefaultEdge edge : sourceGraph.edgeSet()) {
            targetGraph.addEdge(sourceGraph.getEdgeSource(edge), sourceGraph.getEdgeTarget(edge));
        }
    }
113746
private static final <E> void moveAll(ArrayList<E> source, ArrayList<E> target) {
		target.ensureCapacity(target.size() + source.size());
		for (int i = source.size() - 1; i >= 0; i--) {
			target.add(source.remove(i));
		}
	}
1019744
public static void copyProperties(final Object source, final Object target) {

        ExceptionUtils.iae.throwIfNull(source, SOURCE_IS_NULL_MESSAGE);
        ExceptionUtils.iae.throwIfNull(target, TARGETIS_NULL_MESSAGE);
        Class<Object> sourceClass = ClassUtils.getClass(source);
        Class<Object> targetClass = ClassUtils.getClass(target);
        Field[] sourceFields = sourceClass.getDeclaredFields();
        Field[] targetFields = targetClass.getDeclaredFields();
        try {
            for (Field sourceField : sourceFields) {
                Field targetField = getFieldByField(targetFields, sourceField);
                if (targetField != null) {
                    getAndSetValue(source, sourceField, target, targetField);
                }
            }
        } catch (Exception e) {
            throw new FatalBeanException(CAN_NOT_COPY_PROPERTIES, e);
        }
    }