有没有办法在 Java 中获取 InputStream 的 HashCode,我正在尝试使用<p:fileUpload/>from PrimeFaces上传图片,将其转换为 HashCode 并将其与另一张图片进行比较。
目前我正在尝试这个:
public void save(FileUploadEvent event) throws IOException {
HashCode hashCode = null;
HashCode hashCodeCompare = null;
hashCode = Files.asByteSource(new File(event.toString())).hash(Hashing.murmur3_128(50));
hashCodeCompare = Files.asByteSource(new File(FilePathOfFileToCompare)).hash(Hashing.murmur3_128(50));
boolean hashTrueFalse;
if(hashCode.equals(hashCodeCompare)) {
System.out.println("true");
} else{
System.out.println("false");
}
try (InputStream input = event.getFile().getInputstream()) {
String imageName = generateFileName() + "." + fileExtensions(event.getFile().getFileName());
String imageLink = PICTURE_DESTINATION + "\\" + imageName;
Picture picture = new Picture();
picture.setPictureUrl(imageLink);
pictureService.createOrUpdate(picture);
personForm.getCurrentPersonDTO().setPictureDTO(pictureMapper.toDTO(picture));
} catch (IOException e) {
e.printStackTrace(); …Run Code Online (Sandbox Code Playgroud) 我目前正在映射具有两个“子 DTOS”的 DTO。
例如。
PersonDTO有"firstName", "lastName", "languageDTO","zipCodeDTO"
现在在我的 PersonMapper 中,我想使用 my"LanguageMapper"和 my "ZipCodeMapper".
但是@Mapper(uses = "")我只能调用一个外部映射器在我的课堂上使用。
预先感谢您的帮助
这是我的 DTO 的代码
这是我的 ZipCodeDTO:
class ZipCodeDTO {
public static final String FIELD_SEPARATOR = "__";
private String favouriteZipCode;
private String cityName;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFavouriteZipCode() {
return favouriteZipCode;
}
public void setFavouriteZipCode(String favouriteZipCode) { …Run Code Online (Sandbox Code Playgroud)