public String hash() { if (hash == null && this.checksumProvider != null) { hash = this.checksumProvider .putFile(file.getPath()) .checksumAsString(); } return hash; }
public String hash() { return cpf.getProvider(ChecksumType.SHA1).putFile(path).checksumAsString(); }
/** * 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(); }
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 OriginalFileI getFile(ServiceFactory sf) { OriginalFile file = null; ChecksumProviderFactory cpf = new ChecksumProviderFactoryImpl(); try { final byte[] buf = FileUtils.readFileToByteArray(source); final String sha1 = cpf.getProvider(ChecksumType.SHA1) .putBytes(buf).checksumAsString(); log.debug("Loading script: " + sha1); Parameters p = new Parameters(); p.addString("hash", sha1); p.addString("name", getName()); List<OriginalFile> files = loadScripts(sf, p); if (files.size() < 1) { return null; } else { if (files.size() > 1) { log.warn("Multiple scripts found: " + files); } file = files.get(0); } } catch (Exception e) { // pass in order to throw log.warn(e.toString()); // slf4j migration: toString() } if (file == null) { throw new InternalException("Failed to find script"); } else { return new OriginalFileI(file.getId(), false); } }
/** * Calls {@link RawFileStorePrx#save()} and stores the resultant * {@link OriginalFile} for future inspection along with the <em>local</em> * checksum. (The remote checksum is available from the * {@link OriginalFile}. * * @throws ServerError server error */ public void save() throws ServerError { // We don't need write access here, and considering that // a symlink or similar to a non-executable file may have // replaced the previous test file (see checkLocation), we // try to be as conservative as possible. RawFileStorePrx rawFileStore = getUploader("r"); checksum = cp.checksumAsString(); ofile = rawFileStore.save(); if (log.isDebugEnabled()) { log.debug(String.format("%s/%s id=%s", ofile.getPath().getValue(), ofile.getName().getValue(), ofile.getId().getValue())); log.debug(String.format("checksums: client=%s,server=%s", checksum, ofile.getHash().getValue())); } }
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; }
/** * Make the file, this is a temporary file which will be changed when the * script is validated. * * @param script * script. * @return OriginalFile tempfile.. * @throws ServerError */ private OriginalFile makeFile(final String path, final String script, Ice.Current current) throws ServerError { OriginalFile file = new OriginalFile(); file.setName(FilenameUtils.getName(path)); file.setPath(FilenameUtils.getFullPath(path)); file.setSize((long) script.getBytes().length); file.setHasher(new ChecksumAlgorithm("SHA1-160")); file.setHash(cpf.getProvider(ChecksumType.SHA1) .putBytes(script.getBytes()).checksumAsString()); scripts.setMimetype(file); return updateFile(file, current); }
final String toHash = toProvider.checksumAsString(); if (fromProvider != null) { if (!fromProvider.checksumAsString().equals(fromHash)) { throw new ServerError(null, null, "hash mismatch on file ID " + id);
final ChecksumType checksumType = checksumAlgorithms.get(file.getHasher().getValue()); file.setHash(this.checksumProviderFactory .getProvider(checksumType).putFile(path).checksumAsString());
file.setHasher(new ChecksumAlgorithm(ChecksumAlgorithm.VALUE_SHA1_160)); file.setHash(cpf.getProvider(ChecksumType.SHA1).putBytes(data) .checksumAsString()); file.setMimetype(mimetype); FileAnnotation fa = new FileAnnotation();