public String hash() { if (hash == null && this.checksumProvider != null) { hash = this.checksumProvider .putFile(file.getPath()) .checksumAsString(); } return hash; }
/** * Calculates the local sha1 for a file. * @param file a local file * @return the file's SHA-1 hexadecimal digest */ public String sha1(File file) { ChecksumProviderFactory cpf = new ChecksumProviderFactoryImpl(); return cpf.getProvider(ChecksumType.SHA1).putFile( file.getAbsolutePath()).checksumAsString(); }
public String hash() { return cpf.getProvider(ChecksumType.SHA1).putFile(path).checksumAsString(); }
protected String checksum(String filename, ChecksumAlgorithm checksumAlgorithm) { final ChecksumProviderFactory checksumProviderFactory = new ChecksumProviderFactoryImpl(); final ChecksumProvider cp = checksumProviderFactory.getProvider( ChecksumAlgorithmMapper.getChecksumType(checksumAlgorithm)); cp.putFile(filename); return cp.checksumAsString(); }
public List<Long> verifyChecksums(List<Long> ids, Current __current) throws ServerError { /* set up an invocation context in which the group is set to -1, for "all groups" */ final Current allGroupsCurrent = makeAdjustedCurrent(__current); allGroupsCurrent.ctx = new HashMap<String, String>(__current.ctx); allGroupsCurrent.ctx.put(omero.constants.GROUP.value, "-1"); /* verify the checksum of the specified files that are in this repository */ final List<Long> mismatchFiles = new ArrayList<Long>(); for (final long id : repositoryDao.filterFilesByRepository(getRepoUuid(), ids, allGroupsCurrent)) { /* get one of the files */ final OriginalFile file = repositoryDao.getOriginalFileWithHasher(id, allGroupsCurrent); final FsFile fsPath = new FsFile(file.getPath() + file.getName()); final String osPath = serverPaths.getServerFileFromFsFile(fsPath).getAbsolutePath(); /* check the file's checksum */ final ome.model.enums.ChecksumAlgorithm hasher = file.getHasher(); final String hash = file.getHash(); if (hasher != null && hash != null) { /* has a valid checksum, so check it */ final ChecksumProvider fromProvider = checksumProviderFactory.getProvider(ChecksumAlgorithmMapper.getChecksumType(hasher)); fromProvider.putFile(osPath); if (!fromProvider.checksumAsString().equalsIgnoreCase(hash)) { mismatchFiles.add(id); } } } return mismatchFiles; }
final ChecksumType checksumType = checksumAlgorithms.get(file.getHasher().getValue()); file.setHash(this.checksumProviderFactory .getProvider(checksumType).putFile(path).checksumAsString());
/** * "Transfer" files by soft-linking them into place. This method is likely * re-usable for other general "linking" strategies by overriding * {@link #createProcessBuilder(File, File)} and the other protected methods here. */ public String transfer(TransferState state) throws IOException, ServerError { RawFileStorePrx rawFileStore = start(state); try { final OriginalFile root = state.getRootFile(); final OriginalFile ofile = state.getOriginalFile(); final File location = getLocalLocation(root, ofile); final File file = state.getFile(); final long length = state.getLength(); final ChecksumProvider cp = state.getChecksumProvider(); state.uploadStarted(); checkLocation(location, rawFileStore); // closes rawFileStore state.closeUploader(); exec(file, location); checkTarget(location, state); cp.putFile(file.getAbsolutePath()); state.stop(length); state.uploadBytes(length); return finish(state, length); } finally { state.closeUploader(); } }