private long computeHashCode(File toTest, long fileSize, IProgressMonitor monitor) throws IOException { final int BUFFER_SIZE = 2048; char[] charBuffer = new char[BUFFER_SIZE]; byte[] byteBuffer = new byte[BUFFER_SIZE * 2]; SubMonitor subMonitor = SubMonitor.convert(monitor, (int) (fileSize / (BUFFER_SIZE * 2))); StreamHasher hasher = new StreamHasher(); try { InputStream inputStream = new FileInputStream(toTest); try { while (true) { subMonitor.split(1); int bytesRead = readUntilBufferFull(inputStream, byteBuffer); if (bytesRead < byteBuffer.length) { charBuffer = new char[(bytesRead + 1) / 2]; copyByteArrayToCharArray(charBuffer, byteBuffer, bytesRead); hasher.addChunk(charBuffer); break; } copyByteArrayToCharArray(charBuffer, byteBuffer, bytesRead); hasher.addChunk(charBuffer); } } finally { inputStream.close(); } } catch (FileNotFoundException e) { return 0; } return hasher.computeHash(); }
private long computeHashCode(File toTest, long fileSize, IProgressMonitor monitor) throws IOException { final int BUFFER_SIZE = 2048; char[] charBuffer = new char[BUFFER_SIZE]; byte[] byteBuffer = new byte[BUFFER_SIZE * 2]; SubMonitor subMonitor = SubMonitor.convert(monitor, (int) (fileSize / (BUFFER_SIZE * 2))); StreamHasher hasher = new StreamHasher(); try { InputStream inputStream = new FileInputStream(toTest); try { while (true) { subMonitor.split(1); int bytesRead = readUntilBufferFull(inputStream, byteBuffer); if (bytesRead < byteBuffer.length) { charBuffer = new char[(bytesRead + 1) / 2]; copyByteArrayToCharArray(charBuffer, byteBuffer, bytesRead); hasher.addChunk(charBuffer); break; } copyByteArrayToCharArray(charBuffer, byteBuffer, bytesRead); hasher.addChunk(charBuffer); } } finally { inputStream.close(); } } catch (FileNotFoundException e) { return 0; } return hasher.computeHash(); }