• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.bumptech.glide.testutil;
2 
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 
7 /**
8  * Shared utility classes for tests.
9  */
10 public final class TestUtil {
TestUtil()11     private TestUtil() {
12         // Utility class.
13     }
14 
resourceToBytes(Class testClass, String resourceName)15     public static byte[] resourceToBytes(Class testClass, String resourceName) throws IOException {
16         return isToBytes(TestResourceUtil.openResource(testClass, resourceName));
17     }
18 
isToBytes(InputStream is)19     public static byte[] isToBytes(InputStream is) throws IOException {
20         ByteArrayOutputStream os = new ByteArrayOutputStream();
21         byte[] buffer = new byte[1024];
22         int read;
23         try {
24             while ((read = is.read(buffer)) != -1) {
25                 os.write(buffer, 0, read);
26             }
27         } finally {
28             is.close();
29         }
30         return os.toByteArray();
31     }
32 
isToString(InputStream is)33     public static String isToString(InputStream is) throws IOException {
34         return new String(isToBytes(is));
35     }
36 
37 }
38