Skip to content

Commit e481539

Browse files
committed
DefaultWelcomeService: lean on DigestUtils
This addresses issue #82.
1 parent 7d44f23 commit e481539

File tree

1 file changed

+2
-34
lines changed

1 file changed

+2
-34
lines changed

src/main/java/org/scijava/welcome/DefaultWelcomeService.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333

3434
import java.io.File;
3535
import java.io.IOException;
36-
import java.io.UnsupportedEncodingException;
37-
import java.security.MessageDigest;
38-
import java.security.NoSuchAlgorithmException;
3936

4037
import org.scijava.app.AppService;
4138
import org.scijava.command.CommandService;
@@ -49,6 +46,7 @@
4946
import org.scijava.service.Service;
5047
import org.scijava.text.TextService;
5148
import org.scijava.ui.event.UIShownEvent;
49+
import org.scijava.util.DigestUtils;
5250
import org.scijava.util.Prefs;
5351
import org.scijava.welcome.event.WelcomeEvent;
5452

@@ -97,7 +95,7 @@ private void displayWelcome(final boolean force) {
9795
try {
9896
if (welcomeFile.exists()) {
9997
final String welcomeText = textService.asHTML(welcomeFile);
100-
final String checksum = getChecksum(welcomeText);
98+
final String checksum = DigestUtils.bestHex(welcomeText);
10199
final String previousChecksum = Prefs.get(getClass(), CHECKSUM_PREFS_KEY);
102100
if (!force && checksum.equals(previousChecksum)) return;
103101
Prefs.put(getClass(), CHECKSUM_PREFS_KEY, checksum);
@@ -138,34 +136,4 @@ private String firstRunPrefKey() {
138136
return "firstRun-" + appService.getApp().getVersion();
139137
}
140138

141-
// TODO: move this into TextUtils or some such
142-
// see https://github.com/scijava/scijava-common/issues/82
143-
// get digest of the file as according to fullPath
144-
private String getChecksum(final String text)
145-
{
146-
try {
147-
final MessageDigest digest = MessageDigest.getInstance("SHA-1");
148-
digest.update(text.getBytes("UTF-8"));
149-
return toHex(digest.digest());
150-
}
151-
catch (NoSuchAlgorithmException e) {
152-
return "" + text.hashCode();
153-
}
154-
catch (UnsupportedEncodingException e) {
155-
return "" + text.hashCode();
156-
}
157-
}
158-
159-
private final static char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7',
160-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
161-
162-
private String toHex(final byte[] bytes) {
163-
final char[] buffer = new char[bytes.length * 2];
164-
for (int i = 0; i < bytes.length; i++) {
165-
buffer[i * 2] = hex[(bytes[i] & 0xf0) >> 4];
166-
buffer[i * 2 + 1] = hex[bytes[i] & 0xf];
167-
}
168-
return new String(buffer);
169-
}
170-
171139
}

0 commit comments

Comments
 (0)