4
4
import com .filestack .transforms .ImageTransform ;
5
5
import com .filestack .transforms .tasks .AvTransformOptions ;
6
6
import com .filestack .transforms .tasks .CropTask ;
7
- import com . google . common . hash . Hashing ;
8
- import com . google . common . io . Files ;
7
+ import okio . ByteString ;
8
+ import okio . Okio ;
9
9
import org .junit .AfterClass ;
10
10
import org .junit .Assert ;
11
11
import org .junit .Test ;
12
12
13
13
import java .io .File ;
14
+ import java .security .MessageDigest ;
15
+ import java .security .NoSuchAlgorithmException ;
14
16
import java .util .ArrayList ;
15
17
16
18
public class TestTransforms {
@@ -39,9 +41,10 @@ public void testImageTransform() throws Exception {
39
41
String cropPath = loader .getResource ("com/filestack/sample_image_cropped.jpg" ).getPath ();
40
42
File cropFile = new File (cropPath );
41
43
42
- String correct = Files .asByteSource (cropFile ).hash (Hashing .sha256 ()).toString ();
43
- byte [] bytes = transform .getContent ().bytes ();
44
- String output = Hashing .sha256 ().hashBytes (bytes ).toString ();
44
+ byte [] bytes = Okio .buffer (Okio .source (cropFile )).readByteArray ();
45
+ String correct = ByteString .of (sha256 (bytes )).hex ();
46
+ byte [] actualBytes = transform .getContent ().bytes ();
47
+ String output = ByteString .of (sha256 (actualBytes )).hex ();
45
48
46
49
Assert .assertEquals (correct , output );
47
50
}
@@ -70,9 +73,9 @@ public void testAvTransform() throws Exception {
70
73
String mp3Path = loader .getResource ("com/filestack/sample_music.mp3" ).getPath ();
71
74
File mp3File = new File (mp3Path );
72
75
73
- String correct = Files . asByteSource ( mp3File ). hash ( Hashing . sha256 ( )).toString ();
76
+ String correct = ByteString . of ( sha256 ( Okio . buffer ( Okio . source ( mp3File )).readByteArray ())). hex ();
74
77
byte [] bytes = mp3FileLink .getContent ().bytes ();
75
- String output = Hashing . sha256 (). hashBytes ( bytes ).toString ();
78
+ String output = ByteString . of ( bytes ).hex ();
76
79
77
80
Assert .assertEquals (correct , output );
78
81
}
@@ -99,4 +102,10 @@ public static void cleanupFiles() {
99
102
}
100
103
}
101
104
}
102
- }
105
+
106
+ private static byte [] sha256 (byte [] bytes ) throws NoSuchAlgorithmException {
107
+ MessageDigest md = MessageDigest .getInstance ("SHA-256" );
108
+ md .update (bytes );
109
+ return md .digest ();
110
+ }
111
+ }
0 commit comments