当前位置: 首页>>代码示例>>Java>>正文


Java HashUtil.compare方法代码示例

本文整理汇总了Java中org.hive2hive.core.security.HashUtil.compare方法的典型用法代码示例。如果您正苦于以下问题:Java HashUtil.compare方法的具体用法?Java HashUtil.compare怎么用?Java HashUtil.compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hive2hive.core.security.HashUtil的用法示例。


在下文中一共展示了HashUtil.compare方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDeletedRemotely

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
/**
 * Returns a list of files that have been deleted by another client during the absence of this client.
 * 
 * @return a list of files that has been deleted remotely
 */
public List<File> getDeletedRemotely() {
	List<File> deletedRemotely = new ArrayList<File>();

	for (String p : now.keySet()) {
		File file = new File(root, p);
		if (before.containsKey(p) && userProfile.getFileByPath(file, root) == null) {
			// is on disk but deleted in the user profile
			if (HashUtil.compare(before.get(p), now.get(p))) {
				// only delete the file, if it was not modified locally
				deletedRemotely.add(file);
			}
		}
	}

	logger.debug("Found {} files/folders that have been deleted remotely during absence.", deletedRemotely.size());
	return deletedRemotely;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:23,代码来源:FileSynchronizer.java

示例2: verifyAndWriteChunk

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
private void verifyAndWriteChunk(MetaChunk metaChunk, Chunk chunk) {
	// verify the hash
	byte[] respondedHash = HashUtil.hash(chunk.getData());
	if (HashUtil.compare(respondedHash, metaChunk.getChunkHash())) {
		logger.debug("Peer {} sent a valid content for chunk {}. Hash verified.", context.getSelectedPeer(),
				metaChunk.getIndex());
	} else {
		logger.error("Peer {} sent an invalid content for chunk {}.", context.getSelectedPeer(), metaChunk.getIndex());
		responseException = new ProcessExecutionException(this, "Invalid chunk received");
		removeLocation();
		return;
	}

	// hash is ok, write it to the file
	try {
		FileUtils.writeByteArrayToFile(context.getTempDestination(), chunk.getData());
		logger.debug("Wrote chunk {} to temporary file {}", context.getMetaChunk().getIndex(),
				context.getTempDestination());

		// finalize the sub-process
		context.getTask().markDownloaded(context.getMetaChunk().getIndex(), context.getTempDestination());
	} catch (IOException e) {
		context.getTask().abortDownload("Cannot write the chunk to the temporary file. Reason: " + e.getMessage());
	}
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:26,代码来源:AskForChunkStep.java

示例3: modifyUserProfile

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
@Override
public void modifyUserProfile(UserProfile userProfile) throws AbortModifyException {
	BaseMetaFile metaFile = context.consumeMetaFile();
	FileIndex index = (FileIndex) userProfile.getFileById(metaFile.getId());

	// store hash of meta file
	index.setMetaFileHash(context.consumeHash());

	// store for backup
	originalHash = index.getHash();
	if (HashUtil.compare(originalHash, newHash)) {
		throw new AbortModifyException(AbortModificationCode.SAME_CONTENT,
				"Try to create new version with same content.");
	}

	// make modifications
	logger.debug("Updating the hash in the user profile.");
	index.setHash(newHash);

	// store for notification
	context.provideIndex(index);
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:23,代码来源:UpdateHashInUserProfileStep.java

示例4: equals

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
@Override
public boolean equals(Object obj) {
	if (obj == null) {
		return false;
	}

	if (obj instanceof MetaChunk) {
		MetaChunk other = (MetaChunk) obj;
		return other.getChunkId().equalsIgnoreCase(chunkId) && other.getIndex() == index
				&& HashUtil.compare(chunkHash, other.getChunkHash());
	}

	return false;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:15,代码来源:MetaChunk.java

示例5: getDeletedLocally

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
/**
 * Returns a list of files that have been deleted from the disc during this client was offline
 * 
 * @return a list of files that has been deleted locally
 */
public List<Index> getDeletedLocally() {
	List<Index> deletedLocally = new ArrayList<Index>();

	for (String path : before.keySet()) {
		if (now.containsKey(path)) {
			// skip, this file is still here
			continue;
		} else {
			// test whether it is in the user profile
			Index node = userProfile.getFileByPath(new File(root, path), root);
			if (node != null) {
				// file is still in user profile
				if (node.isFolder()) {
					deletedLocally.add(node);
				} else {
					// check the hash value to not delete a modified file
					FileIndex fileNode = (FileIndex) node;
					if (HashUtil.compare(fileNode.getHash(), before.get(path))) {
						// file has not been modified remotely, delete it
						logger.debug("File '{}' has been deleted locally during absence.", path);
						deletedLocally.add(node);
					}
				}
			}
		}
	}

	// delete from behind
	sortNodesPreorder(deletedLocally);
	Collections.reverseOrder();

	logger.info("Found {} files/folders that have been deleted locally during absence.", deletedLocally.size());
	return deletedLocally;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:40,代码来源:FileSynchronizer.java

示例6: getUpdatedLocally

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
/**
 * Returns a list of files that already existed but have been modified by the client while he was offline.
 * 
 * @return a list of files that has been updated locally
 */
public List<File> getUpdatedLocally() {
	List<File> updatedLocally = new ArrayList<File>();

	for (String path : now.keySet()) {
		if (!before.containsKey(path)) {
			// was not here before --> skip
			continue;
		}

		if (HashUtil.compare(before.get(path), now.get(path))) {
			// hash before and after match --> nothing changed
			continue;
		}

		File file = new File(root, path);
		Index index = userProfile.getFileByPath(file, root);
		if (index == null || index.isFolder()) {
			// file not found --> skip, this is not the task of this method
			// file node is a folder --> cannot compare the modification
			continue;
		}

		FileIndex fileNode = (FileIndex) index;

		// has been modified --> check if profile has same hash as 'before'. If not, there are three
		// different versions. Thus, the profile wins.
		if (HashUtil.compare(fileNode.getHash(), before.get(path)) && !HashUtil.compare(fileNode.getHash(), now.get(path))) {
			logger.debug("File '{}' has been updated locally during absence.", path);
			updatedLocally.add(file);
		}
	}

	sortFilesPreorder(updatedLocally);
	logger.info("Found {} files/folders that have been updated locally during absence.", updatedLocally.size());
	return updatedLocally;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:42,代码来源:FileSynchronizer.java

示例7: getUpdatedRemotely

import org.hive2hive.core.security.HashUtil; //导入方法依赖的package包/类
/**
 * Returns files that have been remotely modified while the client was offline
 * 
 * @return a list of files that has been updated remotely
 */
public List<FileIndex> getUpdatedRemotely() {
	List<FileIndex> updatedRemotely = new ArrayList<FileIndex>();

	// visit all files in the tree and compare to disk
	List<Index> indexList = Index.getIndexList(profileRootNode);
	for (Index index : indexList) {
		if (index.isFolder()) {
			// folder cannot be modified
			continue;
		}

		FileIndex fileIndex = (FileIndex) index;
		String path = fileIndex.getFullPath();
		if (before.containsKey(path) && now.containsKey(path)) {
			if (!HashUtil.compare(fileIndex.getHash(), now.get(path))
					&& !HashUtil.compare(fileIndex.getHash(), before.get(path))) {
				// different hashes than 'before' and 'now'
				logger.debug("File '{}' has been updated remotely during absence.", path);
				updatedRemotely.add(fileIndex);
			}
		}
	}

	logger.info("Found {} files/folders that have been updated remotely during absence.", updatedRemotely.size());
	return updatedRemotely;
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:32,代码来源:FileSynchronizer.java


注:本文中的org.hive2hive.core.security.HashUtil.compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。