1package com.bumptech.glide.testutil; 2 3import java.io.ByteArrayOutputStream; 4import java.io.IOException; 5import java.io.InputStream; 6 7/** 8 * Shared utility classes for tests. 9 */ 10public final class TestUtil { 11 private TestUtil() { 12 // Utility class. 13 } 14 15 public static byte[] resourceToBytes(Class testClass, String resourceName) throws IOException { 16 return isToBytes(TestResourceUtil.openResource(testClass, resourceName)); 17 } 18 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 33 public static String isToString(InputStream is) throws IOException { 34 return new String(isToBytes(is)); 35 } 36 37} 38