Using String digest = DigestUtils.md5Hex(input);
I read the hash of the mp3 file and write it in the listview langs.add(data.getHashCode()); bottom screen where all the hashes are the same

 public void readFiles(File baseDirectory) { try { Iterator<File> iterator = FileUtils.iterateFiles(baseDirectory, new String[]{"mp3"}, true); while (iterator.hasNext()) { File fileloop = iterator.next(); InputStream input = new FileInputStream(fileloop); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); Mp3Parser parser = new Mp3Parser(); ParseContext parseCtx = new ParseContext(); parser.parse(input, handler, metadata, parseCtx); String digest = DigestUtils.md5Hex(input); input.close(); String[] metadataNames = metadata.names(); Mp3data track = new Mp3data(); track.setArtist(metadata.get("xmpDM:artist")); track.setAlbum(metadata.get("xmpDM:album")); track.setTitle(metadata.get("title")); track.setDuration(toMinutes(metadata.get("xmpDM:duration"))); track.setPath(fileloop.getAbsolutePath()); track.setHashCode(digest); mp3data.add(track); } Collections.sort(mp3data); } catch (IOException | SAXException | TikaException e) { e.printStackTrace(); } } 

here

 public String getHashCode(){ return hashcode; } public Mp3data setHashCode(String hashcode){ this.hashcode = hashcode; return this; } 

enter image description here

  • This is a hash of an empty file. By this time, the entire stream has already been read by parser.parse - extrn
  • Thank you, but if I write a reading of the hash sum above, an error flies - Kioshilol
  • Everything was decided just added another stream - Kioshilol

1 answer 1

You just need to add another stream InputStream input2 = new FileInputStream(fileloop);

 public void readFiles(File baseDirectory) { try { Iterator<File> iterator = FileUtils.iterateFiles(baseDirectory, new String[]{"mp3"}, true); while (iterator.hasNext()) { File fileloop = iterator.next(); InputStream input = new FileInputStream(fileloop); InputStream input2 = new FileInputStream(fileloop); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); Mp3Parser parser = new Mp3Parser(); ParseContext parseCtx = new ParseContext(); String digest = DigestUtils.md5Hex(input2); parser.parse(input, handler, metadata, parseCtx); input.close(); Mp3data track = new Mp3data(); track.setArtist(metadata.get("xmpDM:artist")); track.setAlbum(metadata.get("xmpDM:album")); track.setTitle(metadata.get("title")); track.setDuration(toMinutes(metadata.get("xmpDM:duration"))); track.setPath(fileloop.getAbsolutePath()); track.setHashCode(digest); mp3data.add(track); } Collections.sort(mp3data); } catch (IOException | SAXException | TikaException e) { e.printStackTrace(); } }